X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLength.cpp;h=89061e104b2470ef85741c125bc6bf8d52f95500;hb=818249f69fbb59f8ecae17213e046069f53de438;hp=f8eb920c0ff48e5b58bd0065d0aad38d00c9009a;hpb=5014b38cb7ca1967275050a90fcfe1aeade963e4;p=lyx.git diff --git a/src/Length.cpp b/src/Length.cpp index f8eb920c0f..89061e104b 100644 --- a/src/Length.cpp +++ b/src/Length.cpp @@ -17,8 +17,12 @@ #include "Length.h" #include "LyXRC.h" +#include "MetricsInfo.h" + +#include "frontends/FontMetrics.h" #include "support/docstream.h" +#include "support/lstrings.h" #include #include @@ -57,17 +61,11 @@ Length::Length(string const & data) } -void Length::swap(Length & rhs) -{ - std::swap(val_, rhs.val_); - std::swap(unit_, rhs.unit_); -} - - string const Length::asString() const { ostringstream os; - os << val_ << unit_name[unit_]; // setw? + if (unit_ != UNIT_NONE) + os << val_ << unit_name[unit_]; // setw? return os.str(); } @@ -75,7 +73,8 @@ string const Length::asString() const docstring const Length::asDocstring() const { odocstringstream os; - os << val_ << unit_name[unit_]; // setw? + if (unit_ != UNIT_NONE) + os << val_ << unit_name[unit_]; // setw? return os.str(); } @@ -83,27 +82,31 @@ docstring const Length::asDocstring() const string const Length::asLatexString() const { ostringstream os; + // Do not allow scientific notation (e.g. 1.2e+03), since this is not valid + // LaTeX (bug 9416) switch (unit_) { case PTW: - os << val_ / 100.0 << "\\textwidth"; + os << support::formatFPNumber(val_ / 100.0) << "\\textwidth"; break; case PCW: - os << val_ / 100.0 << "\\columnwidth"; + os << support::formatFPNumber(val_ / 100.0) << "\\columnwidth"; break; case PPW: - os << val_ / 100.0 << "\\paperwidth"; + os << support::formatFPNumber(val_ / 100.0) << "\\paperwidth"; break; case PLW: - os << val_ / 100.0 << "\\linewidth"; + os << support::formatFPNumber(val_ / 100.0) << "\\linewidth"; break; case PTH: - os << val_ / 100.0 << "\\textheight"; + os << support::formatFPNumber(val_ / 100.0) << "\\textheight"; break; case PPH: - os << val_ / 100.0 << "\\paperheight"; + os << support::formatFPNumber(val_ / 100.0) << "\\paperheight"; + break; + case UNIT_NONE: break; default: - os << val_ << unit_name[unit_]; + os << support::formatFPNumber(val_) << unit_name[unit_]; break; } return os.str(); @@ -200,7 +203,7 @@ int Length::inPixels(int text_width, int em_width_base) const ? em_width_base : 10*(dpi/72.27)*zoom; // A different estimate for em_width is - // theFontMetrics(FontInfo(sane_font)).width('M') + // theFontMetrics(FontInfo(sane_font)).em() // but this estimate might not be more accurate as the screen font // is different then the latex font. @@ -291,6 +294,12 @@ int Length::inPixels(int text_width, int em_width_base) const } +int Length::inPixels(MetricsBase const & base) const +{ + return inPixels(base.textwidth, theFontMetrics(base.font).em()); +} + + int Length::inBP() const { // return any Length value as a one with @@ -363,6 +372,9 @@ GlueLength::GlueLength(string const & data) string const GlueLength::asString() const { + if (len_.empty()) + return string(); + ostringstream buffer; buffer << len_.value();