nativetext: Fix baseline positioning for CoreText
The Qt and CoreText positioning is now in sync. Change-Id: I0cbb5b150d1bef732674b8d42c64a040773a62ab Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
ab448f731e
commit
f10b980840
@ -101,7 +101,9 @@ public:
|
|||||||
|
|
||||||
const int ascent = fontMetrics().ascent();
|
const int ascent = fontMetrics().ascent();
|
||||||
|
|
||||||
p.setPen(Qt::magenta);
|
QPen metricsPen(Qt::magenta, 1.0);
|
||||||
|
metricsPen.setCosmetic(true);
|
||||||
|
p.setPen(metricsPen);
|
||||||
p.drawLine(QPoint(0, ascent), QPoint(width(), ascent));
|
p.drawLine(QPoint(0, ascent), QPoint(width(), ascent));
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
@ -152,13 +154,22 @@ public:
|
|||||||
if (font().styleStrategy() & QFont::NoAntialias)
|
if (font().styleStrategy() & QFont::NoAntialias)
|
||||||
CGContextSetShouldAntialias(ctx, false);
|
CGContextSetShouldAntialias(ctx, false);
|
||||||
|
|
||||||
// Retain count already tracked by QMacCGContext above
|
// Flip to what CT expects
|
||||||
NSGraphicsContext.currentContext = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES];
|
CGContextScaleCTM(ctx, 1, -1);
|
||||||
[text().toNSString() drawAtPoint:CGPointZero withAttributes:@{
|
CGContextTranslateCTM(ctx, 0, -height());
|
||||||
|
|
||||||
|
// Set up baseline
|
||||||
|
CGContextSetTextPosition(ctx, 0, height() - fontMetrics().ascent());
|
||||||
|
|
||||||
|
auto *attributedString = [[NSAttributedString alloc] initWithString:text().toNSString()
|
||||||
|
attributes:@{
|
||||||
NSFontAttributeName : (NSFont *)fontEngine->handle(),
|
NSFontAttributeName : (NSFont *)fontEngine->handle(),
|
||||||
NSForegroundColorAttributeName : nsColor
|
NSForegroundColorAttributeName : nsColor
|
||||||
}];
|
}
|
||||||
NSGraphicsContext.currentContext = nil;
|
];
|
||||||
|
|
||||||
|
QCFType<CTLineRef> line = CTLineCreateWithAttributedString(CFAttributedStringRef([attributedString autorelease]));
|
||||||
|
CTLineDraw(line, ctx);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user