Introduce FontMetrics::xHeight

Use it instead of measuring the height of character 'x'.
This commit is contained in:
Jean-Marc Lasgouttes 2018-07-19 22:16:40 +02:00
parent 30c6d4fafe
commit 9b3fede789
8 changed files with 18 additions and 7 deletions

View File

@ -65,6 +65,8 @@ public:
virtual Dimension const defaultDimension() const = 0;
/// return the em size
virtual int em() const = 0;
/// return the x height
virtual int xHeight() const = 0;
/// return the width of a line for underlining
virtual int lineWidth() const = 0;
/// return the distance from the base line to where an underline

View File

@ -117,6 +117,13 @@ int GuiFontMetrics::em() const
}
int GuiFontMetrics::xHeight() const
{
// LATTEST(metrics_.xHeight() == ascent('x'));
return metrics_.xHeight();
}
int GuiFontMetrics::lineWidth() const
{
return metrics_.lineWidth();

View File

@ -38,6 +38,7 @@ public:
virtual int maxDescent() const;
virtual Dimension const defaultDimension() const;
virtual int em() const;
virtual int xHeight() const;
virtual int lineWidth() const;
virtual int underlinePos() const;
virtual int strikeoutPos() const;

View File

@ -352,7 +352,7 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
}
int const w = dim.wid;
int const h = theFontMetrics(pi.base.font).ascent('x');
int const h = theFontMetrics(pi.base.font).xHeight();
int xp[4], yp[4];
xp[0] = x;

View File

@ -202,7 +202,7 @@ void drawLogo(PainterInfo & pi, int & x, int const y, InsetSpecialChar::Kind kin
/** Reference macro:
* \def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
*/
int const ex = theFontMetrics(font).ascent('x');
int const ex = theFontMetrics(font).xHeight();
drawChar(pi, x, y, 'T');
x -= em / 6;
drawChar(pi, x, y + ex / 2, 'E');
@ -265,7 +265,7 @@ void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
case ALLOWBREAK:
{
// A small vertical line
int const asc = theFontMetrics(pi.base.font).ascent('x');
int const asc = theFontMetrics(pi.base.font).xHeight();
int const desc = theFontMetrics(pi.base.font).descent('g');
int const x0 = x; // x + 1; // FIXME: incline,
int const x1 = x; // x - 1; // similar to LibreOffice?

View File

@ -271,7 +271,7 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim, bool tight) const
frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
BufferView * bv = mi.base.bv;
int const Iascent = fm.dimension('I').ascent();
int xascent = fm.dimension('x').ascent();
int xascent = fm.xHeight();
if (xascent >= Iascent)
xascent = (2 * Iascent) / 3;
minasc_ = xascent;
@ -288,7 +288,7 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim, bool tight) const
if (tight)
// FIXME: this is the minimal ascent seen empirically, check
// what the TeXbook says.
dim.asc = max(dim.asc, fm.ascent('x'));
dim.asc = max(dim.asc, fm.xHeight());
else {
dim.asc = max(dim.asc, fm.maxAscent());
dim.des = max(dim.des, fm.maxDescent());

View File

@ -129,7 +129,8 @@ public:
/// rebuild cached metrics information
/** When \c tight is true, the height of the cell will be at least
* that of 'x'. Otherwise, it will be the max height of the font.
* the x height of the font. Otherwise, it will be the max height
* of the font.
*/
void metrics(MetricsInfo & mi, Dimension & dim, bool tight = true) const;
///

View File

@ -520,7 +520,7 @@ int mathed_font_em(FontInfo const & font)
int mathed_font_x_height(FontInfo const & font)
{
return theFontMetrics(font).ascent('x');
return theFontMetrics(font).xHeight();
}
/* The math units. Quoting TeX by Topic, p.205: