2002-02-26 10:50:48 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file VSpace.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-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>
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "VSpace.h"
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "BufferView.h"
|
2005-05-24 10:23:30 +00:00
|
|
|
#include "gettext.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "lengthcommon.h"
|
2007-04-29 23:33:02 +00:00
|
|
|
#include "Text.h"
|
2001-12-02 16:39:57 +00:00
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
#include "support/convert.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using support::compare;
|
|
|
|
using support::isStrDbl;
|
|
|
|
using support::ltrim;
|
|
|
|
using support::prefixIs;
|
|
|
|
using support::rtrim;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
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
|
2007-04-28 12:58:49 +00:00
|
|
|
Length::UNIT unit[4] = { Length::UNIT_NONE,
|
|
|
|
Length::UNIT_NONE,
|
|
|
|
Length::UNIT_NONE,
|
|
|
|
Length::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
|
|
|
}
|
|
|
|
|
2003-11-13 13:43:44 +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
|
|
|
}
|
|
|
|
|
2003-11-13 13:43:44 +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);
|
2003-11-13 13:43:44 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (data.empty())
|
|
|
|
return '\0';
|
2003-11-13 13:43:44 +00:00
|
|
|
|
|
|
|
if (data[0] == '+') {
|
2000-09-14 17:53:12 +00:00
|
|
|
lyx_advance(data, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
return '+';
|
2003-11-13 13:43:44 +00:00
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
if (prefixIs(data, "plus")) {
|
2000-09-14 17:53:12 +00:00
|
|
|
lyx_advance(data, 4);
|
1999-09-27 18:44:28 +00:00
|
|
|
return '+';
|
2003-11-13 13:43:44 +00:00
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
if (data[0] == '-') {
|
2000-09-14 17:53:12 +00:00
|
|
|
lyx_advance(data, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
return '-';
|
2003-11-13 13:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prefixIs(data, "minus")) {
|
2000-09-14 17:53:12 +00:00
|
|
|
lyx_advance(data, 5);
|
1999-09-27 18:44:28 +00:00
|
|
|
return '-';
|
2003-11-13 13:43:44 +00:00
|
|
|
}
|
2000-11-17 10:15:35 +00:00
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
string::size_type i = data.find_first_not_of("0123456789.");
|
2000-11-17 10:15:35 +00:00
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
if (i != 0) {
|
|
|
|
if (number_index > 3)
|
|
|
|
return 'E';
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
string buffer;
|
2000-11-17 10:15:35 +00:00
|
|
|
|
2003-11-13 13:43:44 +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);
|
|
|
|
|
|
|
|
if (isStrDbl(buffer)) {
|
2005-01-27 21:05:44 +00:00
|
|
|
number[number_index] = convert<double>(buffer);
|
2003-11-13 13:43:44 +00:00
|
|
|
++number_index;
|
|
|
|
return 'n';
|
|
|
|
}
|
|
|
|
return 'E';
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz%");
|
|
|
|
if (i != 0) {
|
|
|
|
if (unit_index > 3)
|
|
|
|
return 'E';
|
|
|
|
|
|
|
|
string buffer;
|
|
|
|
|
|
|
|
// 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);
|
2000-11-17 10:15:35 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
if (unit[unit_index] != Length::UNIT_NONE) {
|
2003-11-13 13:43:44 +00:00
|
|
|
++unit_index;
|
|
|
|
return 'u';
|
2000-11-17 10:15:35 +00:00
|
|
|
}
|
|
|
|
return 'E'; // Error
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2003-11-13 13:43:44 +00:00
|
|
|
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)
|
|
|
|
{
|
2004-11-14 10:20:11 +00:00
|
|
|
if (unit < 0 || unit > num_units)
|
2001-11-30 14:57:15 +00:00
|
|
|
return 0;
|
|
|
|
return unit_name[unit];
|
2001-03-29 15:00:20 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
bool isValidGlueLength(string const & data, GlueLength * 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
|
2007-04-28 12:58:49 +00:00
|
|
|
// in the Length structure. Example: if "data" has the "pattern"
|
2001-11-30 14:57:15 +00:00
|
|
|
// "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);
|
2003-11-13 13:43:44 +00:00
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
default:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
bool isValidLength(string const & data, Length * 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"
|
2003-11-13 13:43:44 +00:00
|
|
|
while (!isEndOfData(buffer)) {
|
2001-11-30 14:57:15 +00:00
|
|
|
if (pattern_index > 2)
|
|
|
|
return false;
|
2003-11-13 13:43:44 +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()
|
2003-12-01 14:16:27 +00:00
|
|
|
: kind_(DEFSKIP), 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
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
VSpace::VSpace(Length const & l)
|
2001-11-30 14:57:15 +00:00
|
|
|
: kind_(LENGTH), len_(l), keep_(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
VSpace::VSpace(GlueLength const & l)
|
2001-12-02 23:47:06 +00:00
|
|
|
: kind_(LENGTH), len_(l), keep_(false)
|
2001-11-30 14:57:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
VSpace::VSpace(string const & data)
|
2003-12-01 14:16:27 +00:00
|
|
|
: kind_(DEFSKIP), len_(), keep_(false)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
if (data.empty())
|
|
|
|
return;
|
2003-11-13 13:43:44 +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);
|
|
|
|
}
|
|
|
|
|
2003-11-13 13:43:44 +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)) {
|
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;
|
2007-04-28 12:58:49 +00:00
|
|
|
len_ = GlueLength(Length(convert<double>(input), Length::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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
GlueLength 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 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
|
|
|
}
|
2003-12-01 14:16:27 +00:00
|
|
|
if (keep_)
|
2001-11-30 14:57:15 +00:00
|
|
|
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
|
|
|
{
|
2001-11-30 14:57:15 +00:00
|
|
|
switch (kind_) {
|
|
|
|
case DEFSKIP:
|
2003-11-13 13:43:44 +00:00
|
|
|
return params.getDefSkip().asLatexCommand(params);
|
|
|
|
|
2002-03-01 12:39:22 +00:00
|
|
|
case SMALLSKIP:
|
2003-11-13 13:43:44 +00:00
|
|
|
return keep_ ? "\\vspace*{\\smallskipamount}" : "\\smallskip{}";
|
|
|
|
|
2002-03-01 12:39:22 +00:00
|
|
|
case MEDSKIP:
|
2003-11-13 13:43:44 +00:00
|
|
|
return keep_ ? "\\vspace*{\\medskipamount}" : "\\medskip{}";
|
|
|
|
|
2002-03-01 12:39:22 +00:00
|
|
|
case BIGSKIP:
|
2003-11-13 13:43:44 +00:00
|
|
|
return keep_ ? "\\vspace*{\\bigskipamount}" : "\\bigskip{}";
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
case VFILL:
|
|
|
|
return keep_ ? "\\vspace*{\\fill}" : "\\vfill{}";
|
2002-03-02 13:21:31 +00:00
|
|
|
|
2004-04-03 08:37:12 +00:00
|
|
|
case LENGTH:
|
2003-11-13 13:43:44 +00:00
|
|
|
return keep_ ? "\\vspace*{" + len_.asLatexString() + '}'
|
|
|
|
: "\\vspace{" + len_.asLatexString() + '}';
|
2003-11-21 17:31:46 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return string();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-11 20:59:04 +00:00
|
|
|
docstring const VSpace::asGUIName() const
|
2005-05-24 10:23:30 +00:00
|
|
|
{
|
2006-11-11 20:59:04 +00:00
|
|
|
docstring result;
|
2005-05-24 10:23:30 +00:00
|
|
|
switch (kind_) {
|
|
|
|
case DEFSKIP:
|
2006-11-11 20:59:04 +00:00
|
|
|
result = _("Default skip");
|
2005-05-24 10:23:30 +00:00
|
|
|
break;
|
|
|
|
case SMALLSKIP:
|
2006-11-11 20:59:04 +00:00
|
|
|
result = _("Small skip");
|
2005-05-24 10:23:30 +00:00
|
|
|
break;
|
|
|
|
case MEDSKIP:
|
2006-11-11 20:59:04 +00:00
|
|
|
result = _("Medium skip");
|
2005-05-24 10:23:30 +00:00
|
|
|
break;
|
|
|
|
case BIGSKIP:
|
2006-11-11 20:59:04 +00:00
|
|
|
result = _("Big skip");
|
2005-05-24 10:23:30 +00:00
|
|
|
break;
|
|
|
|
case VFILL:
|
2006-11-11 20:59:04 +00:00
|
|
|
result = _("Vertical fill");
|
2005-05-24 10:23:30 +00:00
|
|
|
break;
|
|
|
|
case LENGTH:
|
2006-11-11 20:59:04 +00:00
|
|
|
result = from_ascii(len_.asString());
|
2005-05-24 10:23:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (keep_)
|
2006-11-11 20:59:04 +00:00
|
|
|
result += ", " + _("protected");
|
2005-05-24 10:23:30 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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)
|
2004-04-03 08:37:12 +00:00
|
|
|
int const default_height = defaultRowHeight();
|
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
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
case DEFSKIP:
|
2007-08-21 13:03:55 +00:00
|
|
|
return bv.buffer().params().getDefSkip().inPixels(bv);
|
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:
|
2003-11-13 13:43:44 +00:00
|
|
|
return default_height / 4;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-19 17:05:24 +00:00
|
|
|
case MEDSKIP:
|
2003-11-13 13:43:44 +00:00
|
|
|
return default_height / 2;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-01-19 17:05:24 +00:00
|
|
|
case BIGSKIP:
|
2003-11-13 13:43:44 +00:00
|
|
|
return default_height;
|
2002-01-19 17:05:24 +00:00
|
|
|
|
|
|
|
case VFILL:
|
1999-12-16 06:43:25 +00:00
|
|
|
// leave space for the vfill symbol
|
2003-11-13 13:43:44 +00:00
|
|
|
return 3 * default_height;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-08-29 13:05:55 +00:00
|
|
|
case LENGTH:
|
2003-11-13 13:43:44 +00:00
|
|
|
return len_.len().inPixels(bv.workWidth());
|
2003-11-21 17:31:46 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return 0;
|
2002-02-16 15:59:55 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|