X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fvspace.C;h=30c58c4774d6a7f922c43623545da482da551b3c;hb=31b56dac8042735f75229ad480b3e98531c181ff;hp=3c46446067bca30d7c3984ac1cbd93db4b7f183b;hpb=f04a7e4745482dccfa5b73e99375723bf96499e2;p=lyx.git diff --git a/src/vspace.C b/src/vspace.C index 3c46446067..30c58c4774 100644 --- a/src/vspace.C +++ b/src/vspace.C @@ -1,11 +1,10 @@ -// -*- 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. * * ====================================================== */ @@ -15,6 +14,8 @@ #pragma implementation "vspace.h" #endif +#include + #include "lyx_main.h" #include "buffer.h" #include "vspace.h" @@ -24,51 +25,46 @@ #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(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; -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); @@ -110,7 +106,7 @@ char nextToken(string & 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'; @@ -149,7 +145,6 @@ struct LaTeXLength { }; -static LaTeXLength table[] = { { "nu", 0, 0, 0, 0 }, { "nu+nu", 2, 0, 2, 0 }, @@ -167,6 +162,23 @@ LaTeXLength table[] = { { "", 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(i); +} + bool isValidGlueLength (string const & data, LyXGlueLength * result) { @@ -320,6 +332,28 @@ string const LyXLength::asString() const } +string const LyXLength::asLatexString() const +{ + std::ostringstream buffer; + switch(uni) { + case PW: + case PE: + buffer << abs(static_cast(val/100)) << "." << abs(static_cast(val)%100) << "\\columnwidth"; + break; + case PP: + buffer << "." << abs(static_cast(val/100)) << "." << abs(static_cast(val)%100) << "\\pagewidth"; + break; + case PL: + buffer << "." << abs(static_cast(val/100)) << "." << abs(static_cast(val)%100) << "\\linewidth"; + break; + default: + buffer << val << unit_name[uni]; // setw? + break; + } + return buffer.str().c_str(); +} + + /* LyXGlueLength class */ @@ -459,16 +493,16 @@ VSpace::VSpace (string const & data) bool VSpace::operator==(VSpace const & other) const { - if (this->kin == other.kin) - if (this->kin == LENGTH) - if (this->len == other.len) - return this->kp == other.kp; - else - return false; - else - return this->kp == other.kp; - else + if (this->kin != other.kin) + return false; + + if (this->kin != LENGTH) + return this->kp == other.kp; + + if (!(this->len == other.len)) return false; + + return this->kp == other.kp; } @@ -518,13 +552,15 @@ int VSpace::inPixels(BufferView * bv) const // Height of a normal line in pixels (zoom factor considered) 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] @@ -620,6 +656,12 @@ int VSpace::inPixels(int default_height, int default_skip) const // 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;