From 06963940fb33bb240d31b482b22d8de45fe12938 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 17 Apr 2017 18:32:31 +0200 Subject: [PATCH] Change current font only if new graphics font is successfully created If new graphics font couldn't be created successfully there is no need to reset current font by updating it to wxNullGraphicsFont. Closes #17790. --- interface/wx/dcgraph.h | 4 ++++ src/common/graphcmn.cpp | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/interface/wx/dcgraph.h b/interface/wx/dcgraph.h index 045661afc9..c60a00e7e0 100644 --- a/interface/wx/dcgraph.h +++ b/interface/wx/dcgraph.h @@ -10,6 +10,10 @@ wxGCDC is a device context that draws on a wxGraphicsContext. + @remarks + If Direct2D is a renderer of underlying graphics context, only wxFont objects + representing TrueType fonts can be used in the font-related functions. + @library{wxcore} @category{dc} diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 60dbf25885..bdf0597149 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -653,12 +653,21 @@ void wxGraphicsContext::SetFont( const wxGraphicsFont& font ) m_font = font; } -void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour ) +void wxGraphicsContext::SetFont(const wxFont& font, const wxColour& colour) { if ( font.IsOk() ) - SetFont( CreateFont( font, colour ) ); + { + // Change current font only if new graphics font is successfully created. + wxGraphicsFont grFont = CreateFont(font, colour); + if ( !grFont.IsSameAs(wxNullGraphicsFont) ) + { + SetFont(grFont); + } + } else + { SetFont( wxNullGraphicsFont ); + } } void wxGraphicsContext::DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle )