summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextlayout.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-08-17 17:59:06 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-09-02 09:11:31 +0000
commit54dbdc26bacd3ab776c99ebef734404ef2e08ce5 (patch)
tree6c3d5614ea3beefd023ab0a259ecf207655ba2ce /src/gui/text/qtextlayout.cpp
parentba94e26b8b233456b004084892464ec55b20800c (diff)
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 <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/gui/text/qtextlayout.cpp')
-rw-r--r--src/gui/text/qtextlayout.cpp13
1 files changed, 10 insertions, 3 deletions
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)) {