]> git.lyx.org Git - lyx.git/commitdiff
Better mechanism for setting cell height
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 19 Apr 2018 11:15:43 +0000 (13:15 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 10 May 2018 10:48:56 +0000 (12:48 +0200)
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.

(cherry picked from commit 7bcb78a77875ecae0f54063ff02ec90e1b78f8b6)

src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathRoot.cpp
src/mathed/MathData.cpp
src/mathed/MathData.h
src/mathed/MathRow.cpp

index 67300403907d947f43f1ca71e2b75323bf2192e6..9c3bd580cca3cd023e4a4e319620f1ded4e0dc92 100644 (file)
@@ -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);
                }
        }
 
index 4e29d4ce242e75466f8eb9067b6313cce92031c5..0a7ddd6d005858caa476ba2c5e7dea6899f102bf 100644 (file)
@@ -570,13 +570,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);
 }
 
 
index 348b4e9cab67743b8be4275fe125424935d7a04e..3cc8e2e1d7851b0186a03ae87f29e6ec8d58c025 100644 (file)
@@ -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
index beb1299b9afa565a3f63a1cb9f3d00683fd87218..a4a960a7d2ef89c0bdcc4b36c0b7dfa69b419c8d 100644 (file)
@@ -264,13 +264,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;
@@ -281,6 +281,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);
 }
index 31bb787c98f4d82c56e14193c2358aaa4c180f3e..93b0f1559ad7c931be2ca66ea5984af9cc7a6555 100644 (file)
@@ -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;
 
index 561081556e342ef182f6d902251916663fd64909..cc3e5a3dab988d298c5aa879affc6bf10c522b83 100644 (file)
@@ -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;