From aec62f376e27f193cda33ede6e98537988644b8f Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 19 Mar 2013 11:38:31 +0000 Subject: [PATCH] Fix for OSX10.4 fonts. --- .../juce_graphics/native/juce_mac_Fonts.mm | 64 ++++++++++--------- .../native/juce_mac_NSViewComponentPeer.mm | 6 +- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/modules/juce_graphics/native/juce_mac_Fonts.mm b/modules/juce_graphics/native/juce_mac_Fonts.mm index 4fd3b7f264..051a56f66f 100644 --- a/modules/juce_graphics/native/juce_mac_Fonts.mm +++ b/modules/juce_graphics/native/juce_mac_Fonts.mm @@ -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; } diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 2684c2b297..f33e68f8c5 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -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; }