diff options
authorTor Arne Vestbø <>2015-06-25 14:26:06 +0200
committerTor Arne Vestbø <>2015-09-09 17:18:34 +0000
commit35793cea28c4bd1d6d8fbae884d9ae3c19745c61 (patch)
parentb253f404e8e78c6a29778733c389ea22d2681b03 (diff)
CoreText: Respect Qt::AA_Use96Dpi flag when creating CT fonts
The pixel size passed into QCoreTextFontDatabase::fontEngine() has already been scaled to take the destination DPI into account. In the normal case the destination DPI is the same as the screen's logical DPI, 72, and we end up with the pixel size being equal to the point size. But when the Qt::AA_Use96Dpi flag has been set, e.g. when running tests, the pixel size is larger than the point size, and we need to pass this information to CoreText, otherwise we end up with clipped text rendering. This was evident when looking at the lancelot baselines for OS X, which are produced using QTestLib, and hence run with Qt::AA_Use96Dpi set. Change-Id: Ib0f720bb318b2dc437172a6b712675e3dfe3f7ac Reviewed-by: Eskil Abrahamsen Blomfeldt <> Reviewed-by: Tor Arne Vestbø <>
1 files changed, 6 insertions, 10 deletions
diff --git a/src/platformsupport/fontdatabases/mac/ b/src/platformsupport/fontdatabases/mac/
index 1f000421cc..357228db14 100644
--- a/src/platformsupport/fontdatabases/mac/
+++ b/src/platformsupport/fontdatabases/mac/
@@ -45,7 +45,6 @@
#include "qcoretextfontdatabase_p.h"
#include "qfontengine_coretext_p.h"
#include <QtCore/QSettings>
-#include <QtGui/QGuiApplication>
#include <QtCore/QtEndian>
#include <QtGui/private/qfontengine_ft_p.h>
@@ -399,17 +398,14 @@ QFontEngine *QCoreTextFontDatabase::fontEngine(const QFontDef &f, void *usrPtr)
+ // Since we do not pass in the destination DPI to CoreText when making
+ // the font, we need to pass in a point size which is scaled to include
+ // the DPI. The default DPI for the screen is 72, thus the scale factor
+ // is destinationDpi / 72, but since pixelSize = pointSize / 72 * dpi,
+ // the pixelSize is actually the scaled point size for the destination
+ // DPI, and we can use that directly.
qreal scaledPointSize = f.pixelSize;
- // When 96 DPI is forced, the Mac plugin will use DPI 72 for some
- // fonts (hardcoded in and 96 for others. This
- // discrepancy makes it impossible to find the correct point size
- // here without having the DPI used for the font. Until a proper
- // solution (requiring API change) can be made, we simply fall back
- // to passing in the point size to retain old behavior.
- if (QGuiApplication::testAttribute(Qt::AA_Use96Dpi))
- scaledPointSize = f.pointSize;
CGAffineTransform matrix = qt_transform_from_fontdef(f);
CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, scaledPointSize, &matrix);
if (font) {