]> git.lyx.org Git - lyx.git/blobdiff - src/Length.cpp
Try even harder to obtain an instant preview
[lyx.git] / src / Length.cpp
index bb9ec6a3b90b8096d46af014a537cdd869a9527f..2463be8f66c889d37810e907fddbc37d67b5f842 100644 (file)
 
 #include "Length.h"
 #include "LyXRC.h"
+#include "MetricsInfo.h"
+
+#include "frontends/FontMetrics.h"
 
 #include "support/docstream.h"
-#include "support/lassert.h"
 
 #include <sstream>
 #include <iomanip>
@@ -58,13 +60,6 @@ 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;
@@ -106,8 +101,7 @@ string const Length::asLatexString() const
                os << val_ / 100.0 << "\\paperheight";
                break;
        case UNIT_NONE:
-               // One should not try to ouput latex code for an empty length
-               LASSERT(false, break);
+               break;
        default:
                os << val_ << unit_name[unit_];
          break;
@@ -206,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.
 
@@ -297,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