2003-08-23 00:17:00 +00:00
|
|
|
/**
|
2007-04-28 12:58:49 +00:00
|
|
|
* \file Length.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-12-02 23:47:06 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Matthias Ettrich
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author John Levon
|
|
|
|
* \author Dekel Tsur
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
2001-12-02 23:47:06 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
#include "Length.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2015-03-26 15:55:19 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
|
|
|
#include "frontends/FontMetrics.h"
|
2001-12-02 23:47:06 +00:00
|
|
|
|
2006-10-21 19:40:29 +00:00
|
|
|
#include "support/docstream.h"
|
2015-05-14 10:10:42 +00:00
|
|
|
#include "support/lstrings.h"
|
2016-02-17 20:31:37 +00:00
|
|
|
#include "support/lyxlib.h"
|
2007-10-24 22:55:02 +00:00
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2004-11-04 14:44:35 +00:00
|
|
|
#include <iomanip>
|
2002-04-02 13:23:35 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2015-05-20 07:35:57 +00:00
|
|
|
using namespace lyx::support;
|
2001-12-02 23:47:06 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2001-12-02 23:47:06 +00:00
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Length
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Length::Length()
|
|
|
|
: val_(0), unit_(Length::UNIT_NONE)
|
2001-12-02 23:47:06 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
Length::Length(double v, Length::UNIT u)
|
2001-12-02 23:47:06 +00:00
|
|
|
: val_(v), unit_(u)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
Length::Length(string const & data)
|
|
|
|
: val_(0), unit_(Length::PT)
|
2001-12-02 23:47:06 +00:00
|
|
|
{
|
2007-04-28 12:58:49 +00:00
|
|
|
Length tmp;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-08-20 20:30:45 +00:00
|
|
|
if (!isValidLength(data, &tmp))
|
2001-12-02 23:47:06 +00:00
|
|
|
return; // should raise an exception
|
|
|
|
|
|
|
|
val_ = tmp.val_;
|
|
|
|
unit_ = tmp.unit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
string const Length::asString() const
|
2001-12-02 23:47:06 +00:00
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
ostringstream os;
|
2013-04-15 10:35:11 +00:00
|
|
|
if (unit_ != UNIT_NONE)
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_) << unit_name[unit_]; // setw?
|
2004-04-13 06:27:29 +00:00
|
|
|
return os.str();
|
2001-12-02 23:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
docstring const Length::asDocstring() const
|
2006-10-21 19:40:29 +00:00
|
|
|
{
|
|
|
|
odocstringstream os;
|
2013-04-15 10:35:11 +00:00
|
|
|
if (unit_ != UNIT_NONE)
|
2015-10-15 18:52:28 +00:00
|
|
|
os << from_ascii(formatFPNumber(val_))
|
|
|
|
<< from_ascii(unit_name[unit_]); // setw?
|
2006-10-21 19:40:29 +00:00
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
string const Length::asLatexString() const
|
2001-12-02 23:47:06 +00:00
|
|
|
{
|
2004-11-04 14:44:35 +00:00
|
|
|
ostringstream os;
|
2015-05-14 10:10:42 +00:00
|
|
|
// Do not allow scientific notation (e.g. 1.2e+03), since this is not valid
|
|
|
|
// LaTeX (bug 9416)
|
2002-02-16 15:59:55 +00:00
|
|
|
switch (unit_) {
|
2002-08-24 22:02:30 +00:00
|
|
|
case PTW:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_ / 100.0) << "\\textwidth";
|
2004-04-20 08:51:15 +00:00
|
|
|
break;
|
|
|
|
case PCW:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_ / 100.0) << "\\columnwidth";
|
2004-04-20 08:51:15 +00:00
|
|
|
break;
|
|
|
|
case PPW:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_ / 100.0) << "\\paperwidth";
|
2004-04-20 08:51:15 +00:00
|
|
|
break;
|
|
|
|
case PLW:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_ / 100.0) << "\\linewidth";
|
2004-04-20 08:51:15 +00:00
|
|
|
break;
|
|
|
|
case PTH:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_ / 100.0) << "\\textheight";
|
2004-04-13 06:27:29 +00:00
|
|
|
break;
|
2010-07-25 00:17:48 +00:00
|
|
|
case PPH:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_ / 100.0) << "\\paperheight";
|
2010-07-25 00:17:48 +00:00
|
|
|
break;
|
2013-04-15 10:35:11 +00:00
|
|
|
case UNIT_NONE:
|
2013-04-17 09:30:25 +00:00
|
|
|
break;
|
2001-12-02 23:47:06 +00:00
|
|
|
default:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_) << unit_name[unit_];
|
2004-04-13 06:27:29 +00:00
|
|
|
break;
|
2001-12-02 23:47:06 +00:00
|
|
|
}
|
2004-11-04 14:44:35 +00:00
|
|
|
return os.str();
|
2001-12-02 23:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-12 14:42:33 +00:00
|
|
|
string const Length::asHTMLString() const
|
|
|
|
{
|
|
|
|
ostringstream os;
|
|
|
|
switch (unit_) {
|
|
|
|
case PT:
|
|
|
|
case BP:
|
|
|
|
case DD:
|
|
|
|
// close enough
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_) << "pt";
|
2009-06-12 14:42:33 +00:00
|
|
|
break;
|
|
|
|
case MM:
|
|
|
|
case CM:
|
|
|
|
case PC:
|
|
|
|
case IN:
|
|
|
|
case EX:
|
|
|
|
case EM:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_) << unit_name[unit_];
|
2009-06-12 14:42:33 +00:00
|
|
|
break;
|
|
|
|
case CC:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_ / 12.0) << "pt";
|
2009-06-12 14:42:33 +00:00
|
|
|
break;
|
|
|
|
case MU:
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_ / 18.0) << "em";
|
2009-06-12 14:42:33 +00:00
|
|
|
break;
|
|
|
|
case PTW:
|
|
|
|
case PPW:
|
|
|
|
case PLW:
|
|
|
|
case PCW:
|
|
|
|
case PTH:
|
|
|
|
case PPH:
|
|
|
|
// what it's a percentage of probably won't make sense for HTML,
|
|
|
|
// so we'll assume people have chosen these appropriately
|
2015-05-20 07:35:57 +00:00
|
|
|
os << formatFPNumber(val_) << '%';
|
2009-06-12 14:42:33 +00:00
|
|
|
break;
|
|
|
|
case SP:
|
|
|
|
case UNIT_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
double Length::value() const
|
2001-12-02 23:47:06 +00:00
|
|
|
{
|
|
|
|
return val_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
Length::UNIT Length::unit() const
|
2001-12-02 23:47:06 +00:00
|
|
|
{
|
|
|
|
return unit_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
void Length::value(double v)
|
2001-12-02 23:47:06 +00:00
|
|
|
{
|
|
|
|
val_ = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
void Length::unit(Length::UNIT u)
|
2001-12-02 23:47:06 +00:00
|
|
|
{
|
|
|
|
unit_ = u;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
bool Length::zero() const
|
2001-12-05 08:04:20 +00:00
|
|
|
{
|
|
|
|
return val_ == 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
bool Length::empty() const
|
2002-12-04 02:57:14 +00:00
|
|
|
{
|
2007-04-28 12:58:49 +00:00
|
|
|
return unit_ == Length::UNIT_NONE;
|
2002-12-04 02:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
int Length::inPixels(int text_width, int em_width_base) const
|
2002-01-17 23:09:31 +00:00
|
|
|
{
|
|
|
|
// Zoom factor specified by user in percent
|
|
|
|
double const zoom = lyxrc.zoom / 100.0; // [percent]
|
|
|
|
|
|
|
|
// DPI setting for monitor: pixels/inch
|
|
|
|
double const dpi = lyxrc.dpi; // screen resolution [pixels/inch]
|
|
|
|
|
2015-07-12 16:36:19 +00:00
|
|
|
double const em_width_in = (em_width_base > 0)
|
|
|
|
? em_width_base / (zoom * dpi)
|
|
|
|
: 10.0/72.27;
|
2002-11-04 02:12:42 +00:00
|
|
|
// A different estimate for em_width is
|
2015-03-26 15:55:19 +00:00
|
|
|
// theFontMetrics(FontInfo(sane_font)).em()
|
2002-10-24 18:31:47 +00:00
|
|
|
// but this estimate might not be more accurate as the screen font
|
|
|
|
// is different then the latex font.
|
|
|
|
|
2002-01-17 23:09:31 +00:00
|
|
|
// Pixel values are scaled so that the ratio
|
|
|
|
// between lengths and font sizes on the screen
|
|
|
|
// is the same as on paper.
|
|
|
|
|
2015-07-12 16:36:19 +00:00
|
|
|
double const text_width_in = text_width / (zoom * dpi);
|
|
|
|
double const result = zoom * dpi * inInch(text_width_in, em_width_in);
|
2016-02-17 20:31:37 +00:00
|
|
|
return support::iround(result);
|
2015-07-12 16:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Length::inInch(double text_width, double em_width) const
|
|
|
|
{
|
2002-01-17 23:09:31 +00:00
|
|
|
double result = 0.0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-17 23:09:31 +00:00
|
|
|
switch (unit_) {
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::SP:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Scaled point: sp = 1/65536 pt
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_ / (72.27 * 65536); // 4736286.7
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::PT:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Point: 1 pt = 1/72.27 inch
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_ / 72.27; // 72.27
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::BP:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Big point: 1 bp = 1/72 inch
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_ / 72; // 72
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::DD:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Didot: 1157dd = 1238 pt?
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_ / (72.27 / (0.376 * 2.845)); // 67.559735
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::MM:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Millimeter: 1 mm = 1/25.4 inch
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_ / 25.4; // 25.4
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::PC:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Pica: 1 pc = 12 pt
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_ / (72.27 / 12); // 6.0225
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::CC:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Cicero: 1 cc = 12 dd
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_
|
2002-01-17 23:09:31 +00:00
|
|
|
/ (72.27 / (12 * 0.376 * 2.845)); // 5.6299779
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::CM:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Centimeter: 1 cm = 1/2.54 inch
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_ / 2.54; // 2.54
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::IN:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Inch
|
2015-07-12 16:36:19 +00:00
|
|
|
result = val_;
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::EX:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Ex: The height of an "x"
|
2002-10-17 13:15:25 +00:00
|
|
|
// 0.4305 is the ration between 1ex and 1em in cmr10
|
2002-10-24 18:31:47 +00:00
|
|
|
result = val_ * em_width * 0.4305;
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::EM:
|
2002-01-17 23:09:31 +00:00
|
|
|
// Em: The width of an "m"
|
2002-10-24 18:31:47 +00:00
|
|
|
result = val_ * em_width;
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::MU:
|
2002-10-17 13:15:25 +00:00
|
|
|
// math unit = 1/18em
|
2002-10-24 18:31:47 +00:00
|
|
|
result = val_ * em_width / 18;
|
2002-10-17 13:15:25 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::PCW: // Always % of workarea
|
|
|
|
case Length::PTW:
|
|
|
|
case Length::PLW:
|
2002-10-24 18:31:47 +00:00
|
|
|
result = val_ * text_width / 100;
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::PPW:
|
2002-10-24 18:31:47 +00:00
|
|
|
// paperwidth/textwidth is 1.7 for A4 paper with default margins
|
|
|
|
result = val_ * text_width * 1.7 / 100;
|
2002-01-17 23:09:31 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::PTH:
|
2002-10-24 18:31:47 +00:00
|
|
|
result = val_ * text_width * 1.787 / 100;
|
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::PPH:
|
2002-10-24 18:31:47 +00:00
|
|
|
result = val_ * text_width * 2.2 / 100;
|
2002-07-22 12:36:41 +00:00
|
|
|
break;
|
2007-04-28 12:58:49 +00:00
|
|
|
case Length::UNIT_NONE:
|
2002-01-17 23:09:31 +00:00
|
|
|
result = 0; // this cannot happen
|
|
|
|
break;
|
|
|
|
}
|
2015-07-12 16:36:19 +00:00
|
|
|
return result;
|
2002-01-17 23:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-26 15:55:19 +00:00
|
|
|
int Length::inPixels(MetricsBase const & base) const
|
|
|
|
{
|
2016-11-20 22:10:12 +00:00
|
|
|
FontInfo fi = base.font;
|
|
|
|
if (unit_ == Length::MU)
|
|
|
|
fi.setFamily(SYMBOL_FAMILY);
|
|
|
|
return inPixels(base.textwidth, theFontMetrics(fi).em());
|
2015-03-26 15:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
int Length::inBP() const
|
2002-04-11 18:36:18 +00:00
|
|
|
{
|
2007-04-28 12:58:49 +00:00
|
|
|
// return any Length value as a one with
|
2002-04-11 18:36:18 +00:00
|
|
|
// the PostScript point, called bp (big points)
|
2015-07-12 16:36:19 +00:00
|
|
|
|
|
|
|
double const text_width_in = 210.0 / 2.54; // assume A4
|
|
|
|
double const em_width_in = 10.0 / 72.27;
|
|
|
|
double result = 72.0 * inInch(text_width_in, em_width_in);
|
2016-02-17 20:31:37 +00:00
|
|
|
return support::iround(result);
|
2002-04-11 18:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-06 21:24:13 +00:00
|
|
|
Length::UNIT Length::defaultUnit()
|
|
|
|
{
|
2011-10-27 11:52:11 +00:00
|
|
|
return lyxrc.default_length_unit;
|
2009-02-06 21:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
bool operator==(Length const & l1, Length const & l2)
|
2001-12-02 23:47:06 +00:00
|
|
|
{
|
|
|
|
return l1.value() == l2.value() && l1.unit() == l2.unit();
|
|
|
|
}
|
2001-12-12 12:07:38 +00:00
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
bool operator!=(Length const & l1, Length const & l2)
|
|
|
|
{
|
|
|
|
return !(l1 == l2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GlueLength
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
GlueLength::GlueLength(Length const & len)
|
|
|
|
: len_(len)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
GlueLength::GlueLength(Length const & len, Length const & plus,
|
|
|
|
Length const & minus)
|
|
|
|
: len_(len), plus_(plus), minus_(minus)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
GlueLength::GlueLength(string const & data)
|
|
|
|
{
|
2016-06-12 02:38:57 +00:00
|
|
|
// false positive from coverity
|
|
|
|
// coverity[CHECKED_RETURN]
|
2007-04-28 12:58:49 +00:00
|
|
|
isValidGlueLength(data, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const GlueLength::asString() const
|
|
|
|
{
|
2013-04-15 10:35:11 +00:00
|
|
|
if (len_.empty())
|
|
|
|
return string();
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
ostringstream buffer;
|
|
|
|
|
2015-05-20 07:35:57 +00:00
|
|
|
buffer << formatFPNumber(len_.value());
|
2007-04-28 12:58:49 +00:00
|
|
|
|
|
|
|
if (plus_.zero() && minus_.zero()) {
|
|
|
|
buffer << unit_name[len_.unit()];
|
|
|
|
return buffer.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
// just len and plus
|
|
|
|
if (minus_.zero()) {
|
|
|
|
if (len_.unit() != plus_.unit())
|
|
|
|
buffer << unit_name[len_.unit()];
|
2015-05-20 07:35:57 +00:00
|
|
|
buffer << '+' << formatFPNumber(plus_.value());
|
2007-04-28 12:58:49 +00:00
|
|
|
buffer << unit_name[plus_.unit()];
|
|
|
|
return buffer.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
// just len and minus
|
|
|
|
if (plus_.zero()) {
|
|
|
|
if (len_.unit() != minus_.unit())
|
|
|
|
buffer << unit_name[len_.unit()];
|
2015-05-20 07:35:57 +00:00
|
|
|
buffer << '-' << formatFPNumber(minus_.value());
|
2007-04-28 12:58:49 +00:00
|
|
|
buffer << unit_name[minus_.unit()];
|
|
|
|
return buffer.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok, len, plus AND minus
|
|
|
|
|
|
|
|
// len+-
|
|
|
|
if (minus_ == plus_) {
|
|
|
|
if (len_.unit() != minus_.unit())
|
|
|
|
buffer << unit_name[len_.unit()];
|
2015-05-20 07:35:57 +00:00
|
|
|
buffer << "+-" << formatFPNumber(minus_.value());
|
2007-04-28 12:58:49 +00:00
|
|
|
buffer << unit_name[minus_.unit()];
|
|
|
|
return buffer.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is so rare a case, why bother minimising units ?
|
|
|
|
|
|
|
|
buffer << unit_name[len_.unit()];
|
2015-05-20 07:35:57 +00:00
|
|
|
buffer << '+' << formatFPNumber(plus_.value()) << unit_name[plus_.unit()];
|
|
|
|
buffer << '-' << formatFPNumber(minus_.value()) << unit_name[minus_.unit()];
|
2007-04-28 12:58:49 +00:00
|
|
|
|
|
|
|
return buffer.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const GlueLength::asLatexString() const
|
|
|
|
{
|
|
|
|
ostringstream buffer;
|
2009-07-19 20:01:39 +00:00
|
|
|
// use Length::asLatexString() to handle also the percent lengths
|
|
|
|
buffer << len_.Length::asLatexString();
|
2007-04-28 12:58:49 +00:00
|
|
|
if (!plus_.zero())
|
2009-07-19 20:01:39 +00:00
|
|
|
buffer << " plus " << plus_.Length::asLatexString();
|
2007-04-28 12:58:49 +00:00
|
|
|
if (!minus_.zero())
|
2009-07-19 20:01:39 +00:00
|
|
|
buffer << " minus " << minus_.Length::asLatexString();
|
2007-04-28 12:58:49 +00:00
|
|
|
return buffer.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Length const & GlueLength::len() const
|
|
|
|
{
|
|
|
|
return len_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Length const & GlueLength::plus() const
|
|
|
|
{
|
|
|
|
return plus_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Length const & GlueLength::minus() const
|
|
|
|
{
|
|
|
|
return minus_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(GlueLength const & l1, GlueLength const & l2)
|
|
|
|
{
|
|
|
|
return l1.len() == l2.len()
|
|
|
|
&& l1.plus() == l2.plus()
|
|
|
|
&& l1.minus() == l2.minus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(GlueLength const & l1, GlueLength const & l2)
|
2001-12-12 12:07:38 +00:00
|
|
|
{
|
|
|
|
return !(l1 == l2);
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|