From a44e7aa9156049a682c7496ea54ae665be91630b Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Tue, 20 Dec 2016 00:15:59 +0100 Subject: [PATCH] Factor code for math axis height --- src/mathed/InsetMathFrac.cpp | 16 ++++------------ src/mathed/MathSupport.cpp | 7 +++++++ src/mathed/MathSupport.h | 3 +++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp index ad999a221d..ada6476c50 100644 --- a/src/mathed/InsetMathFrac.cpp +++ b/src/mathed/InsetMathFrac.cpp @@ -154,14 +154,6 @@ MathClass InsetMathFrac::mathClass() const namespace { -// align frac to minus character -int dy_for_frac(MetricsBase & mb) -{ - Changer dummy = mb.changeFontSet("mathnormal"); - return theFontMetrics(mb.font).ascent('-') - 1; -} - - // align the top of M in the cell with the top of M in the surrounding font int dy_for_nicefrac(MetricsBase & mb) { @@ -249,7 +241,7 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const case TFRAC: case OVER: case ATOP: { - int const dy = dy_for_frac(mi.base); + int const dy = axis_height(mi.base); Changer dummy = // \tfrac is always in text size (kind_ == TFRAC) ? mi.base.font.changeStyle(LM_ST_SCRIPT) : @@ -332,7 +324,7 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const case TFRAC: case OVER: case ATOP: { - int const dy = dy_for_frac(pi.base); + int const dy = axis_height(pi.base); Changer dummy = // \tfrac is always in text size (kind_ == TFRAC) ? pi.base.font.changeStyle(LM_ST_SCRIPT) : @@ -658,7 +650,7 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const { Changer dummy2 = mi.base.changeEnsureMath(); Dimension dim0, dim1; - int const dy = dy_for_frac(mi.base); + int const dy = axis_height(mi.base); Changer dummy = (kind_ == DBINOM) ? mi.base.font.changeStyle(LM_ST_DISPLAY) : (kind_ == TBINOM) ? mi.base.font.changeStyle(LM_ST_SCRIPT) : @@ -678,7 +670,7 @@ void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const Dimension const dim = dimension(*pi.base.bv); Dimension const & dim0 = cell(0).dimension(*pi.base.bv); Dimension const & dim1 = cell(1).dimension(*pi.base.bv); - int const dy = dy_for_frac(pi.base); + int const dy = axis_height(pi.base); // define the binom brackets docstring const bra = kind_ == BRACE ? from_ascii("{") : kind_ == BRACK ? from_ascii("[") : from_ascii("("); diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp index 222807bba4..5df8a0673e 100644 --- a/src/mathed/MathSupport.cpp +++ b/src/mathed/MathSupport.cpp @@ -985,4 +985,11 @@ docstring asString(MathAtom const & at) } +int axis_height(MetricsBase & mb) +{ + Changer dummy = mb.changeFontSet("mathnormal"); + return theFontMetrics(mb.font).ascent('-') - 1; +} + + } // namespace lyx diff --git a/src/mathed/MathSupport.h b/src/mathed/MathSupport.h index 87f824dc16..2b3e48f68f 100644 --- a/src/mathed/MathSupport.h +++ b/src/mathed/MathSupport.h @@ -81,6 +81,9 @@ docstring asString(MathAtom const &); // converts string to single cell void asArray(docstring const &, MathData &, Parse::flags f = Parse::NORMAL); +// simulate axis height (font dimension sigma 22) +int axis_height(MetricsBase & mb); + } // namespace lyx #endif -- 2.39.5