X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLength.cpp;h=3aa610f659eeaf3c4b5f070fe2e0012631eaa6ee;hb=52019917f411c72ffa6fd8200bc5a89d286d87be;hp=44c3c8137161d1ace6f0c31c316ad8fa46f979f8;hpb=79f11f4e7daadcbf6977e50820d6bd01e6e690b3;p=lyx.git diff --git a/src/Length.cpp b/src/Length.cpp index 44c3c81371..3aa610f659 100644 --- a/src/Length.cpp +++ b/src/Length.cpp @@ -21,8 +21,10 @@ #include "frontends/FontMetrics.h" +#include "support/debug.h" #include "support/docstream.h" #include "support/lstrings.h" +#include "support/lyxlib.h" #include #include @@ -215,7 +217,7 @@ int Length::inPixels(int text_width, int em_width_base) const double const text_width_in = text_width / (zoom * dpi); double const result = zoom * dpi * inInch(text_width_in, em_width_in); - return static_cast(result + ((result >= 0) ? 0.5 : -0.5)); + return support::iround(result); } @@ -299,7 +301,14 @@ double Length::inInch(double text_width, double em_width) const int Length::inPixels(MetricsBase const & base) const { - return inPixels(base.textwidth, theFontMetrics(base.font).em()); + 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()); } @@ -311,7 +320,7 @@ int Length::inBP() const double const text_width_in = 210.0 / 2.54; // assume A4 double const em_width_in = 10.0 / 72.27; double result = 72.0 * inInch(text_width_in, em_width_in); - return static_cast(result + 0.5); + return support::iround(result); } @@ -354,7 +363,8 @@ GlueLength::GlueLength(Length const & len, Length const & plus, GlueLength::GlueLength(string const & data) { - isValidGlueLength(data, this); + if (!isValidGlueLength(data, this)) + LYXERR0("Invalid glue length " + data); }