diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index 8b2444cf6f..2cd8f78f51 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -222,6 +222,8 @@ void TextLayout::draw (Graphics& g, Rectangle area) const auto origin = justification.appliedToRectangle (Rectangle (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 area) const } } } + + context.restoreState(); } void TextLayout::createLayout (const AttributedString& text, float maxWidth) diff --git a/modules/juce_graphics/native/juce_mac_Fonts.mm b/modules/juce_graphics/native/juce_mac_Fonts.mm index 6ae7035d04..051df78cf2 100644 --- a/modules/juce_graphics/native/juce_mac_Fonts.mm +++ b/modules/juce_graphics/native/juce_mac_Fonts.mm @@ -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); }