]> git.lyx.org Git - lyx.git/blobdiff - src/Length.cpp
Remove hardcoded values
[lyx.git] / src / Length.cpp
index 35f6b0cb424060116e30511e127867e173227641..62b7c842f8f8bf509a06406cb27af5c9023d2466 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "support/docstream.h"
 #include "support/lstrings.h"
+#include "support/lyxlib.h"
 
 #include <sstream>
 #include <iomanip>
@@ -75,7 +76,8 @@ docstring const Length::asDocstring() const
 {
        odocstringstream os;
        if (unit_ != UNIT_NONE)
-               os << formatFPNumber(val_) << unit_name[unit_]; // setw?
+               os << from_ascii(formatFPNumber(val_))
+                  << from_ascii(unit_name[unit_]); // setw?
        return os.str();
 }
 
@@ -214,7 +216,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);
 }
 
 
@@ -298,7 +300,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());
 }
 
 
@@ -310,7 +319,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);
 }
 
 
@@ -353,6 +362,8 @@ GlueLength::GlueLength(Length const & len, Length const & plus,
 
 GlueLength::GlueLength(string const & data)
 {
+       // false positive from coverity
+       // coverity[CHECKED_RETURN]
        isValidGlueLength(data, this);
 }