Fix QFontMetrics width

Commit f4dd534 introduced a regression, so that QFontMetrics reported
a wrong size (to be more specific width) for FreeType fonts.
The calculation of glyph advances has to to reflect (rounded)
integral number of pixels. This was only done when the glyph was cached.
So in some cases the first call to QFontMetrics::size gave a different
result than the second.
This patch reverts f4dd5344fb.

The tst_QFontMetrics::same auto test only happened to work on some
platforms, on BlackBerry for instance it did not. Extended the test
case to make sure it works for different font sizes.

Change-Id: Ia5bb9abd3ff98193c9bba048b85207672ed8d9c3
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
Bernd Weimer 2014-02-19 18:00:24 +01:00 committed by The Qt Project
parent 2d22e73775
commit d641792ff2
2 changed files with 7 additions and 1 deletions

View File

@ -1617,7 +1617,7 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlag
face = lockFace();
g = loadGlyph(cacheEnabled ? &defaultGlyphSet : 0, glyphs->glyphs[i], 0, Format_None, true);
glyphs->advances[i] = design ? QFixed::fromFixed(face->glyph->linearHoriAdvance >> 10)
: QFixed::fromFixed(face->glyph->metrics.horiAdvance);
: QFixed::fromFixed(face->glyph->metrics.horiAdvance).round();
if (!cacheEnabled)
delete g;
}

View File

@ -100,6 +100,12 @@ void tst_QFontMetrics::same()
const QString text = QLatin1String("Some stupid STRING");
QCOMPARE(fm.size(0, text), fm.size(0, text)) ;
for (int i = 10; i <= 32; ++i) {
font.setPixelSize(i);
QFontMetrics fm1(font);
QCOMPARE(fm1.size(0, text), fm1.size(0, text));
}
{
QImage image;
QFontMetrics fm2(font, &image);