Browse Source

Workaround for layout of CustomTypefaces on OSX

tags/2021-05-28
jules 11 years ago
parent
commit
fda9e97298
2 changed files with 18 additions and 3 deletions
  1. +6
    -1
      modules/juce_graphics/fonts/juce_CustomTypeface.h
  2. +12
    -2
      modules/juce_graphics/native/juce_mac_Fonts.mm

+ 6
- 1
modules/juce_graphics/fonts/juce_CustomTypeface.h View File

@@ -52,6 +52,11 @@ public:
/** Loads a typeface from a previously saved stream.
The stream must have been created by writeToStream().
NOTE! Since this class was written, support was added for loading real font files from
memory, so for most people, using Typeface::createSystemTypefaceFor() to load a real font
is more appropriate than using this class to store it in a proprietary format.
@see writeToStream
*/
explicit CustomTypeface (InputStream& serialisedTypefaceStream);
@@ -116,7 +121,7 @@ public:
NOTE! Since this class was written, support was added for loading real font files from
memory, so for most people, using Typeface::createSystemTypefaceFor() to load a real font
is more appropriate than using this class to store it in a proprietory format.
is more appropriate than using this class to store it in a proprietary format.
*/
bool writeToStream (OutputStream& outputStream);


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

@@ -1280,15 +1280,25 @@ Typeface::Ptr Font::getDefaultTypefaceForFont (const Font& font)
}
#if JUCE_CORETEXT_AVAILABLE
static bool containsNoMemoryTypefaces (const AttributedString& text)
static bool canAllTypefacesBeUsedInLayout (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;
}
else if (dynamic_cast<CustomTypeface*> (f->getTypeface()) != nullptr)
{
return false;
}
}
}
return true;
}
@@ -1299,7 +1309,7 @@ bool TextLayout::createNativeLayout (const AttributedString& text)
#if JUCE_CORETEXT_AVAILABLE
// 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))
if (canAllTypefacesBeUsedInLayout (text))
{
CoreTextTypeLayout::createLayout (*this, text);
return true;


Loading…
Cancel
Save