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
This commit is contained in:
Stefan Csomor
2018-10-22 17:43:31 +02:00
parent a69a43bc53
commit 7dfbe50fc0
2 changed files with 23 additions and 1 deletions

View File

@@ -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<CFMutableDictionaryRef>

View File

@@ -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<CFAttributedStringRef> 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<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, setColorsInLine ? inlinefontattr : fontattr ) );
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
y += CTFontGetAscent(font);