]> git.lyx.org Git - lyx.git/blobdiff - src/lyxlength.C
remove noload/don't typeset
[lyx.git] / src / lyxlength.C
index 9c7826a7e2c106bbb27ad2afd49bf094aaaace2c..b9586b1c3bb5ef88d4ff211ae8d5bef251eb9a55 100644 (file)
@@ -2,7 +2,7 @@
  * ======================================================
  *
  *           LyX, The Document Processor
- *     
+ *
  *           Copyright 1995 Matthias Ettrich
  *           Copyright 1995-2001 The LyX Team.
  *
 #include "lengthcommon.h"
 #include "lyxrc.h"
 
+#include "support/lstrings.h"
+
 #include "Lsstream.h"
 
 #include <cstdlib>
 
+using std::abs;
 
 LyXLength::LyXLength()
        : val_(0), unit_(LyXLength::PT)
@@ -37,8 +40,8 @@ LyXLength::LyXLength(string const & data)
        : val_(0), unit_(LyXLength::PT)
 {
        LyXLength tmp;
-       
-       if (!isValidLength (data, &tmp))
+
+       if (!isValidLength(data, &tmp))
                return; // should raise an exception
 
        val_  = tmp.val_;
@@ -57,20 +60,31 @@ string const LyXLength::asString() const
 string const LyXLength::asLatexString() const
 {
        ostringstream buffer;
-       switch(unit_) {
-       case PW:
-       case PE:
+       switch (unit_) {
+       case PTW:
+           buffer << abs(static_cast<int>(val_/100)) << "."
+                  << abs(static_cast<int>(val_)%100) << "\\textwidth";
+           break;
+       case PCW:
            buffer << abs(static_cast<int>(val_/100)) << "."
                   << abs(static_cast<int>(val_)%100) << "\\columnwidth";
            break;
-       case PP:
+       case PPW:
            buffer << abs(static_cast<int>(val_/100)) << "."
                   << abs(static_cast<int>(val_)%100) << "\\paperwidth";
            break;
-       case PL:
+       case PLW:
            buffer << abs(static_cast<int>(val_/100)) << "."
                   << abs(static_cast<int>(val_)%100) << "\\linewidth";
            break;
+       case PPH:
+           buffer << abs(static_cast<int>(val_/100)) << "."
+                  << abs(static_cast<int>(val_)%100) << "\\paperheight";
+           break;
+       case PTH:
+           buffer << abs(static_cast<int>(val_/100)) << "."
+                  << abs(static_cast<int>(val_)%100) << "\\textheight";
+           break;
        default:
            buffer << val_ << unit_name[unit_]; // setw?
            break;
@@ -103,7 +117,7 @@ void LyXLength::unit(LyXLength::UNIT u)
 }
 
 
-bool LyXLength::zero() const 
+bool LyXLength::zero() const
 {
        return val_ == 0.0;
 }
@@ -123,9 +137,13 @@ int LyXLength::inPixels(int default_width, int default_height) const
 
        // we don't care about sign of value, we
        // display negative space with text too
+#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;
        int val_sign = val_ < 0.0 ? -1 : 1;
-               
+
        switch (unit_) {
        case LyXLength::SP:
                // Scaled point: sp = 1/65536 pt
@@ -183,12 +201,16 @@ int LyXLength::inPixels(int default_width, int default_height) const
                // math mode
                result = zoom * val_ * default_height;
                break;
-       case LyXLength::PW: // Always % of workarea
-       case LyXLength::PE:
-       case LyXLength::PP:
-       case LyXLength::PL:
+       case LyXLength::PCW: // Always % of workarea
+       case LyXLength::PTW:
+       case LyXLength::PPW:
+       case LyXLength::PLW:
                result = val_ * default_width / 100;
                break;
+       case LyXLength::PTH:
+       case LyXLength::PPH:
+               result = val_ * default_height / 100;
+               break;
        case LyXLength::UNIT_NONE:
                result = 0;  // this cannot happen
                break;
@@ -197,6 +219,33 @@ int LyXLength::inPixels(int default_width, int default_height) const
 }
 
 
+int LyXLength::inBP() const
+{
+       // return any LyXLength value as a one with
+       // the PostScript point, called bp (big points)
+       double result = 0.0;
+       switch (unit_) {
+       case LyXLength::CM:
+               // 1bp = 0.2835cm
+               result = val_ * 28.346;
+               break;
+       case LyXLength::MM:
+               // 1bp = 0.02835mm
+               result = val_ * 2.8346;
+               break;
+       case LyXLength::IN:
+               // 1pt = 1/72in
+               result = val_ * 72.0;
+               break;
+       default:
+               // no other than bp possible
+               result = val_;
+               break;
+       }
+       return static_cast<int>(result + 0.5);
+}
+
+
 bool operator==(LyXLength const & l1, LyXLength const & l2)
 {
        return l1.value() == l2.value() && l1.unit() == l2.unit();
@@ -207,4 +256,3 @@ bool operator!=(LyXLength const & l1, LyXLength const & l2)
 {
        return !(l1 == l2);
 }
-