mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-16 00:34:19 +00:00
CoreGraphics: Fixed a text layout bug
This commit is contained in:
parent
bc25355b71
commit
ece16bce70
2 changed files with 24 additions and 13 deletions
|
|
@ -93,7 +93,7 @@ private:
|
|||
FillType fillType;
|
||||
Font font;
|
||||
CGFontRef fontRef = {};
|
||||
CGAffineTransform fontTransform;
|
||||
AffineTransform fontTransform, inverseFontTransform;
|
||||
CGGradientRef gradient = {};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -623,9 +623,19 @@ void CoreGraphicsContext::setFont (const Font& newFont)
|
|||
CGContextSetFont (context, state->fontRef);
|
||||
CGContextSetFontSize (context, state->font.getHeight() * osxTypeface->fontHeightToPointsFactor);
|
||||
|
||||
state->fontTransform = osxTypeface->renderingTransform;
|
||||
state->fontTransform.a *= state->font.getHorizontalScale();
|
||||
CGContextSetTextMatrix (context, state->fontTransform);
|
||||
auto fontTransform = osxTypeface->renderingTransform;
|
||||
fontTransform.a *= state->font.getHorizontalScale();
|
||||
CGContextSetTextMatrix (context, fontTransform);
|
||||
|
||||
auto cgTransformToJuceTransform = [](CGAffineTransform& t) -> AffineTransform
|
||||
{
|
||||
return { (float) t.a, (float) t.b, (float) t.tx,
|
||||
(float) t.c, (float) t.d, (float) t.ty };
|
||||
};
|
||||
|
||||
state->fontTransform = cgTransformToJuceTransform (fontTransform);
|
||||
auto inverseFontTransform = CGAffineTransformInvert (fontTransform);
|
||||
state->inverseFontTransform = cgTransformToJuceTransform (inverseFontTransform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -641,21 +651,20 @@ void CoreGraphicsContext::drawGlyph (int glyphNumber, const AffineTransform& tra
|
|||
{
|
||||
if (transform.isOnlyTranslation())
|
||||
{
|
||||
CGContextSetTextMatrix (context, state->fontTransform); // have to set this each time, as it's not saved as part of the state
|
||||
auto t = transform.followedBy (state->inverseFontTransform);
|
||||
|
||||
CGGlyph glyphs[1] = { (CGGlyph) glyphNumber };
|
||||
CGPoint positions[1] = { { transform.getTranslationX(), flipHeight - roundToInt (transform.getTranslationY()) } };
|
||||
CGPoint positions[1] = { { t.getTranslationX(), flipHeight - roundToInt (t.getTranslationY()) } };
|
||||
CGContextShowGlyphsAtPositions (context, glyphs, positions, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
CGContextSaveGState (context);
|
||||
flip();
|
||||
applyTransform (transform);
|
||||
|
||||
auto t = state->fontTransform;
|
||||
t.d = -t.d;
|
||||
CGContextSetTextMatrix (context, t);
|
||||
flip();
|
||||
auto fontTransform = state->fontTransform;
|
||||
fontTransform.mat11 = -fontTransform.mat11;
|
||||
applyTransform (fontTransform.followedBy (state->inverseFontTransform).followedBy (transform));
|
||||
|
||||
CGGlyph glyphs[1] = { (CGGlyph) glyphNumber };
|
||||
CGPoint positions[1] = { { 0.0f, 0.0f } };
|
||||
|
|
@ -682,13 +691,15 @@ bool CoreGraphicsContext::drawTextLayout (const AttributedString& text, const Re
|
|||
}
|
||||
|
||||
CoreGraphicsContext::SavedState::SavedState()
|
||||
: font (1.0f), fontTransform (CGAffineTransformIdentity)
|
||||
: font (1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
CoreGraphicsContext::SavedState::SavedState (const SavedState& other)
|
||||
: fillType (other.fillType), font (other.font), fontRef (other.fontRef),
|
||||
fontTransform (other.fontTransform), gradient (other.gradient)
|
||||
fontTransform (other.fontTransform),
|
||||
inverseFontTransform (other.inverseFontTransform),
|
||||
gradient (other.gradient)
|
||||
{
|
||||
if (gradient != nullptr)
|
||||
CGGradientRetain (gradient);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue