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 <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
This commit is contained in:
Tor Arne Vestbø 2015-06-25 14:26:06 +02:00
parent b253f404e8
commit 35793cea28

View File

@ -45,7 +45,6 @@
#include "qcoretextfontdatabase_p.h"
#include "qfontengine_coretext_p.h"
#include <QtCore/QSettings>
#include <QtGui/QGuiApplication>
#include <QtCore/QtEndian>
#ifndef QT_NO_FREETYPE
#include <QtGui/private/qfontengine_ft_p.h>
@ -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) {