commit 7bcb78a77875ecae0f54063ff02ec90e1b78f8b6
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Thu Apr 19 13:15:43 2018 +0200

    Better mechanism for setting cell cell height
    
    When computing a cell metrics, it is now possible to specify whether it
    is tight (at least as tall as 'x') or not (as tall as the max height of
    the font).
    
    Use this to make sure that grid insets have large enough cells. It
    will probably appear that other cells needn't be tight. Currently, the
    only cell which is known to be tight is the nucleus of the root inset.
    Others should be examined one by one. It might be that the default of
    MathData::metrics tight parameter should be `false'.
    
    Fixes bug #11050.
---
 src/mathed/InsetMathGrid.cpp |    3 ++-
 src/mathed/InsetMathHull.cpp |    7 -------
 src/mathed/InsetMathRoot.cpp |    9 +--------
 src/mathed/MathData.cpp      |   18 ++++++++++++++----
 src/mathed/MathData.h        |    5 ++++-
 src/mathed/MathRow.cpp       |    7 +------
 6 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 6c237f6..cb6f440 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -397,7 +397,8 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & 
dim) const
        for (idx_type i = 0; i < nargs(); ++i) {
                if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
                        Dimension dimc;
-                       cell(i).metrics(mi, dimc);
+                       // the 'false' is to make sure that the cell is tall 
enough
+                       cell(i).metrics(mi, dimc, false);
                }
        }
 
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 08d9287..8398347 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -569,13 +569,6 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & 
dim) const
 
        // reserve some space for marker.
        dim.wid += 2;
-
-       // make it at least as high as the current font
-       int asc = 0;
-       int des = 0;
-       math_font_max_dim(mi.base.font, asc, des);
-       dim.asc = max(dim.asc, asc);
-       dim.des = max(dim.des, des);
 }
 
 
diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp
index 348b4e9..3cc8e2e 100644
--- a/src/mathed/InsetMathRoot.cpp
+++ b/src/mathed/InsetMathRoot.cpp
@@ -47,19 +47,12 @@ void mathed_root_metrics(MetricsInfo & mi, MathData const & 
nucleus,
        Dimension dimr;
        if (root) {
                Changer script = mi.base.font.changeStyle(LM_ST_SCRIPTSCRIPT);
-               root->metrics(mi, dimr);
                // make sure that the dim is high enough for any character
-               Dimension fontDim;
-               math_font_max_dim(mi.base.font, fontDim.asc, fontDim.des);
-               dimr += fontDim;
+               root->metrics(mi, dimr, false);
        }
 
        Dimension dimn;
        nucleus.metrics(mi, dimn);
-       // make sure that the dim is high enough for any character
-       // Dimension fontDim;
-       // math_font_max_dim(mi.base.font, fontDim.asc, fontDim.des);
-       // dimn += fontDim;
 
        // Some room for the decoration
        // The width of left decoration was 9 pixels with a 10em font
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index d242a86..719065d 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -259,13 +259,13 @@ bool isInside(DocIterator const & it, MathData const & ar,
 #endif
 
 
-void MathData::metrics(MetricsInfo & mi, Dimension & dim) const
+void MathData::metrics(MetricsInfo & mi, Dimension & dim, bool tight) const
 {
        frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
-       dim = fm.dimension('I');
+       int const Iascent = fm.dimension('I').ascent();
        int xascent = fm.dimension('x').ascent();
-       if (xascent >= dim.asc)
-               xascent = (2 * dim.asc) / 3;
+       if (xascent >= Iascent)
+               xascent = (2 * Iascent) / 3;
        minasc_ = xascent;
        mindes_ = (3 * xascent) / 4;
        slevel_ = (4 * xascent) / 5;
@@ -276,6 +276,16 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim) 
const
        mrow_cache_[mi.base.bv] = mrow;
        kerning_ = mrow.kerning(mi.base.bv);
 
+       // Set a minimal ascent/descent for the cell
+       if (tight)
+               // FIXME: this is the minimal ascent seen empirically, check
+               // what the TeXbook says.
+               dim.asc = max(dim.asc, fm.ascent('x'));
+       else {
+               dim.asc = max(dim.asc, fm.maxAscent());
+               dim.des = max(dim.des, fm.maxDescent());
+       }
+
        // Cache the dimension.
        mi.base.bv->coordCache().arrays().add(this, dim);
 }
diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h
index 70c0019..efa581c 100644
--- a/src/mathed/MathData.h
+++ b/src/mathed/MathData.h
@@ -125,7 +125,10 @@ public:
        bool addToMathRow(MathRow &, MetricsInfo & mi) const;
 
        /// rebuild cached metrics information
-       void metrics(MetricsInfo & mi, Dimension & dim) const;
+       /** 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.
+        */
+       void metrics(MetricsInfo & mi, Dimension & dim, bool tight = true) 
const;
        ///
        Dimension const & dimension(BufferView const &) const;
 
diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp
index 5610815..cc3e5a3 100644
--- a/src/mathed/MathRow.cpp
+++ b/src/mathed/MathRow.cpp
@@ -236,11 +236,6 @@ int MathRow::after(int i) const
 
 void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
 {
-       frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
-       // FIXME: this is the minimal ascent seen empirically, check
-       // what the TeXbook says.
-       dim.asc = fm.ascent('x');
-       dim.wid = 0;
        // In order to compute the dimension of macros and their
        // arguments, it is necessary to keep track of them.
        vector<pair<InsetMath const *, Dimension>> dim_insets;
@@ -287,7 +282,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
                        }
                        break;
                case BOX:
-                       d = fm.dimension('I');
+                       d = theFontMetrics(mi.base.font).dimension('I');
                        if (e.color != Color_none) {
                                // allow for one pixel before/after the box.
                                d.wid += e.before + e.after + 2;

Reply via email to