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"
21 #if defined(__GNUG__) && __GNUC__ == 2 && __GNUC_MINOR__ >= 95
28 // this is now here and in lyxgluelength.C
30 int const num_units = LyXLength::UNIT_NONE;
32 // I am not sure if "mu" should be possible to select (Lgb)
33 char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
34 "mm", "pc", "cc", "cm",
35 "in", "ex", "em", "mu",
36 "%", "c%", "p%", "l%" };
39 LyXLength::UNIT unitFromString(string const & data)
42 while (i < num_units && data != unit_name[i])
44 return static_cast<LyXLength::UNIT>(i);
50 LyXLength::LyXLength()
51 : val_(0), unit_(LyXLength::PT)
55 LyXLength::LyXLength(double v, LyXLength::UNIT u)
60 LyXLength::LyXLength(string const & data)
64 if (!isValidLength (data, &tmp))
65 return; // should raise an exception
72 string const LyXLength::asString() const
75 buffer << val_ << unit_name[unit_]; // setw?
76 return buffer.str().c_str();
80 string const LyXLength::asLatexString() const
86 buffer << abs(static_cast<int>(val_/100)) << "."
87 << abs(static_cast<int>(val_)%100) << "\\columnwidth";
90 buffer << abs(static_cast<int>(val_/100)) << "."
91 << abs(static_cast<int>(val_)%100) << "\\pagewidth";
94 buffer << abs(static_cast<int>(val_/100)) << "."
95 << abs(static_cast<int>(val_)%100) << "\\linewidth";
98 buffer << val_ << unit_name[unit_]; // setw?
101 return buffer.str().c_str();
105 double LyXLength::value() const
111 LyXLength::UNIT LyXLength::unit() const
117 void LyXLength::value(double v)
123 void LyXLength::unit(LyXLength::UNIT u)
129 bool operator==(LyXLength const & l1, LyXLength const & l2)
131 return l1.value() == l2.value() && l1.unit() == l2.unit();