From b7c69a8dadc4b30424fede3778ffd37347de1e5e Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Thu, 1 Dec 2011 14:15:00 +0100 Subject: [PATCH] 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: Pending --- src/gui/text/qfontengine_coretext.mm | 17 +++++++++++++++-- src/gui/text/qfontengine_coretext_p.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfontengine_coretext.mm b/src/gui/text/qfontengine_coretext.mm index 153451e..7fc51a1 100644 --- a/src/gui/text/qfontengine_coretext.mm +++ b/src/gui/text/qfontengine_coretext.mm @@ -94,8 +94,15 @@ QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const QCFString &name, const } transform = CGAffineTransformIdentity; + transformAdvances = false; if (fontDef.stretch != 100) { transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); + SInt32 majorVersion = 0; + SInt32 minorVersion = 0; + Gestalt(gestaltSystemVersionMajor, &majorVersion); + Gestalt(gestaltSystemVersionMinor, &minorVersion); + if (majorVersion == 10 && minorVersion >= 7) + transformAdvances = true; } QCFType descriptor = CTFontDescriptorCreateWithNameAndSize(name, fontDef.pixelSize); @@ -319,9 +326,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, transform); + + 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(); @@ -330,6 +341,8 @@ bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLay } CGSize lastGlyphAdvance; CTFontGetAdvancesForGlyphs(runFont, kCTFontHorizontalOrientation, tmpGlyphs + glyphCount - 1, &lastGlyphAdvance, 1); + if (transformAdvances) + lastGlyphAdvance = CGSizeApplyAffineTransform(lastGlyphAdvance, transform); outGlyphs[rtl ? 0 : (glyphCount - 1)] = tmpGlyphs[glyphCount - 1] | fontIndex; outAdvances_x[rtl ? 0 : (glyphCount - 1)] = 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 attributeDict; CGAffineTransform transform; friend class QFontDialogPrivate; + bool transformAdvances; }; CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef); -- 1.7.5.4