Browse Source

Fix for OSX10.4 fonts.

tags/2021-05-28
jules 13 years ago
parent
commit
aec62f376e
2 changed files with 37 additions and 33 deletions
  1. +35
    -29
      modules/juce_graphics/native/juce_mac_Fonts.mm
  2. +2
    -4
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm

+ 35
- 29
modules/juce_graphics/native/juce_mac_Fonts.mm View File

@@ -724,48 +724,33 @@ public:
[nsFont retain];
ascent = std::abs ((float) [nsFont ascender]);
float totalSize = ascent + std::abs ((float) [nsFont descender]);
ascent /= totalSize;
pathTransform = AffineTransform::identity.scale (1.0f / totalSize);
#if SUPPORT_ONLY_10_4_FONTS
ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
if (atsFont == 0)
atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
fontRef = CGFontCreateWithPlatformFont (&atsFont);
const float totalHeight = std::abs ([nsFont ascender]) + std::abs ([nsFont descender]);
unitsToHeightScaleFactor = 1.0f / totalHeight;
fontHeightToPointsFactor = referenceFontSize / totalHeight;
initWithATSFont();
#else
#if SUPPORT_10_4_FONTS
if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
{
ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
if (atsFont == 0)
atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
fontRef = CGFontCreateWithPlatformFont (&atsFont);
const float totalHeight = std::abs ([nsFont ascender]) + std::abs ([nsFont descender]);
unitsToHeightScaleFactor = 1.0f / totalHeight;
fontHeightToPointsFactor = referenceFontSize / totalHeight;
initWithATSFont();
}
else
#endif
{
fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
const float totalHeight = std::abs ((float) CGFontGetAscent (fontRef)) + std::abs ((float) CGFontGetDescent (fontRef));
const float absAscent = std::abs ((float) CGFontGetAscent (fontRef));
const float totalHeight = absAscent + std::abs ((float) CGFontGetDescent (fontRef));
ascent = absAscent / totalHeight;
unitsToHeightScaleFactor = 1.0f / totalHeight;
fontHeightToPointsFactor = referenceFontSize / totalHeight;
}
const float nsFontAscent = std::abs ([nsFont ascender]);
const float nsFontDescent = std::abs ([nsFont descender]);
fontHeightToPointsFactor = referenceFontSize / (nsFontAscent + nsFontDescent);
}
#endif
pathTransform = AffineTransform::identity.scale (unitsToHeightScaleFactor);
}
~OSXTypeface()
@@ -778,6 +763,27 @@ public:
CGFontRelease (fontRef);
}
#if SUPPORT_10_4_FONTS
void initWithATSFont()
{
ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
if (atsFont == 0)
atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
fontRef = CGFontCreateWithPlatformFont (&atsFont);
const float absAscent = std::abs ([nsFont ascender]);
const float absDescent = std::abs ([nsFont descender]);
const float totalHeight = absAscent + absDescent;
unitsToHeightScaleFactor = 1.0f / totalHeight;
fontHeightToPointsFactor = referenceFontSize / totalHeight;
ascent = absAscent / totalHeight;
}
#endif
float getAscent() const { return ascent; }
float getDescent() const { return 1.0f - ascent; }
float getHeightToPointsFactor() const { return fontHeightToPointsFactor; }


+ 2
- 4
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -725,10 +725,8 @@ public:
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
bool redirectPerformKeyEquivalent (NSEvent* ev)
{
if ([ev type] == NSKeyDown)
return redirectKeyDown (ev);
else if ([ev type] == NSKeyUp)
return redirectKeyUp (ev);
if ([ev type] == NSKeyDown) return redirectKeyDown (ev);
if ([ev type] == NSKeyUp) return redirectKeyUp (ev);
return false;
}


Loading…
Cancel
Save