summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2009-09-09 15:38:57 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2009-09-09 15:44:35 (GMT)
commit07880542ecc479807c23c5646d263135240822ff (patch)
tree3e82442f58390ebc8ac71ab738749ca269037b43 /src/gui/text
parent80ca4cd1d9d9a1b725fb7a6016f1035c3d3ffc92 (diff)
downloadQt-07880542ecc479807c23c5646d263135240822ff.zip
Qt-07880542ecc479807c23c5646d263135240822ff.tar.gz
Qt-07880542ecc479807c23c5646d263135240822ff.tar.bz2
Account for right bearing in QFontMetrics::boundingRect(string)
QFontMetrics::boundingRect() that takes a string needs to account for the right bearing of the last glyph, as it is documented to be the rectangle that contains the pixels of the text. I've added a test for this, and fixed tst_QFontMetrics::elidedText() to use boundingRect() to find the actual width of the text drawn (width() will return the advance of the text, which is larger than the actual width of the pixels.) I've also fixed a small typo in the "len" -> "ilen". Reviewed-by: Simon Hausmann
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextengine.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index c9b6c38..88837ca 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1594,11 +1594,13 @@ glyph_metrics_t QTextEngine::boundingBox(int from, int len) const
for (int i = 0; i < layoutData->items.size(); i++) {
const QScriptItem *si = layoutData->items.constData() + i;
+ QFontEngine *fe = fontEngine(*si);
+
int pos = si->position;
int ilen = length(i);
if (pos > from + len)
break;
- if (pos + len > from) {
+ if (pos + ilen > from) {
if (!si->num_glyphs)
shape(i);
@@ -1631,7 +1633,6 @@ glyph_metrics_t QTextEngine::boundingBox(int from, int len) const
charEnd++;
glyphEnd = (charEnd == ilen) ? si->num_glyphs : logClusters[charEnd];
if (glyphStart <= glyphEnd ) {
- QFontEngine *fe = fontEngine(*si);
glyph_metrics_t m = fe->boundingBox(glyphs.mid(glyphStart, glyphEnd - glyphStart));
gm.x = qMin(gm.x, m.x + gm.xoff);
gm.y = qMin(gm.y, m.y + gm.yoff);
@@ -1641,6 +1642,10 @@ glyph_metrics_t QTextEngine::boundingBox(int from, int len) const
gm.yoff += m.yoff;
}
}
+
+ glyph_t glyph = glyphs.glyphs[logClusters[pos + ilen - 1]];
+ glyph_metrics_t gi = fe->boundingBox(glyph);
+ gm.width -= qRound(gi.xoff - gi.x - gi.width);
}
}
return gm;