]> git.lyx.org Git - lyx.git/blobdiff - src/lyxlength.C
To make make install behave
[lyx.git] / src / lyxlength.C
index 2cc2e853b2cc3b5720e74a9b23518849a79c23e7..67be44c917df7c0dba587c603acebdbc1e18846a 100644 (file)
@@ -2,7 +2,7 @@
  * ======================================================
  *
  *           LyX, The Document Processor
- *     
+ *
  *           Copyright 1995 Matthias Ettrich
  *           Copyright 1995-2001 The LyX Team.
  *
@@ -17,8 +17,8 @@
 #include "lyxlength.h"
 #include "lengthcommon.h"
 #include "lyxrc.h"
-#include "BufferView.h"
-#include "lyxtext.h"
+
+#include "support/lstrings.h"
 
 #include "Lsstream.h"
 
@@ -35,12 +35,48 @@ LyXLength::LyXLength(double v, LyXLength::UNIT u)
 {}
 
 
+#ifndef NO_PEXTRA_REALLY
+// compatibility stuff < version 1.2.0pre and for 
+// "old" 1.2.0 files before the pre
+namespace {
+string const convertOldRelLength(string const & oldLength) 
+{
+       // we can have only one or none of the following
+       if (oldLength.find("c%") != string::npos) {
+               return subst(oldLength,"c%","col%");
+                   
+       } else if (oldLength.find("t%") != string::npos) {
+               if (oldLength.find("text%") != string::npos)
+                   return oldLength;
+               else
+                   return subst(oldLength,"t%","text%");
+
+       } else if (oldLength.find("l%") != string::npos) {
+               if (oldLength.find("col%") != string::npos)
+                   return oldLength;
+               else
+                   return subst(oldLength,"l%","line%");
+
+       } else if (oldLength.find("p%") != string::npos)
+               return subst(oldLength,"p%","page%");
+
+       return oldLength;
+}
+} // end anon
+#endif
+
 LyXLength::LyXLength(string const & data)
        : val_(0), unit_(LyXLength::PT)
 {
        LyXLength tmp;
-       
+
+#ifndef NO_PEXTRA_REALLY
+       // this is needed for 1.1.x minipages with width like %t
+       if (!isValidLength (convertOldRelLength(data), &tmp))
+#else
        if (!isValidLength (data, &tmp))
+#endif
+               if (!isValidLength (convertOldRelLength(data), &tmp))
                return; // should raise an exception
 
        val_  = tmp.val_;
@@ -59,15 +95,18 @@ string const LyXLength::asString() const
 string const LyXLength::asLatexString() const
 {
        ostringstream buffer;
-       switch(unit_) {
+       switch (unit_) {
        case PW:
+           buffer << abs(static_cast<int>(val_/100)) << "."
+                  << abs(static_cast<int>(val_)%100) << "\\textwidth";
+           break;
        case PE:
            buffer << abs(static_cast<int>(val_/100)) << "."
                   << abs(static_cast<int>(val_)%100) << "\\columnwidth";
            break;
        case PP:
            buffer << abs(static_cast<int>(val_/100)) << "."
-                  << abs(static_cast<int>(val_)%100) << "\\pagewidth";
+                  << abs(static_cast<int>(val_)%100) << "\\paperwidth";
            break;
        case PL:
            buffer << abs(static_cast<int>(val_/100)) << "."
@@ -105,18 +144,14 @@ void LyXLength::unit(LyXLength::UNIT u)
 }
 
 
-bool LyXLength::zero() const 
+bool LyXLength::zero() const
 {
        return val_ == 0.0;
 }
 
 
-int LyXLength::inPixels(BufferView const * bv) const
+int LyXLength::inPixels(int default_width, int default_height) const
 {
-       // Height of a normal line in pixels (zoom factor considered)
-       int height = bv->text->defaultHeight(); // [pixels]
-       int default_width  = bv->workWidth();
-
        // Zoom factor specified by user in percent
        double const zoom = lyxrc.zoom / 100.0; // [percent]
 
@@ -131,7 +166,7 @@ int LyXLength::inPixels(BufferView const * bv) const
        // display negative space with text too
        double result = 0.0;
        int val_sign = val_ < 0.0 ? -1 : 1;
-               
+
        switch (unit_) {
        case LyXLength::SP:
                // Scaled point: sp = 1/65536 pt
@@ -179,15 +214,15 @@ int LyXLength::inPixels(BufferView const * bv) const
                break;
        case LyXLength::EX:
                // Ex: The height of an "x"
-               result = zoom * val_ * height / 2; // what to / width?
+               result = zoom * val_ * default_height / 2; // what to / width?
                break;
        case LyXLength::EM: // what to / width?
                // Em: The width of an "m"
-               result = zoom * val_ * height / 2; // Why 2?
+               result = zoom * val_ * default_height / 2; // Why 2?
                break;
        case LyXLength::MU: // This is probably only allowed in
                // math mode
-               result = zoom * val_ * height;
+               result = zoom * val_ * default_height;
                break;
        case LyXLength::PW: // Always % of workarea
        case LyXLength::PE:
@@ -213,4 +248,3 @@ bool operator!=(LyXLength const & l1, LyXLength const & l2)
 {
        return !(l1 == l2);
 }
-