From 5a4d46bf7d329b9eec195f4b7ab6ada403e4f0b4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Sep 2018 13:36:46 +0200 Subject: [PATCH] Handle fractional point sizes in DirectWrite wxGraphicsFont Also stop scaling the font size by DPI manually, we don't need to do it if we use points instead of pixels. This, in turn, made it unnecessary to pass ID2D1Factory parameter to wxD2DFontData ctor. --- src/msw/graphicsd2d.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 9fb830fe52..00eb65dde3 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2637,7 +2637,7 @@ wxD2DPenData* wxGetD2DPenData(const wxGraphicsPen& pen) class wxD2DFontData : public wxGraphicsObjectRefData { public: - wxD2DFontData(wxGraphicsRenderer* renderer, ID2D1Factory* d2d1Factory, const wxFont& font, const wxColor& color); + wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, const wxColor& color); wxCOMPtr CreateTextLayout(const wxString& text) const; @@ -2662,7 +2662,7 @@ private: bool m_strikethrough; }; -wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, ID2D1Factory* d2dFactory, const wxFont& font, const wxColor& color) : +wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, const wxColor& color) : wxGraphicsObjectRefData(renderer), m_brushData(renderer, wxBrush(color)), m_underlined(font.GetUnderlined()), m_strikethrough(font.GetStrikethrough()) { @@ -2715,16 +2715,15 @@ wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, ID2D1Factory* d2dFact hr = familyNames->GetString(0, name, length+1); wxCHECK_HRESULT_RET(hr); - FLOAT dpiX, dpiY; - d2dFactory->GetDesktopDpi(&dpiX, &dpiY); - hr = wxDWriteFactory()->CreateTextFormat( name, NULL, m_font->GetWeight(), m_font->GetStyle(), m_font->GetStretch(), - (FLOAT)(font.GetPixelSize().GetHeight()) / (dpiY / 96.0), + // We need to use DIP units for the font size, with 1dip = 1/96in, + // while wxFont uses points with 1pt = 1/72in. + font.GetFractionalPointSize()*96/72, L"en-us", &m_textFormat); @@ -4708,7 +4707,7 @@ wxImage wxD2DRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp) wxGraphicsFont wxD2DRenderer::CreateFont(const wxFont& font, const wxColour& col) { - wxD2DFontData* fontData = new wxD2DFontData(this, GetD2DFactory(), font, col); + wxD2DFontData* fontData = new wxD2DFontData(this, font, col); if ( !fontData->GetFont() ) { // Apparently a non-TrueType font is given and hence