]> git.lyx.org Git - features.git/commitdiff
Move the inPixels(MetricsBase) help from Length to MetricsBase.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 5 Jan 2018 18:59:31 +0000 (19:59 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 5 Jan 2018 19:14:04 +0000 (20:14 +0100)
A basic class like Length should not depend on something from
frontend.

This change allows to remove several dummy implementations of
theFontMetrics().

16 files changed:
src/Length.cpp
src/Length.h
src/MetricsInfo.cpp
src/MetricsInfo.h
src/insets/InsetBox.cpp
src/insets/InsetLine.cpp
src/insets/InsetSpace.cpp
src/insets/InsetTabular.cpp
src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathKern.cpp
src/mathed/InsetMathSpace.cpp
src/mathed/MathSupport.cpp
src/support/tests/dummy_functions.cpp
src/tests/dummy_functions.cpp
src/tex2lyx/dummy_impl.cpp

index 42188d8929e444387efbaec46668283ee49fbad7..a4d77f34ed041cbb049a20c858e2cddde8c94f25 100644 (file)
@@ -17,9 +17,6 @@
 
 #include "Length.h"
 #include "LyXRC.h"
-#include "MetricsInfo.h"
-
-#include "frontends/FontMetrics.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
@@ -309,19 +306,6 @@ double Length::inInch(double text_width, double em_width) const
 }
 
 
-int Length::inPixels(MetricsBase const & base) const
-{
-       FontInfo fi = base.font;
-       if (unit_ == Length::MU)
-               // mu is 1/18th of an em in the math symbol font
-               fi.setFamily(SYMBOL_FAMILY);
-       else
-               // Math style is only taken into account in the case of mu
-               fi.setStyle(LM_ST_TEXT);
-       return inPixels(base.textwidth, theFontMetrics(fi).em());
-}
-
-
 int Length::inBP() const
 {
        // return any Length value as a one with
index 8f192f85c6730d05a68a2102b20b06b8f06371fb..aaf19238e69541a47db7eb47cea89cdf08ac9bf7 100644 (file)
@@ -20,8 +20,6 @@
 
 namespace lyx {
 
-class MetricsBase;
-
 // Solaris/x86 version 9 and earlier define these
 #undef PC
 #undef SP
@@ -98,12 +96,6 @@ public:
         */
        int inPixels(int text_width, int em_width = 0) const;
 
-       /** return the on-screen size of this length
-        *
-        *  This version of the function uses the current inset width as
-        *  width and the EM value of the current font.
-        */
-       int inPixels(MetricsBase const &) const;
        /// return the value in Big Postscript points.
        /// Caution: Inaccurate for em, ex, mu and percent units.
        int inBP() const;
index 60a004573e2d3d61c1c4bc3d4fe71d077f32a8b0..93782f94765882948b245d7959d7965796b44d00 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "mathed/MathSupport.h"
 
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "support/docstring.h"
@@ -94,6 +95,19 @@ Changer MetricsBase::changeEnsureMath(Inset::mode_type mode)
 }
 
 
+int MetricsBase::inPixels(Length const & len) const
+{
+       FontInfo fi = font;
+       if (len.unit() == Length::MU)
+               // mu is 1/18th of an em in the math symbol font
+               fi.setFamily(SYMBOL_FAMILY);
+       else
+               // Math style is only taken into account in the case of mu
+               fi.setStyle(LM_ST_TEXT);
+       return len.inPixels(textwidth, theFontMetrics(fi).em());
+}
+
+
 /////////////////////////////////////////////////////////////////////////
 //
 // MetricsInfo
index ff0b1c698941faeec9e2add2b2f2f3dc408c4f93..f6b9ea8528cd48cd63cce8e58dd1224f47d19ae3 100644 (file)
@@ -30,6 +30,7 @@ namespace lyx {
 
 namespace frontend { class Painter; }
 class BufferView;
+class Length;
 class MacroContext;
 
 
@@ -69,6 +70,13 @@ public:
        int solidLineOffset() const { return solid_line_offset_; }
        ///
        int dottedLineThickness() const { return dotted_line_thickness_; }
+       /** return the on-screen size of this length
+        *
+        *  This version of the function uses the current inset width as
+        *  width and the EM value of the current font.
+        */
+       int inPixels(Length const & len) const;
+
 private:
        int solid_line_thickness_;
        int solid_line_offset_;
index c593c4c759b6ed311ad584b05c47bbd8d1bc6896..96edf4330109140f373a4f1114329dd1f43f2f19 100644 (file)
@@ -182,15 +182,15 @@ bool InsetBox::allowMultiPar() const
 }
 
 
-void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
+void InsetBox::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        // back up textwidth.
-       int textwidth_backup = m.base.textwidth;
+       int textwidth_backup = mi.base.textwidth;
        if (hasFixedWidth())
-               m.base.textwidth = params_.width.inPixels(m.base);
-       InsetCollapsible::metrics(m, dim);
+               mi.base.textwidth = mi.base.inPixels(params_.width);
+       InsetCollapsible::metrics(mi, dim);
        // retore textwidth.
-       m.base.textwidth = textwidth_backup;
+       mi.base.textwidth = textwidth_backup;
 }
 
 
index dc75aa42516a0e8b6597864d5d09e37f5a2cadd3..c1c890c2ed8b7ffe81bd023f18ad997b0d8e313f 100644 (file)
@@ -112,7 +112,7 @@ void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
        int const max_width = mi.base.textwidth;
 
        Length const width(to_ascii(getParam("width")));
-       dim.wid = width.inPixels(mi.base);
+       dim.wid = mi.base.inPixels(width);
 
        // assure that the line inset is not outside of the window
        // check that it doesn't exceed the outer boundary
@@ -124,11 +124,11 @@ void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.wid = max(minw, abs(dim.wid));
 
        Length height = Length(to_ascii(getParam("height")));
-       height_ = height.inPixels(mi.base);
+       height_ = mi.base.inPixels(height);
 
        // get the length of the parameters in pixels
        Length offset = Length(to_ascii(getParam("offset")));
-       offset_ = offset.inPixels(mi.base);
+       offset_ = mi.base.inPixels(offset);
 
        dim.asc = max(fm.maxAscent(), offset_ + height_);
        dim.des = max(fm.maxDescent(), - offset_);
index 2a709c4b0edf28c15fb3d070c02fe5b49a16a2b7..5e9789c68c058c1b5aaa77da05c880acfc178746 100644 (file)
@@ -243,8 +243,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
                        break;
                case InsetSpaceParams::CUSTOM:
                case InsetSpaceParams::CUSTOM_PROTECTED: {
-                       int const w =
-                               params_.length.len().inPixels(mi.base);
+                       int const w = mi.base.inPixels(params_.length.len());
                        int const minw = (w < 0) ? 3 * arrow_size : 4;
                        dim.wid = max(minw, abs(w));
                        break;
index 94eed7893eb231315f16bf8016733f56a4ff41fa..bc0d0ae3c601b2702038f46b1d6af866ca057398 100644 (file)
@@ -3690,7 +3690,7 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
                        MetricsInfo m = mi;
                        Length const p_width = tabular.getPWidth(cell);
                        if (!p_width.zero())
-                               m.base.textwidth = p_width.inPixels(mi.base);
+                               m.base.textwidth = mi.base.inPixels(p_width);
                        tabular.cellInset(cell)->metrics(m, dim);
                        if (!p_width.zero())
                                dim.wid = m.base.textwidth;
@@ -3750,12 +3750,12 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
                        maxdes = max(maxdes, dim.des + offset);
                }
                int const top_space = tabular.row_info[r].top_space_default ?
-                       default_line_space :
-                       tabular.row_info[r].top_space.inPixels(mi.base);
+                   default_line_space :
+                   mi.base.inPixels(tabular.row_info[r].top_space);
                tabular.setRowAscent(r, maxasc + ADD_TO_HEIGHT + top_space);
                int const bottom_space = tabular.row_info[r].bottom_space_default ?
-                       default_line_space :
-                       tabular.row_info[r].bottom_space.inPixels(mi.base);
+                   default_line_space :
+                   mi.base.inPixels(tabular.row_info[r].bottom_space);
                tabular.setRowDescent(r, maxdes + ADD_TO_HEIGHT + bottom_space);
        }
 
index 67300403907d947f43f1ca71e2b75323bf2192e6..90fe7fc09a6fa2b912f57f5d8e072b345c54b447 100644 (file)
@@ -99,7 +99,7 @@ InsetMathGrid::RowInfo::RowInfo()
 
 int InsetMathGrid::RowInfo::skipPixels(MetricsInfo const & mi) const
 {
-       return crskip_.inPixels(mi.base);
+       return mi.base.inPixels(crskip_);
 }
 
 
index b3d2e77ab8dbacf6d64ea40120cd71e5fd814c36..7ab51daab093e2153767be9b01bf7476c0410fba 100644 (file)
@@ -565,7 +565,7 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
 
                if (l)
                        // Value was hardcoded to 30 pixels
-                       dim.wid += Length(0.3, Length::IN).inPixels(mi.base) + l;
+                       dim.wid += mi.base.inPixels(Length(0.3, Length::IN)) + l;
        }
 
        // reserve some space for marker.
@@ -674,7 +674,7 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
 
                if (l)
                        // Value was hardcoded to 30 pixels
-                       xmath += Length(0.3, Length::IN).inPixels(pi.base) + l;
+                       xmath += pi.base.inPixels(Length(0.3, Length::IN)) + l;
        }
 
        InsetMathGrid::draw(pi, xmath + 1, y);
index d223887e3b6c2d712f0c9a4a1b577dc1e285b70c..61ee6ee5b7db7cd7855fb887b1ac3450a4bd7aff 100644 (file)
@@ -49,7 +49,7 @@ void InsetMathKern::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        dim.asc = 0;
        dim.des = 0;
-       dim.wid = wid_.inPixels(mi.base);
+       dim.wid = mi.base.inPixels(wid_);
 }
 
 
index 88aae1d4a66a85771e783ba88e7aa93b58a561d6..627664b63116b56b1cf271fe4eab246adcba463e 100644 (file)
@@ -125,7 +125,7 @@ void InsetMathSpace::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = 4;
        dim.des = 0;
        if (space_info[space_].custom)
-               dim.wid = abs(length_.inPixels(mi.base));
+               dim.wid = abs(mi.base.inPixels(length_));
        else
                dim.wid = space_info[space_].width;
 }
index 325d640915e4ea2500693451e38494d4096c2286..0e2dc81e7bcabfdb7f4809af1b7a25bfcc634236 100644 (file)
@@ -545,7 +545,7 @@ int mathed_font_x_height(FontInfo const & font)
 int mathed_mu(FontInfo const & font, double mu)
 {
        MetricsBase mb(nullptr, font);
-       return Length(mu, Length::MU).inPixels(mb);
+       return mb.inPixels(Length(mu, Length::MU));
 }
 
 int mathed_thinmuskip(FontInfo const & font) { return mathed_mu(font, 3.0); }
index 2b34792b777ded356fb540ac02a6a8ed18dd3f25..e95ea562356604e4409deb62ec8943265ff99d07 100644 (file)
@@ -46,20 +46,4 @@ namespace lyx {
                return string();
        }
 
-       //
-       // Dummy FontMetrics (needed by Length)
-       //
-       namespace frontend {
-       class FontMetrics {
-               int em() const { return 0; };
-       };
-       } // namespace frontend
-
-       class FontInfo;
-
-       frontend::FontMetrics const & theFontMetrics(FontInfo const &) {
-               static frontend::FontMetrics dummy;
-               return dummy;
-       }
-
 } // namespace lyx
index 95706aad7c58fac7754c7dda0184fba319db213f..28ea633590ec6f7560c7b6887c41156e6f680939 100644 (file)
@@ -49,20 +49,4 @@ namespace lyx {
                return string();
        }
 
-       //
-       // Dummy FontMetrics (needed by Length)
-       //
-       namespace frontend {
-       class FontMetrics {
-               int em() const { return 0; };
-       };
-       } // namespace frontend
-
-       class FontInfo;
-
-       frontend::FontMetrics const & theFontMetrics(FontInfo const &) {
-               static frontend::FontMetrics dummy;
-               return dummy;
-       }
-
 } // namespace lyx
index 15fbf8b3f36a0c13e46bbe59f287b904c3c8a6af..79278f40a379f59312f4cf0d2a1f240ac921bad7 100644 (file)
@@ -112,22 +112,6 @@ string alignmentToCSS(LyXAlignment)
        return string();
 }
 
-//
-// Dummy FontMetrics (needed by Length)
-//
-
-namespace frontend {
-class FontMetrics {
-       int em() const { return 0; };
-};
-} // namespace frontend
-
-class FontInfo;
-
-frontend::FontMetrics const & theFontMetrics(FontInfo const &) {
-       static frontend::FontMetrics dummy;
-       return dummy;
-}
 
 //
 // Keep the linker happy on Windows