X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/11c7d5b6d1cb54d5ffdc11d8ff092b41e225bfb6..af547d51b7494fd365ae29e048d458ff72b27056:/src/msw/fontutil.cpp diff --git a/src/msw/fontutil.cpp b/src/msw/fontutil.cpp index 10e1d82f7e..04ad8a0548 100644 --- a/src/msw/fontutil.cpp +++ b/src/msw/fontutil.cpp @@ -41,6 +41,12 @@ #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 // ============================================================================ @@ -50,12 +56,18 @@ // ---------------------------------------------------------------------------- // 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; @@ -143,6 +157,10 @@ bool wxGetNativeFontEncoding(wxFontEncoding encoding, case wxFONTENCODING_CP1257: info->charset = BALTIC_CHARSET; break; + + case wxFONTENCODING_CP874: + info->charset = THAI_CHARSET; + break; #endif // !Win16 case wxFONTENCODING_CP437: @@ -154,6 +172,8 @@ bool wxGetNativeFontEncoding(wxFontEncoding encoding, return FALSE; } + info->encoding = encoding; + return TRUE; } @@ -164,7 +184,7 @@ bool wxTestFontEncoding(const wxNativeEncodingInfo& info) wxZeroMemory(lf); // all default values lf.lfCharSet = info.charset; - strncpy(lf.lfFaceName, info.facename, sizeof(lf.lfFaceName)); + wxStrncpy(lf.lfFaceName, info.facename, sizeof(lf.lfFaceName)); HFONT hfont = ::CreateFontIndirect(&lf); if ( !hfont ) @@ -256,9 +276,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 @@ -272,7 +292,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(); @@ -377,14 +398,17 @@ 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); +#else + static const int ppInch = 96; +#endif + int fontPoints = (int) (((72.0*((double)height))/(double) ppInch) + 0.5); wxFontEncoding fontEncoding; switch ( logFont->lfCharSet ) @@ -397,6 +421,7 @@ wxFont wxCreateFontFromLogFont(const LOGFONT *logFont) fontEncoding = wxFONTENCODING_CP1252; break; +#ifdef __WIN32__ case EASTEUROPE_CHARSET: fontEncoding = wxFONTENCODING_CP1250; break; @@ -425,6 +450,11 @@ wxFont wxCreateFontFromLogFont(const LOGFONT *logFont) fontEncoding = wxFONTENCODING_CP1254; break; + case THAI_CHARSET: + fontEncoding = wxFONTENCODING_CP437; + break; +#endif + case OEM_CHARSET: fontEncoding = wxFONTENCODING_CP437; break;