X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/09fcd88955f6460d1f0d3d506118ce52c1090621..df16a53ef9ae506c51023178e4fe45ce45e69447:/src/msw/font.cpp diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 7dd7f375a5..2ab0fbb804 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -41,6 +41,7 @@ #include "wx/tokenzr.h" #include "wx/msw/private.h" +#include "wx/tokenzr.h" IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) @@ -85,9 +86,9 @@ public: Init(size, family, style, weight, underlined, faceName, encoding); } - wxFontRefData(const wxNativeFontInfo& info) + wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0) { - Init(info); + Init(info, hFont); } virtual ~wxFontRefData(); @@ -102,7 +103,7 @@ protected: const wxString& faceName, wxFontEncoding encoding); - void Init(const wxNativeFontInfo& info); + void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0); // If TRUE, the pointer to the actual font is temporary and SHOULD NOT BE // DELETED by destructor @@ -121,7 +122,7 @@ protected: // Windows font handle WXHFONT m_hFont; - + // Native font info wxNativeFontInfo m_nativeFontInfo; bool m_nativeFontInfoOk; @@ -156,11 +157,11 @@ void wxFontRefData::Init(int pointSize, m_temporary = FALSE; m_hFont = 0; - + m_nativeFontInfoOk = FALSE; } -void wxFontRefData::Init(const wxNativeFontInfo& info) +void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont) { // extract family from pitch-and-family int lfFamily = info.lf.lfPitchAndFamily; @@ -218,25 +219,23 @@ void wxFontRefData::Init(const wxNativeFontInfo& info) m_faceName = info.lf.lfFaceName; - // remember that 1pt = 1/72inch int height = abs(info.lf.lfHeight); -#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 + // remember that 1pt = 1/72inch + const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY); m_pointSize = (int) (((72.0*((double)height))/(double) ppInch) + 0.5); - + m_encoding = wxGetFontEncFromCharSet(info.lf.lfCharSet); - + m_fontId = 0; m_temporary = FALSE; - m_hFont = 0; - + // hFont may be zero, or it be passed in case we really want to + // use the exact font created in the underlying system + // (for example where we can't guarantee conversion from HFONT + // to LOGFONT back to HFONT) + m_hFont = hFont; + m_nativeFontInfoOk = TRUE; m_nativeFontInfo = info; } @@ -296,42 +295,42 @@ bool wxNativeFontInfo::FromString(const wxString& s) token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; - lf.lfItalic = l; + lf.lfItalic = (BYTE)l; token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; - lf.lfUnderline = l; + lf.lfUnderline = (BYTE)l; token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; - lf.lfStrikeOut = l; + lf.lfStrikeOut = (BYTE)l; token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; - lf.lfCharSet = l; + lf.lfCharSet = (BYTE)l; token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; - lf.lfOutPrecision = l; + lf.lfOutPrecision = (BYTE)l; token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; - lf.lfClipPrecision = l; + lf.lfClipPrecision = (BYTE)l; token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; - lf.lfQuality = l; + lf.lfQuality = (BYTE)l; token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; - lf.lfPitchAndFamily = l; + lf.lfPitchAndFamily = (BYTE)l; token = tokenizer.GetNextToken(); if(!token) @@ -371,15 +370,13 @@ wxString wxNativeFontInfo::ToString() const void wxFont::Init() { - if ( wxTheFontList ) - wxTheFontList->Append(this); } -bool wxFont::Create(const wxNativeFontInfo& info) +bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont) { UnRef(); - m_refData = new wxFontRefData(info); + m_refData = new wxFontRefData(info, hFont); RealizeResource(); @@ -421,8 +418,6 @@ bool wxFont::Create(int pointSize, wxFont::~wxFont() { - if ( wxTheFontList ) - wxTheFontList->DeleteObject(this); } // ---------------------------------------------------------------------------- @@ -443,7 +438,7 @@ bool wxFont::RealizeResource() wxFillLogFont(&M_FONTDATA->m_nativeFontInfo.lf, this); M_FONTDATA->m_nativeFontInfoOk = TRUE; } - + M_FONTDATA->m_hFont = (WXHFONT)::CreateFontIndirect(&M_FONTDATA->m_nativeFontInfo.lf); M_FONTDATA->m_faceName = M_FONTDATA->m_nativeFontInfo.lf.lfFaceName; if ( !M_FONTDATA->m_hFont ) @@ -456,7 +451,7 @@ bool wxFont::RealizeResource() return TRUE; } -bool wxFont::FreeResource(bool force) +bool wxFont::FreeResource(bool WXUNUSED(force)) { if ( GetResourceHandle() ) { @@ -582,8 +577,8 @@ void wxFont::SetEncoding(wxFontEncoding encoding) void wxFont::SetNativeFontInfo(const wxNativeFontInfo& info) { Unshare(); - - FreeResource(); + + FreeResource(); M_FONTDATA->Init(info); @@ -596,44 +591,57 @@ void wxFont::SetNativeFontInfo(const wxNativeFontInfo& info) int wxFont::GetPointSize() const { + wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + return M_FONTDATA->m_pointSize; } int wxFont::GetFamily() const { + wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + return M_FONTDATA->m_family; } int wxFont::GetFontId() const { + wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + return M_FONTDATA->m_fontId; } int wxFont::GetStyle() const { + wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + return M_FONTDATA->m_style; } int wxFont::GetWeight() const { + wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + return M_FONTDATA->m_weight; } bool wxFont::GetUnderlined() const { + wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") ); + return M_FONTDATA->m_underlined; } wxString wxFont::GetFaceName() const { - wxString str; - if ( M_FONTDATA ) - str = M_FONTDATA->m_faceName; - return str; + wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") ); + + return M_FONTDATA->m_faceName; } wxFontEncoding wxFont::GetEncoding() const { + wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); + return M_FONTDATA->m_encoding; } @@ -641,7 +649,7 @@ wxNativeFontInfo *wxFont::GetNativeFontInfo() const { if( M_FONTDATA->m_nativeFontInfoOk ) return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); - + return 0; }