]> git.lyx.org Git - features.git/commitdiff
Revert "Try to compute row height like it should be done"
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 13 May 2019 08:47:47 +0000 (10:47 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:29 +0000 (15:48 +0200)
This is not done right at all. The best is to revert for now and
think about how to do it properly.

This reverts commit 66a3d64346332e47252b37dbc0f80158738987dc.

src/Row.cpp
src/TextMetrics.cpp
src/frontends/FontMetrics.h
src/frontends/qt4/GuiFontMetrics.cpp
src/frontends/qt4/GuiFontMetrics.h

index 1a12e9d695137a7a9d2c691a9193090b07e8c3c9..697e526094b7f399801f4d62d24f7b39f5fc503a 100644 (file)
@@ -376,11 +376,8 @@ void Row::finalizeLast()
 
        if (elt.type == STRING) {
                dim_.wid -= elt.dim.wid;
-               FontMetrics const & fm = theFontMetrics(elt.font);
-               elt.dim.wid = fm.width(elt.str);
+               elt.dim.wid = theFontMetrics(elt.font).width(elt.str);
                dim_.wid += elt.dim.wid;
-               dim_.asc = fm.maxAscent() + fm.leading();
-               dim_.des = fm.maxDescent();
        }
 }
 
index fc7e09d8628ca79cc4069f4b4f29ff04a97b12ec..6f195a602245e51790334845c208f4e3b70a05fc 100644 (file)
@@ -48,7 +48,6 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/lassert.h"
-#include "support/lyxlib.h"
 
 #include <stdlib.h>
 #include <cmath>
@@ -62,10 +61,6 @@ using frontend::FontMetrics;
 
 namespace {
 
-// the somewhat arbitrary leading added between rows. This is 20% of
-// the characters height, inluding the possible leading of the font.
-// 20% is a standard value used by LaTeX and word processors.
-double const extra_leading = 0.2;
 
 int numberOfLabelHfills(Paragraph const & par, Row const & row)
 {
@@ -1155,19 +1150,27 @@ void TextMetrics::setRowHeight(Row & row) const
        // Initial value for ascent (useful if row is empty).
        Font const font = displayFont(row.pit(), row.pos());
        FontMetrics const & fm = theFontMetrics(font);
-       int maxasc = fm.maxAscent() + fm.leading();
-       int maxdes = fm.maxDescent();
+       int maxasc = int(fm.maxAscent() * spacing_val);
+       int maxdes = int(fm.maxDescent() * spacing_val);
 
        // Find the ascent/descent of the row contents
        for (Row::Element const & e : row) {
-               maxasc = max(maxasc, e.dim.ascent());
-               maxdes = max(maxdes, e.dim.descent());
+               if (e.inset) {
+                       maxasc = max(maxasc, e.dim.ascent());
+                       maxdes = max(maxdes, e.dim.descent());
+               } else {
+                       FontMetrics const & fm2 = theFontMetrics(e.font);
+                       maxasc = max(maxasc, int(fm2.maxAscent() * spacing_val));
+                       maxdes = max(maxdes, int(fm2.maxDescent() * spacing_val));
+               }
        }
 
-       // Add some leading (split between before and after)
-       int const leading = support::iround(extra_leading * (maxasc + maxdes));
-       row.dim().asc = int((maxasc + leading - leading / 2) * spacing_val);
-       row.dim().des = int((maxdes + leading / 2) * spacing_val);
+       // This is nicer with box insets
+       ++maxasc;
+       ++maxdes;
+
+       row.dim().asc = maxasc;
+       row.dim().des = maxdes;
 }
 
 
@@ -2017,8 +2020,7 @@ void TextMetrics::completionPosAndDim(Cursor const & cur, int & x, int & y,
 
 int defaultRowHeight()
 {
-       FontMetrics const & fm = theFontMetrics(sane_font);
-       return support::iround(fm.maxHeight() * (1 + extra_leading) + fm.leading());
+       return int(theFontMetrics(sane_font).maxHeight() *  1.2);
 }
 
 } // namespace lyx
index a35a26b481dfa4ded2072ade65a0e41c927f5b78..4472aa70083855c96018e9dd8d34fc7b97c01184 100644 (file)
@@ -60,8 +60,6 @@ public:
        virtual int maxAscent() const = 0;
        /// return the maximum descent of the font
        virtual int maxDescent() const = 0;
-       /// return the default leading of the font (often 0)
-       virtual int leading() const = 0;
        /// return default dimension of the font.
        /// \warning \c width is set to zero.
        virtual Dimension const defaultDimension() const = 0;
index 5f70c8d705f3b4ed25603f6ddad8067d4c0bc430..10ca292cb63ef948022bf34ccbd6f1ecbfafb3ec 100644 (file)
@@ -111,12 +111,6 @@ int GuiFontMetrics::maxDescent() const
 }
 
 
-int GuiFontMetrics::leading() const
-{
-       return metrics_.leading();
-}
-
-
 int GuiFontMetrics::em() const
 {
        return QFontInfo(font_).pixelSize();
index 830a824addd698ebb148acbb598f4da0068e3fa9..4f0b3076a39fa4b1bed40597176e61eed4e49e84 100644 (file)
@@ -36,7 +36,6 @@ public:
 
        virtual int maxAscent() const;
        virtual int maxDescent() const;
-       virtual int leading() const;
        virtual Dimension const defaultDimension() const;
        virtual int em() const;
        virtual int xHeight() const;