summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-01-21 12:55:42 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-01-22 09:32:44 +0100
commit586fd042345b619acceafb13e84b912863961e56 (patch)
tree6a8634f7fe3eb31d79474e1a8ade300a69622379
parent0c4c841ce8cd3a3b8ebc636dd41f7c7a2011991d (diff)
OS X/iOS: Fix stretched font rendering
Setting the stretch of a QFont did not work correctly on OS X or iOS. Two things are needed to make it work: First of all, we need to properly set the transform when creating the CTFont. In addition, we need to manually scale the advances, as CTRunGetPositions() does not do this for us. On OS X 10.6, however, there was a regression and CTRunGetPositions() would return scaled positions, so we exclude the step to scale the advances on this particular version. This is an adaptation of bc25cfdd65452efa226cbd544c9ae9803eb6748a in Qt 4. [ChangeLog][QtGui][OS X/iOS] Fixed a bug when rendering fonts that were set to be stretched. Task-number: QTBUG-43801 Change-Id: I4902a9f5e29299761e3c2c5c6d6d80ee1dea1a25 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
-rw-r--r--src/gui/text/qtextengine.cpp9
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm5
2 files changed, 13 insertions, 1 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index d156124b98..8f60847250 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1237,6 +1237,15 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st
}
#ifdef Q_OS_MAC
+ // CTRunGetPosition has a bug which applies matrix on 10.6, so we disable
+ // scaling the advances for this particular version
+ if (actualFontEngine->fontDef.stretch != 100
+ && QSysInfo::MacintoshVersion != QSysInfo::MV_10_6) {
+ QFixed stretch = QFixed(actualFontEngine->fontDef.stretch) / QFixed(100);
+ for (uint i = 0; i < num_glyphs; ++i)
+ g.advances[i] *= stretch;
+ }
+
if (actualFontEngine->fontDef.styleStrategy & QFont::ForceIntegerMetrics) {
for (uint i = 0; i < num_glyphs; ++i)
g.advances[i] = g.advances[i].round();
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
index 5a6c5de0b4..fe408305e0 100644
--- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
+++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
@@ -370,6 +370,8 @@ void QCoreTextFontDatabase::releaseHandle(void *handle)
CFRelease(CTFontDescriptorRef(handle));
}
+extern CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef);
+
QFontEngine *QCoreTextFontDatabase::fontEngine(const QFontDef &f, void *usrPtr)
{
qreal scaledPointSize = f.pixelSize;
@@ -384,7 +386,8 @@ QFontEngine *QCoreTextFontDatabase::fontEngine(const QFontDef &f, void *usrPtr)
scaledPointSize = f.pointSize;
CTFontDescriptorRef descriptor = (CTFontDescriptorRef) usrPtr;
- CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, scaledPointSize, NULL);
+ CGAffineTransform matrix = qt_transform_from_fontdef(f);
+ CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, scaledPointSize, &matrix);
if (font) {
QFontEngine *engine = new QCoreTextFontEngine(font, f);
engine->fontDef = f;