]> git.lyx.org Git - features.git/commitdiff
Better mechanism for setting cell 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>
Fri, 20 Apr 2018 07:59:45 +0000 (09:59 +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.

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 6c237f6cdf582d8783bea3f2891d13fb7beaf1e5..cb6f440539ba6083f394d4129fedd756175066f8 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 08d92871ca942e8acfbb4d12031356d32e425d1d..83983477515083f7b351af2536726fee2e1fc7be 100644 (file)
@@ -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);
 }
 
 
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 d242a86f72c2d228c16a6a98b399e9457d4251a9..719065d0cef2198e30f74870a6e10b54226e69c6 100644 (file)
@@ -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);
 }
index 70c001975e9614a32f54c84ab6da621398cda9a7..efa581c4142de17569828dbfed772033c2454f5d 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;