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/qtextlayout.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/gui/text/qtextlayout.cpp') diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 0c729c74d1..d68a59fae3 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1966,9 +1966,16 @@ void QTextLine::layout_helper(int maxGlyphs) // end up breaking due to the current glyph being too wide. QFixed previousRightBearing = lbh.rightBearing; - // We ignore the right bearing if the minimum negative bearing is too little to - // expand the text beyond the edge. - if (lbh.calculateNewWidth(line) - lbh.minimumRightBearing > line.width) + // We skip calculating the right bearing if the minimum negative bearing is too + // small to possibly expand the text beyond the edge. Note that this optimization + // will in some cases fail, as the minimum right bearing reported by the font + // engine may not cover all the glyphs in the font. The result is that we think + // we don't need to break at the current glyph (because the right bearing is 0), + // and when we then end up breaking on the next glyph we compute the right bearing + // and end up with a line width that is slightly larger width than what was requested. + // Unfortunately we can't remove this optimization as it will slow down text + // layouting significantly, so we accept the slight correctnes issue. + if ((lbh.calculateNewWidth(line) + qAbs(lbh.minimumRightBearing)) > line.width) lbh.calculateRightBearing(); if (lbh.checkFullOtherwiseExtend(line)) { -- cgit v1.2.3