X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FVSpace.cpp;h=da9133a4c090727525e11a413a82550439bd9c92;hb=01dc4e4b83a863c7503cb471a7b8adc19f134761;hp=e88833e2f42533cf37b59dba389e125de16f8496;hpb=f630be890494c849981e4fb52ea4740506e92bed;p=lyx.git diff --git a/src/VSpace.cpp b/src/VSpace.cpp index e88833e2f4..da9133a4c0 100644 --- a/src/VSpace.cpp +++ b/src/VSpace.cpp @@ -11,37 +11,40 @@ #include #include "VSpace.h" + #include "Buffer.h" #include "BufferParams.h" #include "BufferView.h" -#include "gettext.h" -#include "lengthcommon.h" -#include "LyXText.h" +#include "support/gettext.h" +#include "Length.h" +#include "Text.h" +#include "TextMetrics.h" // for defaultRowHeight() #include "support/convert.h" #include "support/lstrings.h" +#include "support/lassert.h" -namespace lyx { +#include -using support::compare; -using support::isStrDbl; -using support::ltrim; -using support::prefixIs; -using support::rtrim; +using namespace std; +using namespace lyx::support; -using std::string; +namespace lyx { namespace { /// 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 }; +Length::UNIT unit[4] = { + Length::UNIT_NONE, + Length::UNIT_NONE, + Length::UNIT_NONE, + Length::UNIT_NONE +}; /// the current position in the number array int number_index; @@ -49,16 +52,14 @@ int number_index; int unit_index; /// skip n characters of input -inline -void lyx_advance(string & data, string::size_type n) +inline void lyx_advance(string & data, size_t n) { data.erase(0, n); } /// return true when the input is at the end -inline -bool isEndOfData(string const & data) +inline bool isEndOfData(string const & data) { return ltrim(data).empty(); } @@ -103,7 +104,7 @@ char nextToken(string & data) return '-'; } - string::size_type i = data.find_first_not_of("0123456789."); + size_t i = data.find_first_not_of("0123456789."); if (i != 0) { if (number_index > 3) @@ -115,8 +116,9 @@ char nextToken(string & data) if (i == string::npos) { buffer = data; i = data.size() + 1; - } else + } else { buffer = data.substr(0, i); + } lyx_advance(data, i); @@ -139,8 +141,9 @@ char nextToken(string & data) if (i == string::npos) { buffer = data; i = data.size() + 1; - } else + } else { buffer = data.substr(0, i); + } // possibly we have "mmplus" string or similar if (buffer.size() > 5 && @@ -154,7 +157,7 @@ char nextToken(string & data) unit[unit_index] = unitFromString(buffer); } - if (unit[unit_index] != LyXLength::UNIT_NONE) { + if (unit[unit_index] != Length::UNIT_NONE) { ++unit_index; return 'u'; } @@ -203,7 +206,7 @@ const char * stringFromUnit(int unit) } -bool isValidGlueLength(string const & data, LyXGlueLength * result) +bool isValidGlueLength(string const & data, GlueLength * result) { // This parser is table-driven. First, it constructs a "pattern" // that describes the sequence of tokens in "data". For example, @@ -211,7 +214,7 @@ bool isValidGlueLength(string const & data, LyXGlueLength * result) // 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" + // in the Length structure. Example: if "data" has the "pattern" // "nu+nu-nu", the associated table entries are "2, 3, 2, 3". // That means, "plus_val" is the second number that was seen // in the input, "minus_val" is the third number, and "plus_uni" @@ -241,25 +244,23 @@ bool isValidGlueLength(string const & data, LyXGlueLength * result) } // end of hack - int pattern_index = 0; - int table_index = 0; - char pattern[20]; - - number_index = 1; - unit_index = 1; // entries at index 0 are sentinels + number_index = unit_index = 1; // entries at index 0 are sentinels // 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; - ++pattern_index; + size_t const pattern_max_size = 20; + string pattern; + while (!isEndOfData(buffer)) { + if (pattern.size() > pattern_max_size) + return false; + char const c = nextToken(buffer); + if (c == 'E') + return false; + pattern.push_back(c); } - pattern[pattern_index] = '\0'; // search "pattern" in "table" - table_index = 0; - while (compare(pattern, table[table_index].pattern)) { + size_t table_index = 0; + while (pattern != table[table_index].pattern) { ++table_index; if (!*table[table_index].pattern) return false; @@ -280,7 +281,7 @@ bool isValidGlueLength(string const & data, LyXGlueLength * result) } -bool isValidLength(string const & data, LyXLength * result) +bool isValidLength(string const & data, Length * result) { // This is a trimmed down version of isValidGlueLength. // The parser may seem overkill for lengths without @@ -324,7 +325,8 @@ bool isValidLength(string const & data, LyXLength * result) pattern[pattern_index] = '\0'; // only the most basic pattern is accepted here - if (compare(pattern, "nu") != 0) return false; + if (strcmp(pattern, "nu") != 0) + return false; // It _was_ a correct length string. // Store away the values we found. @@ -345,17 +347,17 @@ VSpace::VSpace() {} -VSpace::VSpace(vspace_kind k) +VSpace::VSpace(VSpaceKind k) : kind_(k), len_(), keep_(false) {} -VSpace::VSpace(LyXLength const & l) +VSpace::VSpace(Length const & l) : kind_(LENGTH), len_(l), keep_(false) {} -VSpace::VSpace(LyXGlueLength const & l) +VSpace::VSpace(GlueLength const & l) : kind_(LENGTH), len_(l), keep_(false) {} @@ -368,7 +370,7 @@ VSpace::VSpace(string const & data) string input = rtrim(data); - string::size_type const length = input.length(); + size_t const length = input.length(); if (length > 1 && input[length - 1] == '*') { keep_ = true; @@ -392,35 +394,11 @@ VSpace::VSpace(string const & data) // without units in added_space_top/bottom. // Let unit default to centimeters here. kind_ = LENGTH; - len_ = LyXGlueLength(LyXLength(convert(input), LyXLength::CM)); + len_ = GlueLength(Length(convert(input), Length::CM)); } } -VSpace::vspace_kind VSpace::kind() const -{ - return kind_; -} - - -LyXGlueLength const & VSpace::length() const -{ - return len_; -} - - -bool VSpace::keep() const -{ - return keep_; -} - - -void VSpace::setKeep(bool val) -{ - keep_ = val; -} - - bool VSpace::operator==(VSpace const & other) const { if (kind_ != other.kind_) @@ -476,7 +454,7 @@ string const VSpace::asLatexCommand(BufferParams const & params) const : "\\vspace{" + len_.asLatexString() + '}'; default: - BOOST_ASSERT(false); + LASSERT(false, /**/); return string(); } } @@ -511,6 +489,24 @@ docstring const VSpace::asGUIName() const } +string VSpace::asHTMLLength() const +{ + string result; + switch (kind_) { + case DEFSKIP: result = "2ex"; break; + case SMALLSKIP: result = "1ex"; break; + case MEDSKIP: result = "3ex"; break; + case BIGSKIP: result = "5ex"; break; + case LENGTH: { + Length tmp = len_.len(); + if (tmp.value() > 0) + result = tmp.asHTMLString(); + } + case VFILL: break; + } + return result; +} + int VSpace::inPixels(BufferView const & bv) const { // Height of a normal line in pixels (zoom factor considered) @@ -519,7 +515,7 @@ int VSpace::inPixels(BufferView const & bv) const switch (kind_) { case DEFSKIP: - return bv.buffer()->params().getDefSkip().inPixels(bv); + return bv.buffer().params().getDefSkip().inPixels(bv); // This is how the skips are normally defined by LateX. // But there should be some way to change this per document. @@ -540,7 +536,7 @@ int VSpace::inPixels(BufferView const & bv) const return len_.len().inPixels(bv.workWidth()); default: - BOOST_ASSERT(false); + LASSERT(false, /**/); return 0; } }