Browse Source

Workaround for an Apple font bug in 10.6.

tags/2021-05-28
jules 13 years ago
parent
commit
5d009a2b73
1 changed files with 38 additions and 3 deletions
  1. +38
    -3
      modules/juce_graphics/native/juce_mac_Fonts.mm

+ 38
- 3
modules/juce_graphics/native/juce_mac_Fonts.mm View File

@@ -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…
Cancel
Save