From 7dfbe50fc0da9f129091fb18c7d584be89190607 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 22 Oct 2018 17:43:31 +0200 Subject: [PATCH] fixing proper font rendering color when using emulated bold when the stroke width is set in macOS (emulated bold), the stroke color was not correctly set - unless text color was black --- include/wx/osx/core/cfdictionary.h | 5 +++++ src/osx/carbon/graphics.cpp | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/wx/osx/core/cfdictionary.h b/include/wx/osx/core/cfdictionary.h index fddbb52654..d27c0f5891 100644 --- a/include/wx/osx/core/cfdictionary.h +++ b/include/wx/osx/core/cfdictionary.h @@ -90,6 +90,11 @@ public: { return CFDictionaryCreateCopy(kCFAllocatorDefault, this->m_ptr); } + + CFMutableDictionaryRef CreateMutableCopy() const + { + return CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, this->m_ptr); + } }; class wxCFMutableDictionaryRef : public wxCFDictionaryRefCommon diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index cd99421373..16f58329da 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -39,6 +39,7 @@ #include "wx/osx/dcclient.h" #include "wx/osx/dcmemory.h" #include "wx/osx/private.h" + #include "wx/osx/core/cfdictionary.h" #else #include "CoreServices/CoreServices.h" #include "ApplicationServices/ApplicationServices.h" @@ -2298,7 +2299,23 @@ void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDo CGColorRef col = wxMacCreateCGColor( fref->GetColour() ); CTFontRef font = fref->OSXGetCTFont(); - wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, fref->OSXGetCTFontAttributes()) ); + wxCFDictionaryRef fontattr(wxCFRetain(fref->OSXGetCTFontAttributes())); + wxCFMutableDictionaryRef inlinefontattr; + + bool setColorsInLine = false; + + // if we emulate boldness the stroke color is not taken from the current context + // therefore we have to set it explicitly + if ( fontattr.GetValue(kCTStrokeWidthAttributeName) != NULL) + { + setColorsInLine = true; + inlinefontattr = fontattr.CreateMutableCopy(); + inlinefontattr.SetValue(kCTForegroundColorFromContextAttributeName, kCFBooleanFalse); + inlinefontattr.SetValue(kCTForegroundColorAttributeName,col); + inlinefontattr.SetValue(kCTStrokeColorAttributeName,col); + } + + wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, setColorsInLine ? inlinefontattr : fontattr ) ); wxCFRef line( CTLineCreateWithAttributedString(attrtext) ); y += CTFontGetAscent(font);