mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-21 01:24:21 +00:00
Workaround for an Apple font bug in 10.6.
This commit is contained in:
parent
6d44c8372f
commit
5d009a2b73
1 changed files with 38 additions and 3 deletions
|
|
@ -43,8 +43,38 @@ namespace CoreTextTypeLayout
|
|||
return style;
|
||||
}
|
||||
|
||||
static CTFontRef createCTFont (const Font& font, const float fontSize,
|
||||
const bool applyScaleFactor)
|
||||
// Workaround for Apple bug in CTFontCreateWithFontDescriptor in Garageband/Logic on 10.6
|
||||
#if JUCE_MAC && ((! defined (MAC_OS_X_VERSION_10_7)) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7)
|
||||
static CTFontRef getFontWithTrait (CTFontRef ctFontRef, CTFontSymbolicTraits trait)
|
||||
{
|
||||
CTFontRef newFont = CTFontCreateCopyWithSymbolicTraits (ctFontRef, 0.0f, nullptr, trait, trait);
|
||||
if (newFont == nullptr)
|
||||
return ctFontRef;
|
||||
|
||||
CFRelease (ctFontRef);
|
||||
return newFont;
|
||||
}
|
||||
|
||||
static CTFontRef useStyleFallbackIfNecessary (CTFontRef ctFontRef, CFStringRef cfFontFamily,
|
||||
const float fontSize, const Font& font)
|
||||
{
|
||||
CFStringRef cfActualFontFamily = (CFStringRef) CTFontCopyAttribute (ctFontRef, kCTFontFamilyNameAttribute);
|
||||
|
||||
if (CFStringCompare (cfFontFamily, cfActualFontFamily, 0) != kCFCompareEqualTo)
|
||||
{
|
||||
CFRelease (ctFontRef);
|
||||
ctFontRef = CTFontCreateWithName (cfFontFamily, fontSize, nullptr);
|
||||
|
||||
if (font.isItalic()) ctFontRef = getFontWithTrait (ctFontRef, kCTFontItalicTrait);
|
||||
if (font.isBold()) ctFontRef = getFontWithTrait (ctFontRef, kCTFontBoldTrait);
|
||||
}
|
||||
|
||||
CFRelease (cfActualFontFamily);
|
||||
return ctFontRef;
|
||||
}
|
||||
#endif
|
||||
|
||||
static CTFontRef createCTFont (const Font& font, const float fontSize, const bool applyScaleFactor)
|
||||
{
|
||||
CFStringRef cfFontFamily = FontStyleHelpers::getConcreteFamilyName (font).toCFString();
|
||||
CFStringRef cfFontStyle = findBestAvailableStyle (font.getTypefaceName(),
|
||||
|
|
@ -58,7 +88,6 @@ namespace CoreTextTypeLayout
|
|||
&kCFTypeDictionaryKeyCallBacks,
|
||||
&kCFTypeDictionaryValueCallBacks);
|
||||
CFRelease (cfFontStyle);
|
||||
CFRelease (cfFontFamily);
|
||||
|
||||
CTFontDescriptorRef ctFontDescRef = CTFontDescriptorCreateWithAttributes (fontDescAttributes);
|
||||
CFRelease (fontDescAttributes);
|
||||
|
|
@ -66,6 +95,12 @@ namespace CoreTextTypeLayout
|
|||
CTFontRef ctFontRef = CTFontCreateWithFontDescriptor (ctFontDescRef, fontSize, nullptr);
|
||||
CFRelease (ctFontDescRef);
|
||||
|
||||
#if JUCE_MAC && ((! defined (MAC_OS_X_VERSION_10_7)) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7)
|
||||
ctFontRef = useStyleFallbackIfNecessary (ctFontRef, cfFontFamily, fontSize, font);
|
||||
#endif
|
||||
|
||||
CFRelease (cfFontFamily);
|
||||
|
||||
if (applyScaleFactor)
|
||||
{
|
||||
CGFontRef cgFontRef = CTFontCopyGraphicsFont (ctFontRef, nullptr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue