1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

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

This commit is contained in:
Tom Poole 2019-12-30 15:12:02 +00:00
parent 008f097e12
commit 1d2fc2ddd5
2 changed files with 16 additions and 11 deletions

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)

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);
}