2001-12-02 23:47:06 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lyxlength.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
#include "lengthcommon.h"
|
2001-12-02 23:47:06 +00:00
|
|
|
|
|
|
|
#include "Lsstream.h"
|
|
|
|
|
2001-12-05 01:05:38 +00:00
|
|
|
#include <cstdlib>
|
2001-12-03 13:17:04 +00:00
|
|
|
|
2001-12-02 23:47:06 +00:00
|
|
|
|
|
|
|
LyXLength::LyXLength()
|
|
|
|
: val_(0), unit_(LyXLength::PT)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
LyXLength::LyXLength(double v, LyXLength::UNIT u)
|
|
|
|
: val_(v), unit_(u)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
LyXLength::LyXLength(string const & data)
|
|
|
|
{
|
|
|
|
LyXLength tmp;
|
|
|
|
|
|
|
|
if (!isValidLength (data, &tmp))
|
|
|
|
return; // should raise an exception
|
|
|
|
|
|
|
|
val_ = tmp.val_;
|
|
|
|
unit_ = tmp.unit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const LyXLength::asString() const
|
|
|
|
{
|
|
|
|
ostringstream buffer;
|
|
|
|
buffer << val_ << unit_name[unit_]; // setw?
|
|
|
|
return buffer.str().c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const LyXLength::asLatexString() const
|
|
|
|
{
|
|
|
|
ostringstream buffer;
|
|
|
|
switch(unit_) {
|
|
|
|
case PW:
|
|
|
|
case PE:
|
|
|
|
buffer << abs(static_cast<int>(val_/100)) << "."
|
2001-12-04 16:32:15 +00:00
|
|
|
<< abs(static_cast<int>(val_)%100) << "\\columnwidth";
|
2001-12-02 23:47:06 +00:00
|
|
|
break;
|
|
|
|
case PP:
|
|
|
|
buffer << abs(static_cast<int>(val_/100)) << "."
|
2001-12-04 16:32:15 +00:00
|
|
|
<< abs(static_cast<int>(val_)%100) << "\\pagewidth";
|
2001-12-02 23:47:06 +00:00
|
|
|
break;
|
|
|
|
case PL:
|
|
|
|
buffer << abs(static_cast<int>(val_/100)) << "."
|
2001-12-04 16:32:15 +00:00
|
|
|
<< abs(static_cast<int>(val_)%100) << "\\linewidth";
|
2001-12-02 23:47:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
buffer << val_ << unit_name[unit_]; // setw?
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return buffer.str().c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double LyXLength::value() const
|
|
|
|
{
|
|
|
|
return val_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXLength::UNIT LyXLength::unit() const
|
|
|
|
{
|
|
|
|
return unit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXLength::value(double v)
|
|
|
|
{
|
|
|
|
val_ = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXLength::unit(LyXLength::UNIT u)
|
|
|
|
{
|
|
|
|
unit_ = u;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
bool LyXLength::zero() const
|
|
|
|
{
|
|
|
|
return val_ == 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-02 23:47:06 +00:00
|
|
|
bool operator==(LyXLength const & l1, LyXLength const & l2)
|
|
|
|
{
|
|
|
|
return l1.value() == l2.value() && l1.unit() == l2.unit();
|
|
|
|
}
|