1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2000-02-22 00:36:17 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#ifndef VSPACE_H
|
|
|
|
#define VSPACE_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
#include "LString.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
class BufferParams;
|
|
|
|
class BufferView;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// LyXLength Class
|
|
|
|
class LyXLength {
|
|
|
|
public:
|
|
|
|
/// length units
|
|
|
|
enum UNIT {
|
|
|
|
/// Scaled point (65536sp = 1pt) TeX's smallest unit.
|
|
|
|
SP,
|
|
|
|
/// Point = 1/72.27in = 0.351mm
|
|
|
|
PT,
|
|
|
|
/// Big point (72bp = 1in), also PostScript point
|
|
|
|
BP,
|
|
|
|
/// Didot point = 1/72 of a French inch, = 0.376mm
|
|
|
|
DD,
|
|
|
|
/// Millimeter = 2.845pt
|
|
|
|
MM,
|
|
|
|
/// Pica = 12pt = 4.218mm
|
|
|
|
PC,
|
|
|
|
/// Cicero = 12dd = 4.531mm
|
|
|
|
CC,
|
|
|
|
/// Centimeter = 10mm = 2.371pc
|
|
|
|
CM,
|
|
|
|
/// Inch = 25.4mm = 72.27pt = 6.022pc
|
|
|
|
IN,
|
|
|
|
/// Height of a small "x" for the current font.
|
|
|
|
EX,
|
|
|
|
/// Width of capital "M" in current font.
|
|
|
|
EM,
|
|
|
|
/// Math unit (18mu = 1em) for positioning in math mode
|
|
|
|
MU,
|
2001-03-29 15:00:20 +00:00
|
|
|
/// Percent of columnwidth both "%" or "%c"
|
|
|
|
PW,
|
|
|
|
PE,
|
|
|
|
/// Percent of pagewidth
|
|
|
|
PP,
|
|
|
|
/// Percent of linewidth
|
|
|
|
PL,
|
1999-09-27 18:44:28 +00:00
|
|
|
/// no unit
|
|
|
|
UNIT_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
LyXLength() : val(0), uni(LyXLength::PT) {}
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/** "data" must be a decimal number, followed by a unit. */
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
1999-10-02 16:21:10 +00:00
|
|
|
LyXLength(string const & data);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
float value() const { return val; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXLength::UNIT unit() const { return uni; }
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// conversion
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const asString() const;
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2001-03-29 15:00:20 +00:00
|
|
|
virtual string const asLatexString() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/** If "data" is valid, the length represented by it is
|
1999-10-02 16:21:10 +00:00
|
|
|
stored into "result", if that is not 0. */
|
|
|
|
friend bool isValidLength(string const & data,
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXLength * result = 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
protected:
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
float val;
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
LyXLength::UNIT uni;
|
|
|
|
};
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-05-19 19:46:23 +00:00
|
|
|
inline
|
|
|
|
bool operator==(LyXLength const & l1, LyXLength const & l2)
|
|
|
|
{
|
|
|
|
return l1.value() == l2.value()
|
|
|
|
&& l1.unit() == l2.unit();
|
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
extern LyXLength::UNIT unitFromString (string const & data);
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
extern bool isValidLength(string const & data, LyXLength * result);
|
2001-03-29 15:00:20 +00:00
|
|
|
///
|
|
|
|
extern const char * stringFromUnit(int unit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// LyXGlueLength class
|
|
|
|
class LyXGlueLength : public LyXLength {
|
|
|
|
public:
|
|
|
|
///
|
2000-04-08 17:02:02 +00:00
|
|
|
LyXGlueLength(float v,
|
|
|
|
LyXLength::UNIT u,
|
|
|
|
float pv = 0.0,
|
|
|
|
LyXLength::UNIT pu = LyXLength::UNIT_NONE,
|
|
|
|
float mv = 0.0,
|
|
|
|
LyXLength::UNIT mu = LyXLength::UNIT_NONE)
|
1999-09-27 18:44:28 +00:00
|
|
|
: LyXLength (v, u),
|
|
|
|
plus_val(pv), minus_val(mv),
|
1999-10-02 16:21:10 +00:00
|
|
|
plus_uni(pu), minus_uni(mu) {}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/** "data" must be a decimal number, followed by a unit, and
|
|
|
|
optional "glue" indicated by "+" and "-". You may abbreviate
|
|
|
|
reasonably. Examples:
|
|
|
|
1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm
|
|
|
|
The traditional Latex format is also accepted, like
|
|
|
|
4cm plus 10pt minus 10pt */
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
1999-10-02 16:21:10 +00:00
|
|
|
LyXGlueLength(string const & data);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
float plusValue() const { return plus_val; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXLength::UNIT plusUnit() const { return plus_uni; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
float minusValue() const { return minus_val; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXLength::UNIT minusUnit() const { return minus_uni; }
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// conversion
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const asString() const;
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const asLatexString() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** If "data" is valid, the length represented by it is
|
1999-10-02 16:21:10 +00:00
|
|
|
stored into "result", if that is not 0. */
|
|
|
|
friend bool isValidGlueLength(string const & data,
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXGlueLength* result = 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
protected:
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
float plus_val;
|
|
|
|
///
|
|
|
|
float minus_val;
|
|
|
|
///
|
|
|
|
LyXLength::UNIT plus_uni;
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXLength::UNIT minus_uni;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-05-19 19:46:23 +00:00
|
|
|
inline
|
|
|
|
bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
|
|
|
|
{
|
|
|
|
return l1.value() == l2.value()
|
|
|
|
&& l1.unit() == l2.unit()
|
|
|
|
&& l1.plusValue() == l2.plusValue()
|
|
|
|
&& l1.plusUnit() == l2.plusUnit()
|
|
|
|
&& l1.minusValue() == l2.minusValue()
|
|
|
|
&& l1.minusUnit() == l2.minusUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// VSpace class
|
|
|
|
class VSpace {
|
|
|
|
public:
|
2001-02-16 09:25:43 +00:00
|
|
|
/// The different kinds of spaces.
|
2000-08-07 20:58:24 +00:00
|
|
|
enum vspace_kind {
|
|
|
|
///
|
|
|
|
NONE,
|
|
|
|
///
|
|
|
|
DEFSKIP,
|
|
|
|
///
|
|
|
|
SMALLSKIP,
|
|
|
|
///
|
|
|
|
MEDSKIP,
|
|
|
|
///
|
|
|
|
BIGSKIP,
|
|
|
|
///
|
|
|
|
VFILL,
|
|
|
|
///
|
|
|
|
LENGTH
|
|
|
|
};
|
2001-02-16 09:25:43 +00:00
|
|
|
/// Constructor
|
1999-09-27 18:44:28 +00:00
|
|
|
VSpace() :
|
|
|
|
kin (NONE),
|
|
|
|
len(0.0, LyXLength::PT),
|
1999-10-02 16:21:10 +00:00
|
|
|
kp (false) {}
|
2001-02-16 09:25:43 +00:00
|
|
|
/// Constructor
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
2001-02-16 09:25:43 +00:00
|
|
|
VSpace(vspace_kind k) :
|
1999-09-27 18:44:28 +00:00
|
|
|
kin (k),
|
|
|
|
len (0.0, LyXLength::PT),
|
1999-10-02 16:21:10 +00:00
|
|
|
kp (false) {}
|
2001-02-16 09:25:43 +00:00
|
|
|
/// Constructor
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
1999-09-27 18:44:28 +00:00
|
|
|
VSpace(LyXGlueLength l) :
|
|
|
|
kin (LENGTH),
|
|
|
|
len (l),
|
1999-10-02 16:21:10 +00:00
|
|
|
kp (false) {}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
/// Constructor
|
2000-07-04 19:16:35 +00:00
|
|
|
explicit
|
1999-09-27 18:44:28 +00:00
|
|
|
VSpace(float v, LyXLength::UNIT u) :
|
|
|
|
kin (LENGTH),
|
|
|
|
len (v, u),
|
1999-10-02 16:21:10 +00:00
|
|
|
kp (false) {}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
/// Constructor for reading from a .lyx file
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit
|
1999-10-02 16:21:10 +00:00
|
|
|
VSpace(string const & data);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
/// access functions
|
|
|
|
vspace_kind kind() const { return kin; }
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-12-04 17:18:01 +00:00
|
|
|
LyXGlueLength length() const { return len; }
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// a flag that switches between \vspace and \vspace*
|
|
|
|
bool keep() const { return kp; }
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
void setKeep(bool val) { kp = val; }
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
bool operator==(VSpace const &) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// conversion
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
string const asLyXCommand() const; // how it goes into the LyX file
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
string const asLatexCommand(BufferParams const & params) const;
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-02-22 00:36:17 +00:00
|
|
|
int inPixels(BufferView * bv) const;
|
2000-05-15 14:49:36 +00:00
|
|
|
///
|
2001-03-29 15:00:20 +00:00
|
|
|
int inPixels(int default_height, int default_skip, int default_width=0) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
private:
|
2001-02-16 09:25:43 +00:00
|
|
|
/// This VSpace kind
|
2000-09-14 17:53:12 +00:00
|
|
|
vspace_kind kin;
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXGlueLength len;
|
1999-10-02 16:21:10 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
bool kp;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|