From bc25cfdd65452efa226cbd544c9ae9803eb6748a Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Thu, 1 Dec 2011 14:15:00 +0100 Subject: Fix stretched font positions in Lion In Mac OS X 10.7 and up, According to http://lists.apple.com/archives/Coretext-dev/2011/Nov/msg00006.html we need to manually apply transform matrix to advances if text matrix as been applied, CTRunGetPositions won't apply it. Task-number: QTBUG-22825 Reviewed-by: Eskil --- src/gui/text/qfontengine_coretext.mm | 10 ++++++++-- src/gui/text/qfontengine_coretext_p.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfontengine_coretext.mm b/src/gui/text/qfontengine_coretext.mm index 153451e74b..154c44ff54 100644 --- a/src/gui/text/qfontengine_coretext.mm +++ b/src/gui/text/qfontengine_coretext.mm @@ -97,6 +97,7 @@ QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const QCFString &name, const if (fontDef.stretch != 100) { transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); } + transformAdvances = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7; QCFType descriptor = CTFontDescriptorCreateWithNameAndSize(name, fontDef.pixelSize); QCFType baseFont = CTFontCreateWithFontDescriptor(descriptor, fontDef.pixelSize, &transform); @@ -225,6 +226,7 @@ bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLay Q_ASSERT((CTRunGetStatus(run) & kCTRunStatusRightToLeft) == rtl); CFRange stringRange = CTRunGetStringRange(run); + CGAffineTransform textMatrix = CTRunGetTextMatrix(run); int prepend = 0; #if MAC_OS_X_VERSION_MAX_ALLOWED == MAC_OS_X_VERSION_10_5 UniChar beginGlyph = CFStringGetCharacterAtIndex(cfstring, stringRange.location); @@ -319,9 +321,13 @@ bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLay for (CFIndex i = 0; i < glyphCount - 1; ++i) { int idx = rtlOffset + rtlSign * i; outGlyphs[idx] = tmpGlyphs[i] | fontIndex; - outAdvances_x[idx] = QFixed::fromReal(tmpPoints[i + 1].x - tmpPoints[i].x); + CGSize advance = CGSizeMake(tmpPoints[i + 1].x - tmpPoints[i].x, tmpPoints[i].y - tmpPoints[i + 1].y); + if (transformAdvances) + advance = CGSizeApplyAffineTransform(advance, textMatrix); + + outAdvances_x[idx] = QFixed::fromReal(advance.width); // Use negative y advance for flipped coordinate system - outAdvances_y[idx] = QFixed::fromReal(tmpPoints[i].y - tmpPoints[i + 1].y); + outAdvances_y[idx] = QFixed::fromReal(advance.height); if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { outAdvances_x[idx] = outAdvances_x[idx].round(); diff --git a/src/gui/text/qfontengine_coretext_p.h b/src/gui/text/qfontengine_coretext_p.h index 4bd80beb00..495e6387fc 100644 --- a/src/gui/text/qfontengine_coretext_p.h +++ b/src/gui/text/qfontengine_coretext_p.h @@ -146,6 +146,7 @@ private: mutable QCFType attributeDict; CGAffineTransform transform; friend class QFontDialogPrivate; + bool transformAdvances; }; CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef); -- cgit v1.2.1