X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxlength.C;h=fded92c19bcfe53b595f0d24e86a7cc713607f6f;hb=d2574b7d8e2716d3d3aea92df6576bd01c421a6c;hp=c461efd4755dd666661e2c7275aabafef4ceeadf;hpb=b447408de232872fef1537fca542abc23702d572;p=lyx.git diff --git a/src/lyxlength.C b/src/lyxlength.C index c461efd475..fded92c19b 100644 --- a/src/lyxlength.C +++ b/src/lyxlength.C @@ -19,10 +19,14 @@ #include "lengthcommon.h" #include "lyxrc.h" +#include "support/docstream.h" +#include +#include + + +namespace lyx { -#include "support/std_sstream.h" -using std::abs; using std::ostringstream; using std::string; @@ -58,35 +62,41 @@ string const LyXLength::asString() const } +docstring const LyXLength::asDocstring() const +{ + odocstringstream os; + os << val_ << unit_name[unit_]; // setw? + return os.str(); +} + + string const LyXLength::asLatexString() const { - char buffer[80]; + ostringstream os; switch (unit_) { case PTW: - snprintf(buffer, 78, "%.2f\\textwidth", val_/100.0); - break; - case PCW: - snprintf(buffer, 78, "%.2f\\columnwidth", val_/100.0); - break; - case PPW: - snprintf(buffer, 78, "%.2f\\paperwidth", val_/100.0); - break; - case PLW: - snprintf(buffer, 78, "%.2f\\linewidth", val_/100.0); - break; - case PPH: - snprintf(buffer, 78, "%.2f\\paperheight", val_/100.0); - break; - case PTH: - snprintf(buffer, 78, "%.2f\\textheight", val_/100.0); + os << val_ / 100.0 << "\\textwidth"; + break; + case PCW: + os << val_ / 100.0 << "\\columnwidth"; + break; + case PPW: + os << val_ / 100.0 << "\\paperwidth"; + break; + case PLW: + os << val_ / 100.0 << "\\linewidth"; + break; + case PPH: + os << val_ / 100.0 << "\\paperheight"; + break; + case PTH: + os << val_ / 100.0 << "\\textheight"; break; default: - snprintf(buffer, 78, "%f%s", val_, unit_name[unit_]); + os << val_ << unit_name[unit_]; break; } - // paranoia - buffer[79] = 0; - return buffer; + return os.str(); } @@ -138,7 +148,7 @@ int LyXLength::inPixels(int text_width, int em_width_base) const ? em_width_base : 10*(dpi/72.27)*zoom; // A different estimate for em_width is - // font_metrics::width('M', LyXFont(LyXFont::ALL_SANE)) + // theFontMetrics(LyXFont(LyXFont::ALL_SANE)).width('M') // but this estimate might not be more accurate as the screen font // is different then the latex font. @@ -146,10 +156,6 @@ int LyXLength::inPixels(int text_width, int em_width_base) const // between lengths and font sizes on the screen // is the same as on paper. -#ifdef WITH_WARNINGS -#warning if you don't care than either call this function differently or let it return negative values and call abs() explicitly when needed (Andre') -#endif - double result = 0.0; switch (unit_) { @@ -270,3 +276,6 @@ bool operator!=(LyXLength const & l1, LyXLength const & l2) { return !(l1 == l2); } + + +} // namespace lyx