mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
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().
This commit is contained in:
parent
806f40dbd4
commit
d77b05db80
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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_;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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_);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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_);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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_);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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); }
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user