Vadim, i opened an issue for this at
https://github.com/alexpana/wxWidgets/issues
I tried to make a patch for this purpose.
The patch handled the font creation error (with assert in debug), and with
that it is already possible to live :)
But if it is desirable to implement in addition your idea about adding of a
new method to wxGraphicsContext, I could add also it as code refactoring is
already made in this patch.
{{{
Index: src/common/graphcmn.cpp
===================================================================
--- src/common/graphcmn.cpp (revision 77707)
+++ src/common/graphcmn.cpp (working copy)
@@ -621,7 +621,12 @@
void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour
)
{
if ( font.IsOk() )
- SetFont( CreateFont( font, colour ) );
+ {
+ wxGraphicsFont &gfont = CreateFont( font, colour );
+ wxASSERT_MSG(gfont.GetRefData() != 0, wxT("Font isn't
supported!"));
+ if( gfont.GetRefData() )
+ SetFont( gfont );
+ }
else
SetFont( wxNullGraphicsFont );
}
Index: src/msw/graphicsd2d.cpp
===================================================================
--- src/msw/graphicsd2d.cpp (revision 77707)
+++ src/msw/graphicsd2d.cpp (working copy)
@@ -2063,6 +2063,8 @@
wxCOMPtr<IDWriteFont> GetFont() { return m_font; };
+ static bool CreateFontFromwxFont(const wxFont& font, IDWriteFont**
d2dfont=0);
+
private:
// The native, device-independent font object
wxCOMPtr<IDWriteFont> m_font;
@@ -2078,12 +2080,11 @@
bool m_strikethrough;
};
-wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, ID2D1Factory*
d2dFactory, const wxFont& font, const wxColor& color) :
- wxGraphicsObjectRefData(renderer), m_brushData(renderer,
wxBrush(color)),
- m_underlined(font.GetUnderlined()),
m_strikethrough(font.GetStrikethrough())
+bool wxD2DFontData::CreateFontFromwxFont(const wxFont& font, IDWriteFont**
pd2dfont)
{
HRESULT hr;
+ wxCOMPtr<IDWriteFont> d2dfont;
wxCOMPtr<IDWriteGdiInterop> gdiInterop;
hr = wxDWriteFactory()->GetGdiInterop(&gdiInterop);
@@ -2098,9 +2099,24 @@
logfont.lfFaceName[i] = font.GetFaceName().GetChar(i);
}
}
+ hr = gdiInterop->CreateFontFromLOGFONT(&logfont, &d2dfont);
+ if ( pd2dfont )
+ {
+ if ( d2dfont ) d2dfont->AddRef();
+ *pd2dfont = d2dfont;
+ }
+ return d2dfont != 0;
+}
- hr = gdiInterop->CreateFontFromLOGFONT(&logfont, &m_font);
+wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, ID2D1Factory*
d2dFactory, const wxFont& font, const wxColor& color) :
+ wxGraphicsObjectRefData(renderer), m_font(0), m_brushData(renderer,
wxBrush(color)),
+ m_underlined(font.GetUnderlined()),
m_strikethrough(font.GetStrikethrough())
+{
+ HRESULT hr;
+ if ( !CreateFontFromwxFont(font, &m_font) )
+ return; // Font isn't supported
+
wxCOMPtr<IDWriteFontFamily> fontFamily;
m_font->GetFontFamily(&fontFamily);
@@ -3666,7 +3682,9 @@
wxD2DFontData* fontData = new wxD2DFontData(this, GetD2DFactory(),
font, col);
wxGraphicsFont graphicsFont;
- graphicsFont.SetRefData(fontData);
+ if ( !fontData->GetFont() ) // Fail
+ wxDELETE(fontData);
+ graphicsFont.SetRefData(fontData); // 0 if it fails
return graphicsFont;
}
}}}
Thank you,
Andrey