From b625ff4c7b68505b6d299d688734c9c1d448cb80 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 4 Sep 2012 13:54:07 +0200 Subject: Fix printing with OS X platform plugin 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 change. The default dpi for the screen is 72, thus the scale factor is destinationDpi/72. Since pixelSize = pointSize / 72 * dpi, the pixelSize is actually the scaled point size for the destination dpi, thus we pass in that instead. Note that this only works because the default screen dpi on Mac is 72. You can look at the CoreText font database in Qt 4.8 to verify that the same trick is used there. When 96 dpi is explicitly set (specifically for autotests), we need to fall back to the old behavior, since the OSX platform plugin will then use 72 for some fonts and 96 for others making it impossible to detect the DPI in a consistent way. The correct fix would be to pass in the dpi to the function, but until that fix can be made, we just use the old code to keep the autotests passing. Task-number: QTBUG-25555 Change-Id: Id20a273549c3abf3db56ef1c48553c0958c48d61 Reviewed-by: Qt Doc Bot Reviewed-by: Jiang Jiang --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 7d778e13a3..29db7a6e23 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -47,6 +47,7 @@ #include "qcoretextfontdatabase_p.h" #include "qfontengine_coretext_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -305,8 +306,19 @@ QFontEngine *QCoreTextFontDatabase::fontEngine(const QFontDef &f, QUnicodeTables { Q_UNUSED(script); + 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; + CTFontDescriptorRef descriptor = (CTFontDescriptorRef) usrPtr; - CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, f.pointSize, NULL); + CTFontRef font = CTFontCreateWithFontDescriptor(descriptor, scaledPointSize, NULL); if (font) { QFontEngine *engine = new QCoreTextFontEngine(font, f); engine->fontDef = f; -- cgit v1.2.3