From 12493a5fb8f95c1a2918fc3ef010995ab1e4946a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Oct 2011 22:07:18 +0000 Subject: [PATCH] Refactor wxGDIPlusFontData ctor to allow using it without wxGDIPlusContext. wxGDIPlusFontData only needs wxGDIPlusContext to get the font unit to use, so pass the font unit directly to the ctor to allow also using it when there is no context at hand. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69357 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/graphics.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 0ed550a04a..42c0b21746 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -297,7 +297,16 @@ public: virtual Brush* GetGDIPlusBrush() { return m_textBrush; } virtual Font* GetGDIPlusFont() { return m_font; } + private : + // Common part of all ctors, flags here is a combination of values of + // FontStyle GDI+ enum. + void Init(const wxString& name, + REAL size, + int style, + const wxColour& col, + Unit fontUnit = UnitPixel); + Brush* m_textBrush; Font* m_font; }; @@ -840,13 +849,28 @@ wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, // wxGDIPlusFont implementation //----------------------------------------------------------------------------- +void +wxGDIPlusFontData::Init(const wxString& name, + REAL size, + int style, + const wxColour& col, + Unit fontUnit) +{ + // This scaling is needed when we use unit other than the + // default UnitPoint. It works for both display and printing. + size *= 100.0f / 72.0f; + + m_font = new Font(name, size, style, fontUnit); + + m_textBrush = new SolidBrush(wxColourToColor(col)); +} + wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxGDIPlusContext* gc, const wxFont &font, const wxColour& col ) : wxGraphicsObjectRefData( renderer ) { - wxWCharBuffer s = font.GetFaceName().wc_str( *wxConvUI ); int style = FontStyleRegular; if ( font.GetStyle() == wxFONTSTYLE_ITALIC ) style |= FontStyleItalic; @@ -863,17 +887,9 @@ wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer* renderer, if ( fontUnit == UnitDisplay ) fontUnit = UnitPixel; - REAL points = font.GetPointSize(); - - // This scaling is needed when we use unit other than the - // default UnitPoint. It works for both display and printing. - REAL size = points * (100.0 / 72.0); - // NB: font unit should match context's unit. We can use UnitPixel, // as that is what the print context should use. - m_font = new Font( s, size, style, fontUnit ); - - m_textBrush = new SolidBrush(wxColourToColor(col)); + Init(font.GetFaceName(), font.GetPointSize(), style, col, fontUnit); } wxGDIPlusFontData::~wxGDIPlusFontData() -- 2.45.2