Browse Source

macOS: Fixed an issue restoring graphics state after drawing an AttributedString

tags/2021-05-28
Tom Poole 6 years ago
parent
commit
1d2fc2ddd5
2 changed files with 16 additions and 11 deletions
  1. +4
    -0
      modules/juce_graphics/fonts/juce_TextLayout.cpp
  2. +12
    -11
      modules/juce_graphics/native/juce_mac_Fonts.mm

+ 4
- 0
modules/juce_graphics/fonts/juce_TextLayout.cpp View File

@@ -222,6 +222,8 @@ void TextLayout::draw (Graphics& g, Rectangle<float> area) const
auto origin = justification.appliedToRectangle (Rectangle<float> (width, getHeight()), area).getPosition();
auto& context = g.getInternalContext();
context.saveState();
auto clip = context.getClipBounds();
auto clipTop = clip.getY() - origin.y;
auto clipBottom = clip.getBottom() - origin.y;
@@ -257,6 +259,8 @@ void TextLayout::draw (Graphics& g, Rectangle<float> area) const
}
}
}
context.restoreState();
}
void TextLayout::createLayout (const AttributedString& text, float maxWidth)


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

@@ -276,10 +276,10 @@ namespace CoreTextTypeLayout
CTParagraphStyleSetting settings[] =
{
{ kCTParagraphStyleSpecifierAlignment, sizeof (CTTextAlignment), &ctTextAlignment },
{ kCTParagraphStyleSpecifierLineBreakMode, sizeof (CTLineBreakMode), &ctLineBreakMode },
{ kCTParagraphStyleSpecifierAlignment, sizeof (CTTextAlignment), &ctTextAlignment },
{ kCTParagraphStyleSpecifierLineBreakMode, sizeof (CTLineBreakMode), &ctLineBreakMode },
{ kCTParagraphStyleSpecifierBaseWritingDirection, sizeof (CTWritingDirection), &ctWritingDirection},
{ kCTParagraphStyleSpecifierLineSpacingAdjustment, sizeof (CGFloat), &ctLineSpacing }
{ kCTParagraphStyleSpecifierLineSpacingAdjustment, sizeof (CGFloat), &ctLineSpacing }
};
auto ctParagraphStyleRef = CTParagraphStyleCreate (settings, (size_t) numElementsInArray (settings));
@@ -350,24 +350,25 @@ namespace CoreTextTypeLayout
auto frame = createCTFrame (text, CGRectMake ((CGFloat) ctFrameArea.getX(), flipHeight - (CGFloat) ctFrameArea.getBottom(),
(CGFloat) ctFrameArea.getWidth(), (CGFloat) ctFrameArea.getHeight()));
auto textMatrix = CGContextGetTextMatrix (context);
CGContextSaveGState (context);
if (verticalJustification == Justification::verticallyCentred
|| verticalJustification == Justification::bottom)
|| verticalJustification == Justification::bottom)
{
auto adjust = ctFrameArea.getHeight() - findCTFrameHeight (frame);
if (verticalJustification == Justification::verticallyCentred)
adjust *= 0.5f;
CGContextSaveGState (context);
CGContextTranslateCTM (context, 0, -adjust);
CTFrameDraw (frame, context);
CGContextRestoreGState (context);
}
else
{
CTFrameDraw (frame, context);
}
CTFrameDraw (frame, context);
CGContextRestoreGState (context);
CGContextSetTextMatrix (context, textMatrix);
CFRelease (frame);
}


Loading…
Cancel
Save