]> git.lyx.org Git - lyx.git/blobdiff - src/Length.cpp
PDF-form.lyx: add a note
[lyx.git] / src / Length.cpp
index 4b269aa31517e1ee7bd72dd40f3aa4b3333e3caa..2463be8f66c889d37810e907fddbc37d67b5f842 100644 (file)
@@ -17,6 +17,9 @@
 
 #include "Length.h"
 #include "LyXRC.h"
+#include "MetricsInfo.h"
+
+#include "frontends/FontMetrics.h"
 
 #include "support/docstream.h"
 
@@ -57,17 +60,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 +72,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();
 }
 
@@ -96,11 +94,13 @@ string const Length::asLatexString() const
        case PLW:
                os << val_ / 100.0 << "\\linewidth";
                break;
+       case PTH:
+               os << val_ / 100.0 << "\\textheight";
+               break;
        case PPH:
                os << val_ / 100.0 << "\\paperheight";
                break;
-       case PTH:
-               os << val_ / 100.0 << "\\textheight";
+       case UNIT_NONE:
                break;
        default:
                os << val_ << unit_name[unit_];
@@ -200,7 +200,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 +291,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
@@ -320,20 +326,7 @@ int Length::inBP() const
 
 Length::UNIT Length::defaultUnit()
 {
-       // FIXME user a proper pref, since we should get rid of
-       // default_papersize in lyxrc.
-       UNIT u = Length::CM;
-       switch (lyxrc.default_papersize) {
-               case PAPER_USLETTER:
-               case PAPER_USLEGAL:
-               case PAPER_USEXECUTIVE:
-                       u = Length::IN;
-                       break;
-               default:
-                       break;
-       }
-
-       return u;
+       return lyxrc.default_length_unit;
 }
 
 
@@ -376,6 +369,9 @@ GlueLength::GlueLength(string const & data)
 
 string const GlueLength::asString() const
 {
+       if (len_.empty())
+               return string();
+
        ostringstream buffer;
 
        buffer << len_.value();