From: Jean-Marc Lasgouttes Date: Fri, 5 Jan 2018 18:59:31 +0000 (+0100) Subject: Move the inPixels(MetricsBase) help from Length to MetricsBase. X-Git-Tag: lyx-2.4.0dev-acb2ca7b~4065 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d77b05db80497cb0b5ce6ca1497165d968c234be;p=features.git Move the inPixels(MetricsBase) help from Length to MetricsBase. A basic class like Length should not depend on something from frontend. This change allows to remove several dummy implementations of theFontMetrics(). --- diff --git a/src/Length.cpp b/src/Length.cpp index 42188d8929..a4d77f34ed 100644 --- a/src/Length.cpp +++ b/src/Length.cpp @@ -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 diff --git a/src/Length.h b/src/Length.h index 8f192f85c6..aaf19238e6 100644 --- a/src/Length.h +++ b/src/Length.h @@ -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; diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp index 60a004573e..93782f9476 100644 --- a/src/MetricsInfo.cpp +++ b/src/MetricsInfo.cpp @@ -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 diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h index ff0b1c6989..f6b9ea8528 100644 --- a/src/MetricsInfo.h +++ b/src/MetricsInfo.h @@ -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_; diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index c593c4c759..96edf43301 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -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; } diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp index dc75aa4251..c1c890c2ed 100644 --- a/src/insets/InsetLine.cpp +++ b/src/insets/InsetLine.cpp @@ -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_); diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index 2a709c4b0e..5e9789c68c 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -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; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 94eed7893e..bc0d0ae3c6 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -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); } diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 6730040390..90fe7fc09a 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -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_); } diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index b3d2e77ab8..7ab51daab0 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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); diff --git a/src/mathed/InsetMathKern.cpp b/src/mathed/InsetMathKern.cpp index d223887e3b..61ee6ee5b7 100644 --- a/src/mathed/InsetMathKern.cpp +++ b/src/mathed/InsetMathKern.cpp @@ -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_); } diff --git a/src/mathed/InsetMathSpace.cpp b/src/mathed/InsetMathSpace.cpp index 88aae1d4a6..627664b631 100644 --- a/src/mathed/InsetMathSpace.cpp +++ b/src/mathed/InsetMathSpace.cpp @@ -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; } diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp index 325d640915..0e2dc81e7b 100644 --- a/src/mathed/MathSupport.cpp +++ b/src/mathed/MathSupport.cpp @@ -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); } diff --git a/src/support/tests/dummy_functions.cpp b/src/support/tests/dummy_functions.cpp index 2b34792b77..e95ea56235 100644 --- a/src/support/tests/dummy_functions.cpp +++ b/src/support/tests/dummy_functions.cpp @@ -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 diff --git a/src/tests/dummy_functions.cpp b/src/tests/dummy_functions.cpp index 95706aad7c..28ea633590 100644 --- a/src/tests/dummy_functions.cpp +++ b/src/tests/dummy_functions.cpp @@ -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 diff --git a/src/tex2lyx/dummy_impl.cpp b/src/tex2lyx/dummy_impl.cpp index 15fbf8b3f3..79278f40a3 100644 --- a/src/tex2lyx/dummy_impl.cpp +++ b/src/tex2lyx/dummy_impl.cpp @@ -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