]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/fontutil.cpp
added automatic growing of in-place wxTextCtrls for generic wxListCtrl and wxTreeCtrl
[wxWidgets.git] / src / msw / fontutil.cpp
index f75d090505e6b308b19f904cbf5cb90b11a1b281..a5b4de99d7674b6c9d48419fe94327837619ef75 100644 (file)
 
 #include "wx/tokenzr.h"
 
+// If 1, use the screen resolution to calculate font sizes.
+// This is OK for screen fonts but might have implications when the
+// same font is used for printing.
+// If 0, assume 96 DPI.
+#define wxUSE_SCREEN_DPI 1
+
 // ============================================================================
 // implementation
 // ============================================================================
 // ----------------------------------------------------------------------------
 
 // convert to/from the string representation: format is
-//      facename[;charset]
+//      encodingid;facename[;charset]
 
 bool wxNativeEncodingInfo::FromString(const wxString& s)
 {
     wxStringTokenizer tokenizer(s, _T(";"));
 
+    wxString encid = tokenizer.GetNextToken();
+    long enc;
+    if ( !encid.ToLong(&enc) )
+        return FALSE;
+    encoding = (wxFontEncoding)enc;
+
     facename = tokenizer.GetNextToken();
     if ( !facename )
         return FALSE;
@@ -81,10 +93,12 @@ bool wxNativeEncodingInfo::FromString(const wxString& s)
 
 wxString wxNativeEncodingInfo::ToString() const
 {
-    wxString s(facename);
+    wxString s;
+
+    s << (long)encoding << _T(';') << facename;
     if ( charset != ANSI_CHARSET )
     {
-        s << _T(';') << charset;
+         s << _T(';') << charset;
     }
 
     return s;
@@ -159,7 +173,7 @@ bool wxGetNativeFontEncoding(wxFontEncoding encoding,
     }
 
     info->encoding = encoding;
-   
+
     return TRUE;
 }
 
@@ -184,6 +198,69 @@ bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
     return TRUE;
 }
 
+// ----------------------------------------------------------------------------
+// wxFontEncoding <-> CHARSET_XXX
+// ----------------------------------------------------------------------------
+
+wxFontEncoding wxGetFontEncFromCharSet(int cs)
+{
+    wxFontEncoding fontEncoding;
+
+    switch ( cs )
+    {
+        default:
+            // JACS: Silently using ANSI_CHARSET
+            // apparently works for Chinese Windows. Assume it works
+            // for all/most other languages.
+            //wxFAIL_MSG(wxT("unsupported charset"));
+            // fall through
+
+        case ANSI_CHARSET:
+            fontEncoding = wxFONTENCODING_CP1252;
+            break;
+
+#ifdef __WIN32__
+        case EASTEUROPE_CHARSET:
+            fontEncoding = wxFONTENCODING_CP1250;
+            break;
+
+        case BALTIC_CHARSET:
+            fontEncoding = wxFONTENCODING_CP1257;
+            break;
+
+        case RUSSIAN_CHARSET:
+            fontEncoding = wxFONTENCODING_CP1251;
+            break;
+
+        case ARABIC_CHARSET:
+            fontEncoding = wxFONTENCODING_CP1256;
+            break;
+
+        case GREEK_CHARSET:
+            fontEncoding = wxFONTENCODING_CP1253;
+            break;
+
+        case HEBREW_CHARSET:
+            fontEncoding = wxFONTENCODING_CP1255;
+            break;
+
+        case TURKISH_CHARSET:
+            fontEncoding = wxFONTENCODING_CP1254;
+            break;
+
+        case THAI_CHARSET:
+            fontEncoding = wxFONTENCODING_CP437;
+            break;
+#endif // Win32
+
+        case OEM_CHARSET:
+            fontEncoding = wxFONTENCODING_CP437;
+            break;
+    }
+
+    return fontEncoding;
+}
+
 // ----------------------------------------------------------------------------
 // wxFont <-> LOGFONT conversion
 // ----------------------------------------------------------------------------
@@ -262,9 +339,9 @@ void wxFillLogFont(LOGFONT *logFont, const wxFont *font)
             break;
     }
 
-#if 0
+#if wxUSE_SCREEN_DPI
     HDC dc = ::GetDC(NULL);
-    int ppInch = ::GetDeviceCaps(dc, LOGPIXELSY);
+    static const int ppInch = ::GetDeviceCaps(dc, LOGPIXELSY);
     ::ReleaseDC(NULL, dc);
 #else
     // New behaviour: apparently ppInch varies according to Large/Small Fonts
@@ -278,7 +355,8 @@ void wxFillLogFont(LOGFONT *logFont, const wxFont *font)
     int nHeight = (font->GetPointSize()*ppInch/72);
 #else
     // Correct for Windows compatibility
-    int nHeight = - (font->GetPointSize()*ppInch/72);
+//    int nHeight = - (font->GetPointSize()*ppInch/72);
+    int nHeight = - (int) ( (font->GetPointSize()*((double)ppInch)/72.0) + 0.5);
 #endif
 
     wxString facename = font->GetFaceName();
@@ -383,68 +461,20 @@ wxFont wxCreateFontFromLogFont(const LOGFONT *logFont)
 
     wxString fontFace = logFont->lfFaceName;
 
-    // font size
-    HDC dc = ::GetDC(NULL);
-
     // remember that 1pt = 1/72inch
     int height = abs(logFont->lfHeight);
-    int fontPoints = (72*height)/GetDeviceCaps(dc, LOGPIXELSY);
 
+#if wxUSE_SCREEN_DPI
+    HDC dc = ::GetDC(NULL);
+    static const int ppInch = GetDeviceCaps(dc, LOGPIXELSY);
     ::ReleaseDC(NULL, dc);
-
-    wxFontEncoding fontEncoding;
-    switch ( logFont->lfCharSet )
-    {
-        default:
-            wxFAIL_MSG(wxT("unsupported charset"));
-            // fall through
-
-        case ANSI_CHARSET:
-            fontEncoding = wxFONTENCODING_CP1252;
-            break;
-
-#ifdef __WIN32__
-        case EASTEUROPE_CHARSET:
-            fontEncoding = wxFONTENCODING_CP1250;
-            break;
-
-        case BALTIC_CHARSET:
-            fontEncoding = wxFONTENCODING_CP1257;
-            break;
-
-        case RUSSIAN_CHARSET:
-            fontEncoding = wxFONTENCODING_CP1251;
-            break;
-
-        case ARABIC_CHARSET:
-            fontEncoding = wxFONTENCODING_CP1256;
-            break;
-
-        case GREEK_CHARSET:
-            fontEncoding = wxFONTENCODING_CP1253;
-            break;
-
-        case HEBREW_CHARSET:
-            fontEncoding = wxFONTENCODING_CP1255;
-            break;
-
-        case TURKISH_CHARSET:
-            fontEncoding = wxFONTENCODING_CP1254;
-            break;
-
-        case THAI_CHARSET:
-            fontEncoding = wxFONTENCODING_CP437;
-            break;
+#else
+    static const int ppInch = 96;
 #endif
-
-        case OEM_CHARSET:
-            fontEncoding = wxFONTENCODING_CP437;
-            break;
-    }
+    int fontPoints = (int) (((72.0*((double)height))/(double) ppInch) + 0.5);
 
     return wxFont(fontPoints, fontFamily, fontStyle,
                   fontWeight, fontUnderline, fontFace,
-                  fontEncoding);
+                  wxGetFontEncFromCharSet(logFont->lfCharSet));
 }
 
-