diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-12-10 17:57:26 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-12-11 23:41:47 +0000 |
commit | f10b98084064f5d53717c8364048562d373a7f88 (patch) | |
tree | c8f59193ef3f187ebdf204d8c127045fec1988e5 /tests/manual | |
parent | ab448f731ecd8437c7c5c8b96a0e7f419ec3a7ca (diff) |
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>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/textrendering/nativetext/main.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/tests/manual/textrendering/nativetext/main.cpp b/tests/manual/textrendering/nativetext/main.cpp index 5c7621e61f..3fb78858f0 100644 --- a/tests/manual/textrendering/nativetext/main.cpp +++ b/tests/manual/textrendering/nativetext/main.cpp @@ -101,7 +101,9 @@ public: 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.end(); @@ -152,13 +154,22 @@ public: if (font().styleStrategy() & QFont::NoAntialias) CGContextSetShouldAntialias(ctx, false); - // Retain count already tracked by QMacCGContext above - NSGraphicsContext.currentContext = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES]; - [text().toNSString() drawAtPoint:CGPointZero withAttributes:@{ - NSFontAttributeName : (NSFont *)fontEngine->handle(), - NSForegroundColorAttributeName : nsColor - }]; - NSGraphicsContext.currentContext = nil; + // Flip to what CT expects + CGContextScaleCTM(ctx, 1, -1); + 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(), + NSForegroundColorAttributeName : nsColor + } + ]; + + QCFType<CTLineRef> line = CTLineCreateWithAttributedString(CFAttributedStringRef([attributedString autorelease])); + CTLineDraw(line, ctx); #endif } |