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>
This commit is contained in:
parent
7f8ca0fc4c
commit
b625ff4c7b
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user