From 9b3fede789d234244b0005184aaddae2129ecf70 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 19 Jul 2018 22:16:40 +0200 Subject: [PATCH] Introduce FontMetrics::xHeight Use it instead of measuring the height of character 'x'. --- src/frontends/FontMetrics.h | 2 ++ src/frontends/qt4/GuiFontMetrics.cpp | 7 +++++++ src/frontends/qt4/GuiFontMetrics.h | 1 + src/insets/InsetSpace.cpp | 2 +- src/insets/InsetSpecialChar.cpp | 4 ++-- src/mathed/MathData.cpp | 4 ++-- src/mathed/MathData.h | 3 ++- src/mathed/MathSupport.cpp | 2 +- 8 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/frontends/FontMetrics.h b/src/frontends/FontMetrics.h index c02606c438..4472aa7008 100644 --- a/src/frontends/FontMetrics.h +++ b/src/frontends/FontMetrics.h @@ -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 diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp index c2d4b884e4..1c2421d11b 100644 --- a/src/frontends/qt4/GuiFontMetrics.cpp +++ b/src/frontends/qt4/GuiFontMetrics.cpp @@ -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(); diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h index 3f50dfe5d2..8a2ebe2525 100644 --- a/src/frontends/qt4/GuiFontMetrics.h +++ b/src/frontends/qt4/GuiFontMetrics.h @@ -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; diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index 5e9789c68c..fd8c261d2e 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -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; diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index e9153cd900..4a46f398eb 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -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? diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index 07decba9e5..87b1820cba 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -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()); diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index 7099e64643..cd4d44b4a8 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -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; /// diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp index ea8309545f..2cf4bd5f26 100644 --- a/src/mathed/MathSupport.cpp +++ b/src/mathed/MathSupport.cpp @@ -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: