summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2012-09-04 13:54:07 +0200
committerQt by Nokia <qt-info@nokia.com>2012-09-10 14:09:45 +0200
commitb625ff4c7b68505b6d299d688734c9c1d448cb80 (patch)
treeaef733892e8fa7c811db277e137c286f5b3592f7 /src
parent7f8ca0fc4c29deee5eed5697ed4999b9a86f44c1 (diff)
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 <qt_docbot@qt-project.org> Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm14
1 files changed, 13 insertions, 1 deletions
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 <QtCore/QSettings>
+#include <QtGui/QGuiApplication>
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;