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)
36 : val_(0), unit_(LyXLength::PT)
40 if (!isValidLength (data, &tmp))
41 return; // should raise an exception
48 string const LyXLength::asString() const
51 buffer << val_ << unit_name[unit_]; // setw?
52 return buffer.str().c_str();
56 string const LyXLength::asLatexString() const
62 buffer << abs(static_cast<int>(val_/100)) << "."
63 << abs(static_cast<int>(val_)%100) << "\\columnwidth";
66 buffer << abs(static_cast<int>(val_/100)) << "."
67 << abs(static_cast<int>(val_)%100) << "\\pagewidth";
70 buffer << abs(static_cast<int>(val_/100)) << "."
71 << abs(static_cast<int>(val_)%100) << "\\linewidth";
74 buffer << val_ << unit_name[unit_]; // setw?
77 return buffer.str().c_str();
81 double LyXLength::value() const
87 LyXLength::UNIT LyXLength::unit() const
93 void LyXLength::value(double v)
99 void LyXLength::unit(LyXLength::UNIT u)
105 bool LyXLength::zero() const
111 bool operator==(LyXLength const & l1, LyXLength const & l2)
113 return l1.value() == l2.value() && l1.unit() == l2.unit();
117 bool operator!=(LyXLength const & l1, LyXLength const & l2)