-// -*- C++ -*-
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
+ * Copyright 1995-2001 The LyX Team.
*
* ====================================================== */
#pragma implementation "vspace.h"
#endif
+#include <stdio.h>
+
#include "lyx_main.h"
#include "buffer.h"
#include "vspace.h"
// I am not sure if "mu" should be possible to select (Lgb)
char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
"mm", "pc", "cc", "cm",
- "in", "ex", "em", "mu" };
+ "in", "ex", "em", "mu",
+ "%", "c%", "p%", "l%" };
/* The following static items form a simple scanner for
inline
-void lyx_advance(string & data, unsigned int n)
+void lyx_advance(string & data, string::size_type n)
{
data.erase(0, n);
}
} else return 'E';
}
- i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz");
+ i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz%");
if (i != 0) {
if (unit_index > 3) return 'E';
} // namespace anon
+const char * stringFromUnit(int unit)
+{
+ if (unit < 0 || unit >= num_units)
+ return 0;
+ return unit_name[unit];
+}
+
LyXLength::UNIT unitFromString (string const & data)
{
// To make isValidGlueLength recognize negative values as
// the first number this little hack is needed:
- short val_sign = 1; // positive as default
+ int val_sign = 1; // positive as default
switch (buffer[0]) {
case '-':
lyx_advance(buffer, 1);
// To make isValidLength recognize negative values
// this little hack is needed:
- short val_sign = 1; // positive as default
+ int val_sign = 1; // positive as default
switch (buffer[0]) {
case '-':
lyx_advance(buffer, 1);
string const LyXLength::asString() const
{
- std::ostringstream buffer;
+ ostringstream buffer;
buffer << val << unit_name[uni]; // setw?
return buffer.str().c_str();
}
+string const LyXLength::asLatexString() const
+{
+ ostringstream buffer;
+ switch(uni) {
+ case PW:
+ case PE:
+ buffer << abs(static_cast<int>(val/100)) << "." << abs(static_cast<int>(val)%100) << "\\columnwidth";
+ break;
+ case PP:
+ buffer << abs(static_cast<int>(val/100)) << "." << abs(static_cast<int>(val)%100) << "\\pagewidth";
+ break;
+ case PL:
+ buffer << abs(static_cast<int>(val/100)) << "." << abs(static_cast<int>(val)%100) << "\\linewidth";
+ break;
+ default:
+ buffer << val << unit_name[uni]; // setw?
+ break;
+ }
+ return buffer.str().c_str();
+}
+
+
/* LyXGlueLength class
*/
{
LyXGlueLength tmp(0.0, PT);
- if (!isValidGlueLength (data, &tmp))
- return; // should raise an exception
- else {
- val = tmp.val;
- uni = tmp.uni;
- plus_val = tmp.plus_val;
- plus_uni = tmp.plus_uni;
- minus_val = tmp.minus_val;
- minus_uni = tmp.minus_uni;
- }
+ // we should really raise exception here
+ if (!isValidGlueLength(data, &tmp))
+ ;
+
+ val = tmp.val;
+ uni = tmp.uni;
+ plus_val = tmp.plus_val;
+ plus_uni = tmp.plus_uni;
+ minus_val = tmp.minus_val;
+ minus_uni = tmp.minus_uni;
}
string const LyXGlueLength::asString() const
{
- std::ostringstream buffer;
+ ostringstream buffer;
if (plus_val != 0.0)
if (minus_val != 0.0)
string const LyXGlueLength::asLatexString() const
{
- std::ostringstream buffer;
+ ostringstream buffer;
if (plus_val != 0.0)
if (minus_val != 0.0)
float value;
string input = strip(data);
- int length = input.length();
+ string::size_type const length = input.length();
if (length > 1 && input[length-1] == '*') {
kp = true;
int VSpace::inPixels(BufferView * bv) const
{
// Height of a normal line in pixels (zoom factor considered)
- int height = bv->text->DefaultHeight(); // [pixels]
+ int height = bv->text->defaultHeight(); // [pixels]
int skip = 0;
+ int width = bv->workWidth();
+
if (kin == DEFSKIP)
skip = bv->buffer()->params.getDefSkip().inPixels(bv);
- return inPixels(height, skip);
+ return inPixels(height, skip, width);
}
-int VSpace::inPixels(int default_height, int default_skip) const
+int VSpace::inPixels(int default_height, int default_skip, int default_width) const
{
// Height of a normal line in pixels (zoom factor considered)
int height = default_height; // [pixels]
// is the same as on paper.
// we don't care about sign of value, we
- // can't display negative anyway
+ // display negative space with text too
result = 0.0;
value = len.value();
- short val_sign = value < 0.0 ? -1 : 1;
+ int val_sign = value < 0.0 ? -1 : 1;
switch (len.unit()) {
case LyXLength::SP:
// math mode
result = zoom * value * height;
break;
+ case LyXLength::PW: // Always % of workarea
+ case LyXLength::PE:
+ case LyXLength::PP:
+ case LyXLength::PL:
+ result = value * default_width / 100;
+ break;
case LyXLength::UNIT_NONE:
result = 0; // this cannot happen
break;