From 35793cea28c4bd1d6d8fbae884d9ae3c19745c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 25 Jun 2015 14:26:06 +0200 Subject: CoreText: Respect Qt::AA_Use96Dpi flag when creating CT fonts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 1f000421cc..357228db14 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -45,7 +45,6 @@ #include "qcoretextfontdatabase_p.h" #include "qfontengine_coretext_p.h" #include -#include #include #ifndef QT_NO_FREETYPE #include @@ -399,17 +398,14 @@ QFontEngine *QCoreTextFontDatabase::fontEngine(const QFontDef &f, void *usrPtr) } #endif + // 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 qcocoaintegration.mm) 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) { -- cgit v1.2.3