From 54dbdc26bacd3ab776c99ebef734404ef2e08ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 17 Aug 2015 17:59:06 +0200 Subject: Move min left/right bearing calculations to QFontEngine baseclass The logic used in the FreeType font engine can be generalized and move to the QFontEngine baseclass. This allows the CoreText font engine to correctly report the minimum left/right bearings, which decreases the chance that an optimization in QTextLayout's line breaking algorithm will produce wrong results. The calculation of left and right bearing has been moved to the glyph_metrics_t type to reduce code duplication. This allows us to use the with and height of the bounding box to determine if the glyph has any contours. Change-Id: I864697d3f31ed56f22f04666199b6c5023c5e585 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfontengine_ft.cpp | 49 ----------------------------------------- 1 file changed, 49 deletions(-) (limited to 'src/gui/text/qfontengine_ft.cpp') diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 246df127ad..0d28785aa1 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -688,7 +688,6 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format, symbol = bool(fontDef.family.contains(QLatin1String("symbol"), Qt::CaseInsensitive)); } - lbearing = rbearing = SHRT_MIN; freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing); FT_Face face = lockFace(); @@ -1258,54 +1257,6 @@ qreal QFontEngineFT::maxCharWidth() const return metrics.max_advance >> 6; } -static const ushort char_table[] = { - 40, - 67, - 70, - 75, - 86, - 88, - 89, - 91, - 95, - 102, - 114, - 124, - 127, - 205, - 645, - 884, - 922, - 1070, - 12386 -}; - -static const int char_table_entries = sizeof(char_table)/sizeof(ushort); - - -qreal QFontEngineFT::minLeftBearing() const -{ - if (lbearing == SHRT_MIN) - (void) minRightBearing(); // calculates both - return lbearing.toReal(); -} - -qreal QFontEngineFT::minRightBearing() const -{ - if (rbearing == SHRT_MIN) { - lbearing = rbearing = 0; - for (int i = 0; i < char_table_entries; ++i) { - const glyph_t glyph = glyphIndex(char_table[i]); - if (glyph != 0) { - glyph_metrics_t gi = const_cast(this)->boundingBox(glyph); - lbearing = qMin(lbearing, gi.x); - rbearing = qMin(rbearing, (gi.xoff - gi.x - gi.width)); - } - } - } - return rbearing.toReal(); -} - QFixed QFontEngineFT::lineThickness() const { return line_thickness; -- cgit v1.2.3