-// -*- 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"
#include "support/lstrings.h"
+namespace {
+
/* length units
*/
-static const int num_units = LyXLength::UNIT_NONE;
+int const num_units = LyXLength::UNIT_NONE;
// I am not sure if "mu" should be possible to select (Lgb)
-static char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
- "mm", "pc", "cc", "cm",
- "in", "ex", "em", "mu" };
+char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
+ "mm", "pc", "cc", "cm",
+ "in", "ex", "em", "mu",
+ "%", "c%", "p%", "l%" };
-LyXLength::UNIT unitFromString (string const & data)
-{
- int i = 0;
- while ((i < num_units) && (data != unit_name[i])) ++i;
- return static_cast<LyXLength::UNIT>(i);
-}
-
/* The following static items form a simple scanner for
* length strings, used by isValid[Glue]Length. See comments there.
*/
-static float number[4] = { 0, 0, 0, 0 };
-static LyXLength::UNIT unit[4] = { LyXLength::UNIT_NONE,
- LyXLength::UNIT_NONE,
- LyXLength::UNIT_NONE,
- LyXLength::UNIT_NONE };
-static int number_index, unit_index;
+float number[4] = { 0, 0, 0, 0 };
+LyXLength::UNIT unit[4] = { LyXLength::UNIT_NONE,
+ LyXLength::UNIT_NONE,
+ LyXLength::UNIT_NONE,
+ LyXLength::UNIT_NONE };
+int number_index;
+int unit_index;
-static inline
+inline
void lyx_advance(string & data, unsigned int n)
{
data.erase(0, n);
}
-static inline
+inline
bool isEndOfData(string const & data)
{
return frontStrip(data).empty();
}
-static
char nextToken(string & data)
{
data = frontStrip(data);
} 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';
};
-static
LaTeXLength table[] = {
{ "nu", 0, 0, 0, 0 },
{ "nu+nu", 2, 0, 2, 0 },
{ "", 0, 0, 0, 0 } // sentinel, must be empty
};
+} // 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)
+{
+ int i = 0;
+ while ((i < num_units) && (data != unit_name[i])) ++i;
+ return static_cast<LyXLength::UNIT>(i);
+}
+
bool isValidGlueLength (string const & data, LyXGlueLength * result)
{
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
*/
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)
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]
// 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;