2002-02-26 10:50:48 +00:00
|
|
|
/**
|
|
|
|
* \file vspace.C
|
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-11-30 14:57:15 +00:00
|
|
|
*
|
2002-02-26 10:50:48 +00:00
|
|
|
* \author Matthias Ettrich
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-02-26 10:50:48 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-12-02 16:39:57 +00:00
|
|
|
#include "vspace.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "bufferparams.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "BufferView.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "lengthcommon.h"
|
2003-02-14 00:41:44 +00:00
|
|
|
#include "lyxtext.h"
|
2001-12-02 16:39:57 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
/// used to return numeric values in parsing vspace
|
|
|
|
double number[4] = { 0, 0, 0, 0 };
|
|
|
|
/// used to return unit types in parsing vspace
|
|
|
|
LyXLength::UNIT unit[4] = { LyXLength::UNIT_NONE,
|
|
|
|
LyXLength::UNIT_NONE,
|
|
|
|
LyXLength::UNIT_NONE,
|
|
|
|
LyXLength::UNIT_NONE };
|
2001-12-02 23:47:06 +00:00
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
/// the current position in the number array
|
2001-12-02 23:47:06 +00:00
|
|
|
int number_index;
|
2002-02-26 10:50:48 +00:00
|
|
|
/// the current position in the unit array
|
2001-12-02 23:47:06 +00:00
|
|
|
int unit_index;
|
2000-03-08 01:45:25 +00:00
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
/// skip n characters of input
|
2001-03-20 01:22:46 +00:00
|
|
|
inline
|
2001-10-01 15:31:59 +00:00
|
|
|
void lyx_advance(string & data, string::size_type n)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
data.erase(0, n);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
/// return true when the input is at the end
|
2001-03-20 01:22:46 +00:00
|
|
|
inline
|
2000-09-14 17:53:12 +00:00
|
|
|
bool isEndOfData(string const & data)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-07-28 22:50:13 +00:00
|
|
|
return ltrim(data).empty();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
/**
|
|
|
|
* nextToken - return the next token in the input
|
|
|
|
* @param data input string
|
|
|
|
* @return a char representing the type of token returned
|
|
|
|
*
|
2002-03-21 17:27:08 +00:00
|
|
|
* The possible return values are :
|
|
|
|
* + stretch indicator for glue length
|
2002-02-26 10:50:48 +00:00
|
|
|
* - shrink indicator for glue length
|
|
|
|
* n a numeric value (stored in number array)
|
|
|
|
* u a unit type (stored in unit array)
|
|
|
|
* E parse error
|
|
|
|
*/
|
2000-09-14 17:53:12 +00:00
|
|
|
char nextToken(string & data)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-07-28 22:50:13 +00:00
|
|
|
data = ltrim(data);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (data.empty())
|
|
|
|
return '\0';
|
|
|
|
else if (data[0] == '+') {
|
2000-09-14 17:53:12 +00:00
|
|
|
lyx_advance(data, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
return '+';
|
2000-09-14 17:53:12 +00:00
|
|
|
} else if (prefixIs(data, "plus")) {
|
|
|
|
lyx_advance(data, 4);
|
1999-09-27 18:44:28 +00:00
|
|
|
return '+';
|
2000-09-14 17:53:12 +00:00
|
|
|
} else if (data[0] == '-') {
|
|
|
|
lyx_advance(data, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
return '-';
|
2000-09-14 17:53:12 +00:00
|
|
|
} else if (prefixIs(data, "minus")) {
|
|
|
|
lyx_advance(data, 5);
|
1999-09-27 18:44:28 +00:00
|
|
|
return '-';
|
2000-09-14 17:53:12 +00:00
|
|
|
} else {
|
2000-11-17 10:15:35 +00:00
|
|
|
string::size_type i = data.find_first_not_of("0123456789.");
|
|
|
|
|
|
|
|
if (i != 0) {
|
|
|
|
if (number_index > 3) return 'E';
|
|
|
|
|
|
|
|
string buffer;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-11-17 10:15:35 +00:00
|
|
|
// we have found some number
|
|
|
|
if (i == string::npos) {
|
|
|
|
buffer = data;
|
|
|
|
i = data.size() + 1;
|
|
|
|
} else
|
|
|
|
buffer = data.substr(0, i);
|
|
|
|
|
|
|
|
lyx_advance(data, i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-09-26 13:10:34 +00:00
|
|
|
if (isStrDbl(buffer)) {
|
|
|
|
number[number_index] = strToDbl(buffer);
|
1999-10-02 16:21:10 +00:00
|
|
|
++number_index;
|
1999-09-27 18:44:28 +00:00
|
|
|
return 'n';
|
2000-11-17 10:15:35 +00:00
|
|
|
} else return 'E';
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-03-29 15:00:20 +00:00
|
|
|
i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz%");
|
2000-11-17 10:15:35 +00:00
|
|
|
if (i != 0) {
|
|
|
|
if (unit_index > 3) return 'E';
|
|
|
|
|
|
|
|
string buffer;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-11-17 10:15:35 +00:00
|
|
|
// we have found some alphabetical string
|
|
|
|
if (i == string::npos) {
|
|
|
|
buffer = data;
|
|
|
|
i = data.size() + 1;
|
|
|
|
} else
|
|
|
|
buffer = data.substr(0, i);
|
|
|
|
|
|
|
|
// possibly we have "mmplus" string or similar
|
|
|
|
if (buffer.size() > 5 && (buffer.substr(2,4) == string("plus") || buffer.substr(2,5) == string("minus"))) {
|
|
|
|
lyx_advance(data, 2);
|
|
|
|
unit[unit_index] = unitFromString(buffer.substr(0, 2));
|
|
|
|
} else {
|
|
|
|
lyx_advance(data, i);
|
|
|
|
unit[unit_index] = unitFromString(buffer);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (unit[unit_index] != LyXLength::UNIT_NONE) {
|
1999-10-02 16:21:10 +00:00
|
|
|
++unit_index;
|
1999-09-27 18:44:28 +00:00
|
|
|
return 'u';
|
2000-11-17 10:15:35 +00:00
|
|
|
} else return 'E'; // Error
|
|
|
|
}
|
|
|
|
return 'E'; // Error
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-08 01:45:25 +00:00
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
/// latex representation of a vspace
|
2000-03-08 01:45:25 +00:00
|
|
|
struct LaTeXLength {
|
1999-10-02 16:21:10 +00:00
|
|
|
char const * pattern;
|
2001-11-30 14:57:15 +00:00
|
|
|
int plus_val_index;
|
|
|
|
int minus_val_index;
|
|
|
|
int plus_uni_index;
|
|
|
|
int minus_uni_index;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2000-03-08 01:45:25 +00:00
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
/// the possible formats for a vspace string
|
2000-03-08 01:45:25 +00:00
|
|
|
LaTeXLength table[] = {
|
|
|
|
{ "nu", 0, 0, 0, 0 },
|
|
|
|
{ "nu+nu", 2, 0, 2, 0 },
|
|
|
|
{ "nu+nu-nu", 2, 3, 2, 3 },
|
|
|
|
{ "nu+-nu", 2, 2, 2, 2 },
|
|
|
|
{ "nu-nu", 0, 2, 0, 2 },
|
|
|
|
{ "nu-nu+nu", 3, 2, 3, 2 },
|
|
|
|
{ "nu-+nu", 2, 2, 2, 2 },
|
|
|
|
{ "n+nu", 2, 0, 1, 0 },
|
|
|
|
{ "n+n-nu", 2, 3, 1, 1 },
|
|
|
|
{ "n+-nu", 2, 2, 1, 1 },
|
|
|
|
{ "n-nu", 0, 2, 0, 1 },
|
|
|
|
{ "n-n+nu", 3, 2, 1, 1 },
|
|
|
|
{ "n-+nu", 2, 2, 1, 1 },
|
|
|
|
{ "", 0, 0, 0, 0 } // sentinel, must be empty
|
|
|
|
};
|
|
|
|
|
2001-12-02 23:47:06 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2001-03-29 15:00:20 +00:00
|
|
|
const char * stringFromUnit(int unit)
|
|
|
|
{
|
2001-11-30 14:57:15 +00:00
|
|
|
if (unit < 0 || unit >= num_units)
|
|
|
|
return 0;
|
|
|
|
return unit_name[unit];
|
2001-03-29 15:00:20 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
bool isValidGlueLength(string const & data, LyXGlueLength * result)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// This parser is table-driven. First, it constructs a "pattern"
|
2001-11-30 14:57:15 +00:00
|
|
|
// that describes the sequence of tokens in "data". For example,
|
1999-09-27 18:44:28 +00:00
|
|
|
// "n-nu" means: number, minus sign, number, unit. As we go along,
|
2001-11-30 14:57:15 +00:00
|
|
|
// numbers and units are stored into static arrays. Then, "pattern"
|
|
|
|
// is searched in the "table". If it is found, the associated
|
|
|
|
// table entries tell us which number and unit should go where
|
|
|
|
// in the LyXLength structure. Example: if "data" has the "pattern"
|
|
|
|
// "nu+nu-nu", the associated table entries are "2, 3, 2, 3".
|
1999-09-27 18:44:28 +00:00
|
|
|
// That means, "plus_val" is the second number that was seen
|
|
|
|
// in the input, "minus_val" is the third number, and "plus_uni"
|
|
|
|
// and "minus_uni" are the second and third units, respectively.
|
|
|
|
// ("val" and "uni" are always the first items seen in "data".)
|
2001-11-30 14:57:15 +00:00
|
|
|
// This is the most elegant solution I could find -- a straight-
|
|
|
|
// forward approach leads to very long, tedious code that would be
|
|
|
|
// much harder to understand and maintain. (AS)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
if (data.empty())
|
|
|
|
return true;
|
2002-07-28 22:50:13 +00:00
|
|
|
string buffer = ltrim(data);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// To make isValidGlueLength recognize negative values as
|
|
|
|
// the first number this little hack is needed:
|
2001-11-26 11:08:43 +00:00
|
|
|
int val_sign = 1; // positive as default
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (buffer[0]) {
|
1999-09-27 18:44:28 +00:00
|
|
|
case '-':
|
1999-11-04 01:40:20 +00:00
|
|
|
lyx_advance(buffer, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
val_sign = -1;
|
|
|
|
break;
|
|
|
|
case '+':
|
1999-11-04 01:40:20 +00:00
|
|
|
lyx_advance(buffer, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
// fall through
|
|
|
|
default:
|
|
|
|
// no action
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// end of hack
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
int pattern_index = 0;
|
|
|
|
int table_index = 0;
|
|
|
|
char pattern[20];
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
number_index = 1;
|
|
|
|
unit_index = 1; // entries at index 0 are sentinels
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// construct "pattern" from "data"
|
|
|
|
while (!isEndOfData (buffer)) {
|
|
|
|
if (pattern_index > 20) return false;
|
|
|
|
pattern[pattern_index] = nextToken (buffer);
|
|
|
|
if (pattern[pattern_index] == 'E') return false;
|
1999-10-02 16:21:10 +00:00
|
|
|
++pattern_index;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
pattern[pattern_index] = '\0';
|
|
|
|
|
|
|
|
// search "pattern" in "table"
|
|
|
|
table_index = 0;
|
1999-10-02 16:21:10 +00:00
|
|
|
while (compare(pattern, table[table_index].pattern)) {
|
|
|
|
++table_index;
|
2001-11-30 14:57:15 +00:00
|
|
|
if (!*table[table_index].pattern)
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Get the values from the appropriate places. If an index
|
|
|
|
// is zero, the corresponding array value is zero or UNIT_NONE,
|
|
|
|
// so we needn't check this.
|
|
|
|
if (result) {
|
2001-12-02 23:47:06 +00:00
|
|
|
result->len_.value (number[1] * val_sign);
|
|
|
|
result->len_.unit (unit[1]);
|
|
|
|
result->plus_.value (number[table[table_index].plus_val_index]);
|
|
|
|
result->plus_.unit (unit [table[table_index].plus_uni_index]);
|
|
|
|
result->minus_.value(number[table[table_index].minus_val_index]);
|
|
|
|
result->minus_.unit (unit [table[table_index].minus_uni_index]);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
bool isValidLength(string const & data, LyXLength * result)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-02-26 10:50:48 +00:00
|
|
|
// This is a trimmed down version of isValidGlueLength.
|
|
|
|
// The parser may seem overkill for lengths without
|
|
|
|
// glue, but since we already have it, using it is
|
|
|
|
// easier than writing something from scratch.
|
2001-01-26 17:24:09 +00:00
|
|
|
if (data.empty())
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
string buffer = data;
|
|
|
|
int pattern_index = 0;
|
|
|
|
char pattern[3];
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// To make isValidLength recognize negative values
|
|
|
|
// this little hack is needed:
|
2001-11-26 11:08:43 +00:00
|
|
|
int val_sign = 1; // positive as default
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (buffer[0]) {
|
1999-09-27 18:44:28 +00:00
|
|
|
case '-':
|
1999-11-04 01:40:20 +00:00
|
|
|
lyx_advance(buffer, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
val_sign = -1;
|
|
|
|
break;
|
|
|
|
case '+':
|
1999-11-04 01:40:20 +00:00
|
|
|
lyx_advance(buffer, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
// fall through
|
|
|
|
default:
|
|
|
|
// no action
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// end of hack
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
number_index = unit_index = 1; // entries at index 0 are sentinels
|
|
|
|
|
|
|
|
// construct "pattern" from "data"
|
|
|
|
while (!isEndOfData (buffer)) {
|
2001-11-30 14:57:15 +00:00
|
|
|
if (pattern_index > 2)
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
pattern[pattern_index] = nextToken (buffer);
|
2001-11-30 14:57:15 +00:00
|
|
|
if (pattern[pattern_index] == 'E')
|
|
|
|
return false;
|
1999-10-02 16:21:10 +00:00
|
|
|
++pattern_index;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
pattern[pattern_index] = '\0';
|
|
|
|
|
|
|
|
// only the most basic pattern is accepted here
|
2002-03-21 17:27:08 +00:00
|
|
|
if (compare(pattern, "nu") != 0) return false;
|
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
// It _was_ a correct length string.
|
1999-09-27 18:44:28 +00:00
|
|
|
// Store away the values we found.
|
|
|
|
if (result) {
|
2001-11-30 14:57:15 +00:00
|
|
|
result->val_ = number[1] * val_sign;
|
|
|
|
result->unit_ = unit[1];
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-03-08 01:45:25 +00:00
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
//
|
|
|
|
// VSpace class
|
|
|
|
//
|
|
|
|
|
|
|
|
VSpace::VSpace()
|
2001-12-02 23:47:06 +00:00
|
|
|
: kind_(NONE), len_(), keep_(false)
|
2001-11-30 14:57:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
VSpace::VSpace(vspace_kind k)
|
2001-12-02 23:47:06 +00:00
|
|
|
: kind_(k), len_(), keep_(false)
|
2001-11-30 14:57:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-12-02 23:47:06 +00:00
|
|
|
VSpace::VSpace(LyXLength const & l)
|
2001-11-30 14:57:15 +00:00
|
|
|
: kind_(LENGTH), len_(l), keep_(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-12-02 23:47:06 +00:00
|
|
|
VSpace::VSpace(LyXGlueLength const & l)
|
|
|
|
: kind_(LENGTH), len_(l), keep_(false)
|
2001-11-30 14:57:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
VSpace::VSpace(string const & data)
|
2001-12-02 23:47:06 +00:00
|
|
|
: kind_(NONE), len_(), keep_(false)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
if (data.empty())
|
|
|
|
return;
|
2001-11-30 14:57:15 +00:00
|
|
|
double value;
|
2002-07-28 22:50:13 +00:00
|
|
|
string input = rtrim(data);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-10-01 15:31:59 +00:00
|
|
|
string::size_type const length = input.length();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-08-23 11:47:03 +00:00
|
|
|
if (length > 1 && input[length - 1] == '*') {
|
2001-11-30 14:57:15 +00:00
|
|
|
keep_ = true;
|
1999-10-02 16:21:10 +00:00
|
|
|
input.erase(length - 1);
|
|
|
|
}
|
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
if (prefixIs (input, "defskip")) kind_ = DEFSKIP;
|
|
|
|
else if (prefixIs (input, "smallskip")) kind_ = SMALLSKIP;
|
|
|
|
else if (prefixIs (input, "medskip")) kind_ = MEDSKIP;
|
|
|
|
else if (prefixIs (input, "bigskip")) kind_ = BIGSKIP;
|
|
|
|
else if (prefixIs (input, "vfill")) kind_ = VFILL;
|
|
|
|
else if (isValidGlueLength(input, &len_)) kind_ = LENGTH;
|
2003-09-05 22:17:02 +00:00
|
|
|
else if (isStrDbl(input)) {
|
|
|
|
value = strToDbl(input);
|
1999-09-27 18:44:28 +00:00
|
|
|
// This last one is for reading old .lyx files
|
|
|
|
// without units in added_space_top/bottom.
|
|
|
|
// Let unit default to centimeters here.
|
2001-11-30 14:57:15 +00:00
|
|
|
kind_ = LENGTH;
|
2001-12-02 23:47:06 +00:00
|
|
|
len_ = LyXGlueLength(LyXLength(value, LyXLength::CM));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
VSpace::vspace_kind VSpace::kind() const
|
|
|
|
{
|
|
|
|
return kind_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-07 01:45:40 +00:00
|
|
|
LyXGlueLength const & VSpace::length() const
|
2001-11-30 14:57:15 +00:00
|
|
|
{
|
|
|
|
return len_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool VSpace::keep() const
|
|
|
|
{
|
|
|
|
return keep_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VSpace::setKeep(bool val)
|
|
|
|
{
|
|
|
|
keep_ = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
bool VSpace::operator==(VSpace const & other) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-11-30 14:57:15 +00:00
|
|
|
if (kind_ != other.kind_)
|
2001-02-12 14:09:09 +00:00
|
|
|
return false;
|
2001-11-30 14:57:15 +00:00
|
|
|
|
|
|
|
if (kind_ != LENGTH)
|
|
|
|
return this->keep_ == other.keep_;
|
|
|
|
|
|
|
|
if (len_ != other.len_)
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
2001-11-30 14:57:15 +00:00
|
|
|
|
|
|
|
return keep_ == other.keep_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const VSpace::asLyXCommand() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-11-30 14:57:15 +00:00
|
|
|
string result;
|
|
|
|
switch (kind_) {
|
1999-09-27 18:44:28 +00:00
|
|
|
case NONE: break;
|
|
|
|
case DEFSKIP: result = "defskip"; break;
|
|
|
|
case SMALLSKIP: result = "smallskip"; break;
|
|
|
|
case MEDSKIP: result = "medskip"; break;
|
|
|
|
case BIGSKIP: result = "bigskip"; break;
|
|
|
|
case VFILL: result = "vfill"; break;
|
2001-11-30 14:57:15 +00:00
|
|
|
case LENGTH: result = len_.asString(); break;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-11-30 14:57:15 +00:00
|
|
|
if (keep_ && kind_ != NONE && kind_ != DEFSKIP)
|
|
|
|
result += '*';
|
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const VSpace::asLatexCommand(BufferParams const & params) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-03-01 12:39:22 +00:00
|
|
|
string ret;
|
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
switch (kind_) {
|
2002-03-01 12:39:22 +00:00
|
|
|
case NONE:
|
|
|
|
break;
|
2001-11-30 14:57:15 +00:00
|
|
|
case DEFSKIP:
|
2002-03-01 12:39:22 +00:00
|
|
|
ret = params.getDefSkip().asLatexCommand(params);
|
|
|
|
break;
|
|
|
|
case SMALLSKIP:
|
|
|
|
ret = keep_ ? "\\vspace*{\\smallskipamount}"
|
|
|
|
: "\\smallskip{}";
|
|
|
|
break;
|
|
|
|
case MEDSKIP:
|
|
|
|
ret = keep_ ? "\\vspace*{\\medskipamount}"
|
|
|
|
: "\\medskip{}";
|
|
|
|
break;
|
|
|
|
case BIGSKIP:
|
|
|
|
ret = keep_ ? "\\vspace*{\\bigskipamount}"
|
|
|
|
: "\\bigskip{}";
|
|
|
|
break;
|
|
|
|
case VFILL:
|
|
|
|
ret = keep_ ? "\\vspace*{\\fill}"
|
|
|
|
: "\\vfill{}";
|
|
|
|
break;
|
|
|
|
case LENGTH:
|
2002-03-02 13:21:31 +00:00
|
|
|
{
|
|
|
|
string const lenstr = len_.asLatexString();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-03-02 13:21:31 +00:00
|
|
|
ret = keep_ ? "\\vspace*{" + lenstr + '}'
|
|
|
|
: "\\vspace{" + lenstr + '}';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-03-01 12:39:22 +00:00
|
|
|
return ret;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-01 12:39:22 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
int VSpace::inPixels(BufferView const & bv) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// Height of a normal line in pixels (zoom factor considered)
|
2003-02-14 00:41:44 +00:00
|
|
|
int const default_height = defaultRowHeight(); // [pixels]
|
2001-03-29 15:00:20 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
int retval = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
switch (kind_) {
|
2002-08-29 13:05:55 +00:00
|
|
|
|
2001-11-30 14:57:15 +00:00
|
|
|
case NONE:
|
2002-08-29 13:05:55 +00:00
|
|
|
// value for this is already set
|
2002-02-16 15:59:55 +00:00
|
|
|
break;
|
2002-08-29 13:05:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
case DEFSKIP:
|
2003-09-09 09:47:59 +00:00
|
|
|
retval = bv.buffer()->params().getDefSkip().inPixels(bv);
|
2002-02-16 15:59:55 +00:00
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
// This is how the skips are normally defined by LateX.
|
2002-08-29 13:05:55 +00:00
|
|
|
// But there should be some way to change this per document.
|
2002-01-19 17:05:24 +00:00
|
|
|
case SMALLSKIP:
|
2002-02-16 15:59:55 +00:00
|
|
|
retval = default_height / 4;
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-19 17:05:24 +00:00
|
|
|
case MEDSKIP:
|
2002-02-16 15:59:55 +00:00
|
|
|
retval = default_height / 2;
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-19 17:05:24 +00:00
|
|
|
case BIGSKIP:
|
2002-02-16 15:59:55 +00:00
|
|
|
retval = default_height;
|
|
|
|
break;
|
2002-01-19 17:05:24 +00:00
|
|
|
|
|
|
|
case VFILL:
|
1999-12-16 06:43:25 +00:00
|
|
|
// leave space for the vfill symbol
|
2002-02-16 15:59:55 +00:00
|
|
|
retval = 3 * default_height;
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-08-29 13:05:55 +00:00
|
|
|
case LENGTH:
|
2003-02-26 17:04:10 +00:00
|
|
|
retval = len_.len().inPixels(bv.workWidth());
|
2002-02-16 15:59:55 +00:00
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
}
|
|
|
|
return retval;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|