]> git.lyx.org Git - lyx.git/commitdiff
Introduce FontMetrics::xHeight
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 19 Jul 2018 20:16:40 +0000 (22:16 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 19 Jul 2018 20:16:40 +0000 (22:16 +0200)
Use it instead of measuring the height of character 'x'.

src/frontends/FontMetrics.h
src/frontends/qt4/GuiFontMetrics.cpp
src/frontends/qt4/GuiFontMetrics.h
src/insets/InsetSpace.cpp
src/insets/InsetSpecialChar.cpp
src/mathed/MathData.cpp
src/mathed/MathData.h
src/mathed/MathSupport.cpp

index c02606c4384f3536c0759b13503bbc4413e30022..4472aa70083855c96018e9dd8d34fc7b97c01184 100644 (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
index c2d4b884e4eddc8018c8824c593f77969fdbb980..1c2421d11b9c3e80f7d4f4f83cd4c552cc0bc2ec 100644 (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();
index 3f50dfe5d29902d0516e2b27c3ca2ec32fa4d4e4..8a2ebe2525fb0c98bc55e8bd726abc3cd7f8fe67 100644 (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;
index 5e9789c68c058c1b5aaa77da05c880acfc178746..fd8c261d2e649c621c2bc3a043bbf55a7bd6d426 100644 (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;
index e9153cd900c43e81c51ae9155c02ac3048335d87..4a46f398eb8ba5f17dd954559365b15254cad298 100644 (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?
index 07decba9e5d26f4f66079e127a61e208ba017b18..87b1820cba7d81b38a5c76b8e39c7e324d73fd69 100644 (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());
index 7099e64643affd4a7df3300350dc61105bd08005..cd4d44b4a8f4dcc311e0edeb6b86de74f9892826 100644 (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;
        ///
index ea8309545fac6041d52d6a709888feb4a81f1c3d..2cf4bd5f26ebc1f69244cc6e7cf5c96575fce8f2 100644 (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: