]> git.lyx.org Git - lyx.git/blobdiff - src/Length.cpp
Split external_templates to individual *.xtemplate files
[lyx.git] / src / Length.cpp
index 44c3c8137161d1ace6f0c31c316ad8fa46f979f8..3aa610f659eeaf3c4b5f070fe2e0012631eaa6ee 100644 (file)
 
 #include "frontends/FontMetrics.h"
 
+#include "support/debug.h"
 #include "support/docstream.h"
 #include "support/lstrings.h"
+#include "support/lyxlib.h"
 
 #include <sstream>
 #include <iomanip>
@@ -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<int>(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<int>(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);
 }