Browse Source

Workaround for CoreText layout failure with in-memory typefaces.

tags/2021-05-28
jules 11 years ago
parent
commit
858686d88c
1 changed files with 33 additions and 12 deletions
  1. +33
    -12
      modules/juce_graphics/native/juce_mac_Fonts.mm

+ 33
- 12
modules/juce_graphics/native/juce_mac_Fonts.mm View File

@@ -486,7 +486,7 @@ public:
font.getTypefaceStyle()), font.getTypefaceStyle()),
fontRef (nullptr), fontRef (nullptr),
ctFontRef (nullptr), ctFontRef (nullptr),
fontHeightToPointsFactor (1.0f),
fontHeightToPointsFactor (1.0f), isMemoryFont (false),
renderingTransform (CGAffineTransformIdentity), renderingTransform (CGAffineTransformIdentity),
attributedStringAtts (nullptr), attributedStringAtts (nullptr),
ascent (0.0f), ascent (0.0f),
@@ -505,7 +505,7 @@ public:
: Typeface (String(), String()), : Typeface (String(), String()),
fontRef (nullptr), fontRef (nullptr),
ctFontRef (nullptr), ctFontRef (nullptr),
fontHeightToPointsFactor (1.0f),
fontHeightToPointsFactor (1.0f), isMemoryFont (true),
renderingTransform (CGAffineTransformIdentity), renderingTransform (CGAffineTransformIdentity),
attributedStringAtts (nullptr), attributedStringAtts (nullptr),
ascent (0.0f), ascent (0.0f),
@@ -672,6 +672,8 @@ public:
float fontHeightToPointsFactor; float fontHeightToPointsFactor;
CGAffineTransform renderingTransform; CGAffineTransform renderingTransform;
bool isMemoryFont;
private: private:
CFDictionaryRef attributedStringAtts; CFDictionaryRef attributedStringAtts;
float ascent, unitsToHeightScaleFactor; float ascent, unitsToHeightScaleFactor;
@@ -701,13 +703,12 @@ private:
CTFontRef getCTFontFromTypeface (const Font& f) CTFontRef getCTFontFromTypeface (const Font& f)
{ {
if (OSXTypeface* tf = dynamic_cast <OSXTypeface*> (f.getTypeface()))
if (OSXTypeface* tf = dynamic_cast<OSXTypeface*> (f.getTypeface()))
return tf->ctFontRef; return tf->ctFontRef;
return 0; return 0;
} }
StringArray Font::findAllTypefaceNames() StringArray Font::findAllTypefaceNames()
{ {
StringArray names; StringArray names;
@@ -912,7 +913,7 @@ public:
#if SUPPORT_ONLY_10_4_FONTS #if SUPPORT_ONLY_10_4_FONTS
HeapBlock <NSSize> advances (length); HeapBlock <NSSize> advances (length);
[nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
[nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i)
x += advances[i].width; x += advances[i].width;
@@ -940,7 +941,7 @@ public:
return x * unitsToHeightScaleFactor; return x * unitsToHeightScaleFactor;
} }
void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets) override
void getGlyphPositions (const String& text, Array<int>& resultGlyphs, Array<float>& xOffsets) override
{ {
xOffsets.add (0); xOffsets.add (0);
@@ -1152,8 +1153,8 @@ private:
if (rangeOffset == 0) if (rangeOffset == 0)
return delta + c; return delta + c;
else
return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
} }
} }
@@ -1271,13 +1272,33 @@ Typeface::Ptr Font::getDefaultTypefaceForFont (const Font& font)
return Typeface::createSystemTypefaceFor (newFont); return Typeface::createSystemTypefaceFor (newFont);
} }
#if JUCE_CORETEXT_AVAILABLE
static bool containsNoMemoryTypefaces (const AttributedString& text)
{
const int numCharacterAttributes = text.getNumAttributes();
for (int i = 0; i < numCharacterAttributes; ++i)
if (const Font* const f = text.getAttribute (i)->getFont())
if (OSXTypeface* tf = dynamic_cast<OSXTypeface*> (f->getTypeface()))
if (tf->isMemoryFont)
return false;
return true;
}
#endif
bool TextLayout::createNativeLayout (const AttributedString& text) bool TextLayout::createNativeLayout (const AttributedString& text)
{ {
#if JUCE_CORETEXT_AVAILABLE #if JUCE_CORETEXT_AVAILABLE
CoreTextTypeLayout::createLayout (*this, text);
return true;
#else
// Seems to be an unfathomable bug in CoreText which prevents the layout working with
// typefaces that were loaded from memory, so have to fallback if we hit any of those..
if (containsNoMemoryTypefaces (text))
{
CoreTextTypeLayout::createLayout (*this, text);
return true;
}
#endif
(void) text; (void) text;
return false; return false;
#endif
} }

Loading…
Cancel
Save