1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-26 02:14:22 +00:00

Fixed an issue rendering AttributedStrings containing horizontal font scale

This commit is contained in:
Tom Poole 2021-03-25 15:45:28 +00:00
parent a9ad07a945
commit 2367d648f4
3 changed files with 27 additions and 8 deletions

View file

@ -676,8 +676,7 @@ void CoreGraphicsContext::drawGlyph (int glyphNumber, const AffineTransform& tra
bool CoreGraphicsContext::drawTextLayout (const AttributedString& text, const Rectangle<float>& area)
{
CoreTextTypeLayout::drawToCGContext (text, area, context.get(), (float) flipHeight);
return true;
return CoreTextTypeLayout::drawToCGContext (text, area, context.get(), (float) flipHeight);
}
CoreGraphicsContext::SavedState::SavedState()

View file

@ -324,9 +324,23 @@ namespace CoreTextTypeLayout
return range.getLength();
}
static void drawToCGContext (const AttributedString& text, const Rectangle<float>& area,
static bool areAllFontsDefaultWidth (const AttributedString& text)
{
auto numCharacterAttributes = text.getNumAttributes();
for (int i = 0; i < numCharacterAttributes; ++i)
if (text.getAttribute (i).font.getHorizontalScale() != 1.0f)
return false;
return true;
}
static bool drawToCGContext (const AttributedString& text, const Rectangle<float>& area,
const CGContextRef& context, float flipHeight)
{
if (! areAllFontsDefaultWidth (text))
return false;
auto framesetter = createCTFramesetter (text);
// Ugly hack to fix a bug in OS X Sierra where the CTFrame needs to be slightly
@ -377,6 +391,8 @@ namespace CoreTextTypeLayout
CGContextRestoreGState (context);
CGContextSetTextMatrix (context, textMatrix);
return true;
}
static void createLayout (TextLayout& glyphLayout, const AttributedString& text)
@ -817,7 +833,7 @@ static bool canAllTypefacesBeUsedInLayout (const AttributedString& text)
for (int i = 0; i < numCharacterAttributes; ++i)
{
if (auto tf = dynamic_cast<OSXTypeface*> (text.getAttribute(i).font.getTypeface()))
if (auto tf = dynamic_cast<OSXTypeface*> (text.getAttribute (i).font.getTypeface()))
if (tf->canBeUsedForLayout)
continue;
@ -829,7 +845,7 @@ static bool canAllTypefacesBeUsedInLayout (const AttributedString& text)
bool TextLayout::createNativeLayout (const AttributedString& text)
{
if (canAllTypefacesBeUsedInLayout (text))
if (canAllTypefacesBeUsedInLayout (text) && CoreTextTypeLayout::areAllFontsDefaultWidth (text))
{
CoreTextTypeLayout::createLayout (*this, text);
return true;

View file

@ -419,13 +419,17 @@ namespace DirectWriteTypeLayout
}
}
static bool canAllTypefacesBeUsedInLayout (const AttributedString& text)
static bool canAllTypefacesAndFontsBeUsedInLayout (const AttributedString& text)
{
auto numCharacterAttributes = text.getNumAttributes();
for (int i = 0; i < numCharacterAttributes; ++i)
if (dynamic_cast<WindowsDirectWriteTypeface*> (text.getAttribute(i).font.getTypeface()) == nullptr)
{
const auto& font = text.getAttribute (i).font;
if (font.getHorizontalScale() != 1.0f || dynamic_cast<WindowsDirectWriteTypeface*> (font.getTypeface()) == nullptr)
return false;
}
return true;
}
@ -435,7 +439,7 @@ static bool canAllTypefacesBeUsedInLayout (const AttributedString& text)
bool TextLayout::createNativeLayout (const AttributedString& text)
{
#if JUCE_USE_DIRECTWRITE
if (! canAllTypefacesBeUsedInLayout (text))
if (! canAllTypefacesAndFontsBeUsedInLayout (text))
return false;
SharedResourcePointer<Direct2DFactories> factories;