diff options
author | Jiang Jiang <jiang.jiang@nokia.com> | 2011-12-01 13:15:00 (GMT) |
---|---|---|
committer | Jiang Jiang <jiang.jiang@nokia.com> | 2011-12-01 15:09:20 (GMT) |
commit | bc25cfdd65452efa226cbd544c9ae9803eb6748a (patch) | |
tree | 47c80a8949117cd02d2f6330550910bd7a7e290a /src/gui | |
parent | d014bb648f3e8499a87c180274af5cc7e16e72de (diff) | |
download | Qt-bc25cfdd65452efa226cbd544c9ae9803eb6748a.zip Qt-bc25cfdd65452efa226cbd544c9ae9803eb6748a.tar.gz Qt-bc25cfdd65452efa226cbd544c9ae9803eb6748a.tar.bz2 |
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
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/text/qfontengine_coretext.mm | 10 | ||||
-rw-r--r-- | 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 153451e..154c44f 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<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithNameAndSize(name, fontDef.pixelSize); QCFType<CTFontRef> 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 4bd80be..495e638 100644 --- a/src/gui/text/qfontengine_coretext_p.h +++ b/src/gui/text/qfontengine_coretext_p.h @@ -146,6 +146,7 @@ private: mutable QCFType<CFMutableDictionaryRef> attributeDict; CGAffineTransform transform; friend class QFontDialogPrivate; + bool transformAdvances; }; CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef); |