Remove historical +1 from font height calculation
Historically, we've calculated font height as ascent+descent+1. In Qt 4, a patch was added to work around this by subtracting 1 from the descent of the font engines. We now remove the +1 and the work arounds. Change-Id: I7e25d49b97ac892015d3328f32d70eb9a7c2d88f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
2801db558c
commit
cb8445f032
@ -469,7 +469,7 @@ void QAbstractTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int
|
|||||||
|
|
||||||
QSizeF s = handler.iface->intrinsicSize(document(), posInDocument, format);
|
QSizeF s = handler.iface->intrinsicSize(document(), posInDocument, format);
|
||||||
item.setWidth(s.width());
|
item.setWidth(s.width());
|
||||||
item.setAscent(s.height() - 1);
|
item.setAscent(s.height());
|
||||||
item.setDescent(0);
|
item.setDescent(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1173,8 +1173,7 @@ QFixed QFontEngineFT::ascent() const
|
|||||||
|
|
||||||
QFixed QFontEngineFT::descent() const
|
QFixed QFontEngineFT::descent() const
|
||||||
{
|
{
|
||||||
// subtract a pixel to work around QFontMetrics's built-in + 1
|
return QFixed::fromFixed(-metrics.descender);
|
||||||
return QFixed::fromFixed(-metrics.descender - 64);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QFixed QFontEngineFT::leading() const
|
QFixed QFontEngineFT::leading() const
|
||||||
@ -1589,7 +1588,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(const QGlyphLayout &glyphs)
|
|||||||
glyph_metrics_t overall;
|
glyph_metrics_t overall;
|
||||||
// initialize with line height, we get the same behaviour on all platforms
|
// initialize with line height, we get the same behaviour on all platforms
|
||||||
overall.y = -ascent();
|
overall.y = -ascent();
|
||||||
overall.height = ascent() + descent() + 1;
|
overall.height = ascent() + descent();
|
||||||
|
|
||||||
QFixed ymax = 0;
|
QFixed ymax = 0;
|
||||||
QFixed xmax = 0;
|
QFixed xmax = 0;
|
||||||
|
@ -484,8 +484,8 @@ QFixed QFontEngineDirectWrite::ascent() const
|
|||||||
QFixed QFontEngineDirectWrite::descent() const
|
QFixed QFontEngineDirectWrite::descent() const
|
||||||
{
|
{
|
||||||
return fontDef.styleStrategy & QFont::ForceIntegerMetrics
|
return fontDef.styleStrategy & QFont::ForceIntegerMetrics
|
||||||
? (m_descent - 1).round()
|
? (m_descent).round()
|
||||||
: (m_descent - 1);
|
: (m_descent);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFixed QFontEngineDirectWrite::leading() const
|
QFixed QFontEngineDirectWrite::leading() const
|
||||||
|
@ -288,7 +288,7 @@ int QFontMetrics::height() const
|
|||||||
{
|
{
|
||||||
QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
||||||
Q_ASSERT(engine != 0);
|
Q_ASSERT(engine != 0);
|
||||||
return qRound(engine->ascent()) + qRound(engine->descent()) + 1;
|
return qRound(engine->ascent()) + qRound(engine->descent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -316,7 +316,7 @@ int QFontMetrics::lineSpacing() const
|
|||||||
{
|
{
|
||||||
QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
||||||
Q_ASSERT(engine != 0);
|
Q_ASSERT(engine != 0);
|
||||||
return qRound(engine->leading()) + qRound(engine->ascent()) + qRound(engine->descent()) + 1;
|
return qRound(engine->leading()) + qRound(engine->ascent()) + qRound(engine->descent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1147,7 +1147,7 @@ qreal QFontMetricsF::height() const
|
|||||||
QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
||||||
Q_ASSERT(engine != 0);
|
Q_ASSERT(engine != 0);
|
||||||
|
|
||||||
return (engine->ascent() + engine->descent() + 1).toReal();
|
return (engine->ascent() + engine->descent()).toReal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1175,7 +1175,7 @@ qreal QFontMetricsF::lineSpacing() const
|
|||||||
{
|
{
|
||||||
QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
|
||||||
Q_ASSERT(engine != 0);
|
Q_ASSERT(engine != 0);
|
||||||
return (engine->leading() + engine->ascent() + engine->descent() + 1).toReal();
|
return (engine->leading() + engine->ascent() + engine->descent()).toReal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -366,7 +366,7 @@ struct Q_AUTOTEST_EXPORT QScriptItem
|
|||||||
QFixed leading;
|
QFixed leading;
|
||||||
QFixed width;
|
QFixed width;
|
||||||
int glyph_data_offset;
|
int glyph_data_offset;
|
||||||
QFixed height() const { return ascent + descent + 1; }
|
QFixed height() const { return ascent + descent; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -396,7 +396,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine
|
|||||||
mutable uint gridfitted : 1;
|
mutable uint gridfitted : 1;
|
||||||
uint hasTrailingSpaces : 1;
|
uint hasTrailingSpaces : 1;
|
||||||
uint leadingIncluded : 1;
|
uint leadingIncluded : 1;
|
||||||
QFixed height() const { return (ascent + descent).ceil() + 1
|
QFixed height() const { return (ascent + descent).ceil()
|
||||||
+ (leadingIncluded? qMax(QFixed(),leading) : QFixed()); }
|
+ (leadingIncluded? qMax(QFixed(),leading) : QFixed()); }
|
||||||
QFixed base() const { return ascent
|
QFixed base() const { return ascent
|
||||||
+ (leadingIncluded ? qMax(QFixed(),leading) : QFixed()); }
|
+ (leadingIncluded ? qMax(QFixed(),leading) : QFixed()); }
|
||||||
|
@ -1429,9 +1429,9 @@ qreal QTextLine::descent() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the line's height. This is equal to ascent() + descent() + 1
|
Returns the line's height. This is equal to ascent() + descent()
|
||||||
if leading is not included. If leading is included, this equals to
|
if leading is not included. If leading is included, this equals to
|
||||||
ascent() + descent() + leading() + 1.
|
ascent() + descent() + leading().
|
||||||
|
|
||||||
\sa ascent(), descent(), leading(), setLeadingIncluded()
|
\sa ascent(), descent(), leading(), setLeadingIncluded()
|
||||||
*/
|
*/
|
||||||
|
@ -255,9 +255,7 @@ QFixed QCoreTextFontEngine::descent() const
|
|||||||
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
|
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
|
||||||
d = d.round();
|
d = d.round();
|
||||||
|
|
||||||
// subtract a pixel to even out the historical +1 in QFontMetrics::height().
|
return d;
|
||||||
// Fix in Qt 5.
|
|
||||||
return d - 1;
|
|
||||||
}
|
}
|
||||||
QFixed QCoreTextFontEngine::leading() const
|
QFixed QCoreTextFontEngine::leading() const
|
||||||
{
|
{
|
||||||
|
@ -517,9 +517,7 @@ QFixed QWindowsFontEngine::ascent() const
|
|||||||
|
|
||||||
QFixed QWindowsFontEngine::descent() const
|
QFixed QWindowsFontEngine::descent() const
|
||||||
{
|
{
|
||||||
// ### we subtract 1 to even out the historical +1 in QFontMetrics'
|
return tm.tmDescent;
|
||||||
// ### height=asc+desc+1 equation. Fix in Qt5.
|
|
||||||
return tm.tmDescent - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QFixed QWindowsFontEngine::leading() const
|
QFixed QWindowsFontEngine::leading() const
|
||||||
|
@ -140,7 +140,7 @@ void tst_QFontMetrics::metrics()
|
|||||||
font = fdb.font(family, style, 12);
|
font = fdb.font(family, style, 12);
|
||||||
|
|
||||||
QFontMetrics fontmetrics(font);
|
QFontMetrics fontmetrics(font);
|
||||||
QCOMPARE(fontmetrics.ascent() + fontmetrics.descent() + 1,
|
QCOMPARE(fontmetrics.ascent() + fontmetrics.descent(),
|
||||||
fontmetrics.height());
|
fontmetrics.height());
|
||||||
|
|
||||||
QCOMPARE(fontmetrics.height() + fontmetrics.leading(),
|
QCOMPARE(fontmetrics.height() + fontmetrics.leading(),
|
||||||
@ -156,7 +156,7 @@ void tst_QFontMetrics::metrics()
|
|||||||
font = fdb.font(family, style, size);
|
font = fdb.font(family, style, size);
|
||||||
|
|
||||||
QFontMetrics fontmetrics(font);
|
QFontMetrics fontmetrics(font);
|
||||||
QCOMPARE(fontmetrics.ascent() + fontmetrics.descent() + 1,
|
QCOMPARE(fontmetrics.ascent() + fontmetrics.descent(),
|
||||||
fontmetrics.height());
|
fontmetrics.height());
|
||||||
QCOMPARE(fontmetrics.height() + fontmetrics.leading(),
|
QCOMPARE(fontmetrics.height() + fontmetrics.leading(),
|
||||||
fontmetrics.lineSpacing());
|
fontmetrics.lineSpacing());
|
||||||
|
@ -352,7 +352,7 @@ void tst_QTextLayout::threeLineBoundingRect()
|
|||||||
QCOMPARE(qRound(line.naturalTextWidth()), thirdLineWidth);
|
QCOMPARE(qRound(line.naturalTextWidth()), thirdLineWidth);
|
||||||
y += qRound(line.ascent() + line.descent());
|
y += qRound(line.ascent() + line.descent());
|
||||||
|
|
||||||
QCOMPARE(layout.boundingRect(), QRectF(0, 0, longestLine, y + 1));
|
QCOMPARE(layout.boundingRect(), QRectF(0, 0, longestLine, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QTextLayout::boundingRectWithLongLineAndNoWrap()
|
void tst_QTextLayout::boundingRectWithLongLineAndNoWrap()
|
||||||
@ -386,7 +386,7 @@ void tst_QTextLayout::forcedBreaks()
|
|||||||
QCOMPARE(line.textStart(), pos);
|
QCOMPARE(line.textStart(), pos);
|
||||||
QCOMPARE(line.textLength(),2);
|
QCOMPARE(line.textLength(),2);
|
||||||
QCOMPARE(qRound(line.naturalTextWidth()),testFont.pixelSize());
|
QCOMPARE(qRound(line.naturalTextWidth()),testFont.pixelSize());
|
||||||
QCOMPARE((int) line.height(), testFont.pixelSize() + 1); // + 1 baseline
|
QCOMPARE((int) line.height(), testFont.pixelSize());
|
||||||
QCOMPARE(line.xToCursor(0), line.textStart());
|
QCOMPARE(line.xToCursor(0), line.textStart());
|
||||||
pos += line.textLength();
|
pos += line.textLength();
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ void tst_QTextLayout::forcedBreaks()
|
|||||||
QCOMPARE(line.textStart(),pos);
|
QCOMPARE(line.textStart(),pos);
|
||||||
QCOMPARE(line.textLength(),1);
|
QCOMPARE(line.textLength(),1);
|
||||||
QCOMPARE(qRound(line.naturalTextWidth()), 0);
|
QCOMPARE(qRound(line.naturalTextWidth()), 0);
|
||||||
QCOMPARE((int) line.height(), testFont.pixelSize() + 1); // + 1 baseline
|
QCOMPARE((int) line.height(), testFont.pixelSize());
|
||||||
QCOMPARE(line.xToCursor(0), line.textStart());
|
QCOMPARE(line.xToCursor(0), line.textStart());
|
||||||
pos += line.textLength();
|
pos += line.textLength();
|
||||||
|
|
||||||
@ -404,7 +404,7 @@ void tst_QTextLayout::forcedBreaks()
|
|||||||
QCOMPARE(line.textStart(),pos);
|
QCOMPARE(line.textStart(),pos);
|
||||||
QCOMPARE(line.textLength(),2);
|
QCOMPARE(line.textLength(),2);
|
||||||
QCOMPARE(qRound(line.naturalTextWidth()),testFont.pixelSize());
|
QCOMPARE(qRound(line.naturalTextWidth()),testFont.pixelSize());
|
||||||
QCOMPARE(qRound(line.height()), testFont.pixelSize() + 1); // + 1 baseline
|
QCOMPARE(qRound(line.height()), testFont.pixelSize());
|
||||||
QCOMPARE(line.xToCursor(0), line.textStart());
|
QCOMPARE(line.xToCursor(0), line.textStart());
|
||||||
pos += line.textLength();
|
pos += line.textLength();
|
||||||
|
|
||||||
@ -413,7 +413,7 @@ void tst_QTextLayout::forcedBreaks()
|
|||||||
QCOMPARE(line.textStart(),pos);
|
QCOMPARE(line.textStart(),pos);
|
||||||
QCOMPARE(line.textLength(),1);
|
QCOMPARE(line.textLength(),1);
|
||||||
QCOMPARE(qRound(line.naturalTextWidth()), testFont.pixelSize());
|
QCOMPARE(qRound(line.naturalTextWidth()), testFont.pixelSize());
|
||||||
QCOMPARE((int) line.height(), testFont.pixelSize() + 1); // + 1 baseline
|
QCOMPARE((int) line.height(), testFont.pixelSize());
|
||||||
QCOMPARE(line.xToCursor(0), line.textStart());
|
QCOMPARE(line.xToCursor(0), line.textStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user