From e19345987714f4f76c8d7075355980b154adbc44 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 18 Nov 2019 12:15:48 +0100 Subject: Fix kerning with fractional pixel size Since most of our APIs for pixel size are integer-based, we would assume it was when passing it to Harfbuzz. But QRawFont (and the internal APIs in Qt and Harfbuzz) support floating point pixel sizes. The result would be that setting e.g. pixel size 20.25 would give the same glyph positions as 20.75, but the glyphs would be some fraction of a pixel larger. Using floats instead should have no impact on the common case where the pixel size is an integer, but it should also enable the other case, where QRawFont is used (or potentially future APIs that do not have the integer limitation.) [ChangeLog][QtGui][Text] Fixed a problem where pixel sizes would be truncated before calculating glyph positions. Fixes: QTBUG-67091 Change-Id: Ib066b1330ddcf52d4b344412e350aa9a60c847ff Reviewed-by: Konstantin Ritt --- src/gui/text/qharfbuzzng.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/text/qharfbuzzng.cpp b/src/gui/text/qharfbuzzng.cpp index 9c8582b43d..397e6cc49f 100644 --- a/src/gui/text/qharfbuzzng.cpp +++ b/src/gui/text/qharfbuzzng.cpp @@ -695,12 +695,12 @@ _hb_qt_font_create(QFontEngine *fe) return NULL; } - const int y_ppem = fe->fontDef.pixelSize; - const int x_ppem = (fe->fontDef.pixelSize * fe->fontDef.stretch) / 100; + const qreal y_ppem = fe->fontDef.pixelSize; + const qreal x_ppem = (fe->fontDef.pixelSize * fe->fontDef.stretch) / 100.0; hb_font_set_funcs(font, hb_qt_get_font_funcs(), (void *)fe, NULL); - hb_font_set_scale(font, QFixed(x_ppem).value(), -QFixed(y_ppem).value()); - hb_font_set_ppem(font, x_ppem, y_ppem); + hb_font_set_scale(font, QFixed::fromReal(x_ppem).value(), -QFixed::fromReal(y_ppem).value()); + hb_font_set_ppem(font, int(x_ppem), int(y_ppem)); hb_font_set_ptem(font, fe->fontDef.pointSize); -- cgit v1.2.3