1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "lyxlength.h"
18 #include "lengthcommon.h"
25 LyXLength::LyXLength()
26 : val_(0), unit_(LyXLength::PT)
30 LyXLength::LyXLength(double v, LyXLength::UNIT u)
35 LyXLength::LyXLength(string const & data)
39 if (!isValidLength (data, &tmp))
40 return; // should raise an exception
47 string const LyXLength::asString() const
50 buffer << val_ << unit_name[unit_]; // setw?
51 return buffer.str().c_str();
55 string const LyXLength::asLatexString() const
61 buffer << abs(static_cast<int>(val_/100)) << "."
62 << abs(static_cast<int>(val_)%100) << "\\columnwidth";
65 buffer << abs(static_cast<int>(val_/100)) << "."
66 << abs(static_cast<int>(val_)%100) << "\\pagewidth";
69 buffer << abs(static_cast<int>(val_/100)) << "."
70 << abs(static_cast<int>(val_)%100) << "\\linewidth";
73 buffer << val_ << unit_name[unit_]; // setw?
76 return buffer.str().c_str();
80 double LyXLength::value() const
86 LyXLength::UNIT LyXLength::unit() const
92 void LyXLength::value(double v)
98 void LyXLength::unit(LyXLength::UNIT u)
104 bool LyXLength::zero() const
110 bool operator==(LyXLength const & l1, LyXLength const & l2)
112 return l1.value() == l2.value() && l1.unit() == l2.unit();
116 bool operator!=(LyXLength const & l1, LyXLength const & l2)