#include "Length.h"
#include "LyXRC.h"
+#include "MetricsInfo.h"
+
+#include "frontends/FontMetrics.h"
#include "support/docstream.h"
+#include "support/lstrings.h"
#include <sstream>
#include <iomanip>
}
-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();
}
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();
}
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();
? 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.
}
+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
string const GlueLength::asString() const
{
+ if (len_.empty())
+ return string();
+
ostringstream buffer;
buffer << len_.value();