Addressing #212 bloat of fileformat for tabulars. More than this I'm not

willing to do on this for 1.2.0. Anyway this reduces TableExamples.lyx from
107kb to 66kb.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3585 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2002-02-26 08:24:48 +00:00
parent 96c10746aa
commit 635fea0855
4 changed files with 60 additions and 33 deletions

View File

@ -1,3 +1,13 @@
2002-02-26 Juergen Vigna <jug@sad.it>
* tabular_funcs.C (write_attribute): changed so that some default
attributes are not written at all.
(getTokenValue): set default values before trying to read the
value so we have the return value always set as default if we don't
find the token we search for.
* tabular.C (Write): write bools as bools not as strings!
2002-02-22 Juergen Vigna <jug@sad.it>
* BufferView_pimpl.C (workAreaButtonPress): call edit() before calling

View File

@ -1012,50 +1012,50 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const
<< ">\n";
// global longtable options
os << "<features"
<< write_attribute("rotate", tostr(rotate))
<< write_attribute("islongtable", tostr(is_long_tabular))
<< write_attribute("firstHeadTopDL", tostr(endfirsthead.topDL))
<< write_attribute("firstHeadBottomDL", tostr(endfirsthead.bottomDL))
<< write_attribute("firstHeadEmpty", tostr(endfirsthead.empty))
<< write_attribute("headTopDL", tostr(endhead.topDL))
<< write_attribute("headBottomDL", tostr(endhead.bottomDL))
<< write_attribute("footTopDL", tostr(endfoot.topDL))
<< write_attribute("footBottomDL", tostr(endfoot.bottomDL))
<< write_attribute("lastFootTopDL", tostr(endlastfoot.topDL))
<< write_attribute("lastFootBottomDL", tostr(endlastfoot.bottomDL))
<< write_attribute("lastFootEmpty", tostr(endlastfoot.empty))
<< write_attribute("rotate", rotate)
<< write_attribute("islongtable", is_long_tabular)
<< write_attribute("firstHeadTopDL", endfirsthead.topDL)
<< write_attribute("firstHeadBottomDL", endfirsthead.bottomDL)
<< write_attribute("firstHeadEmpty", endfirsthead.empty)
<< write_attribute("headTopDL", endhead.topDL)
<< write_attribute("headBottomDL", endhead.bottomDL)
<< write_attribute("footTopDL", endfoot.topDL)
<< write_attribute("footBottomDL", endfoot.bottomDL)
<< write_attribute("lastFootTopDL", endlastfoot.topDL)
<< write_attribute("lastFootBottomDL", endlastfoot.bottomDL)
<< write_attribute("lastFootEmpty", endlastfoot.empty)
<< ">\n";
for (int j = 0; j < columns_; ++j) {
os << "<column"
<< write_attribute("alignment", tostr(column_info[j].alignment))
<< write_attribute("valignment", tostr(column_info[j].valignment))
<< write_attribute("leftline", tostr(column_info[j].left_line))
<< write_attribute("rightline", tostr(column_info[j].right_line))
<< write_attribute("alignment", column_info[j].alignment)
<< write_attribute("valignment", column_info[j].valignment)
<< write_attribute("leftline", column_info[j].left_line)
<< write_attribute("rightline", column_info[j].right_line)
<< write_attribute("width", column_info[j].p_width.asString())
<< write_attribute("special", column_info[j].align_special)
<< ">\n";
}
for (int i = 0; i < rows_; ++i) {
os << "<row"
<< write_attribute("topline", tostr(row_info[i].top_line))
<< write_attribute("bottomline", tostr(row_info[i].bottom_line))
<< write_attribute("endhead", tostr(row_info[i].endhead))
<< write_attribute("endfirsthead", tostr(row_info[i].endfirsthead))
<< write_attribute("endfoot", tostr(row_info[i].endfoot))
<< write_attribute("endlastfoot", tostr(row_info[i].endlastfoot))
<< write_attribute("newpage", tostr(row_info[i].newpage))
<< write_attribute("topline", row_info[i].top_line)
<< write_attribute("bottomline", row_info[i].bottom_line)
<< write_attribute("endhead", row_info[i].endhead)
<< write_attribute("endfirsthead", row_info[i].endfirsthead)
<< write_attribute("endfoot", row_info[i].endfoot)
<< write_attribute("endlastfoot", row_info[i].endlastfoot)
<< write_attribute("newpage", row_info[i].newpage)
<< ">\n";
for (int j = 0; j < columns_; ++j) {
os << "<cell"
<< write_attribute("multicolumn", cell_info[i][j].multicolumn)
<< write_attribute("alignment", tostr(cell_info[i][j].alignment))
<< write_attribute("valignment", tostr(cell_info[i][j].valignment))
<< write_attribute("topline", tostr(cell_info[i][j].top_line))
<< write_attribute("bottomline", tostr(cell_info[i][j].bottom_line))
<< write_attribute("leftline", tostr(cell_info[i][j].left_line))
<< write_attribute("rightline", tostr(cell_info[i][j].right_line))
<< write_attribute("rotate", tostr(cell_info[i][j].rotate))
<< write_attribute("usebox", tostr(cell_info[i][j].usebox))
<< write_attribute("alignment", cell_info[i][j].alignment)
<< write_attribute("valignment", cell_info[i][j].valignment)
<< write_attribute("topline", cell_info[i][j].top_line)
<< write_attribute("bottomline", cell_info[i][j].bottom_line)
<< write_attribute("leftline", cell_info[i][j].left_line)
<< write_attribute("rightline", cell_info[i][j].right_line)
<< write_attribute("rotate", cell_info[i][j].rotate)
<< write_attribute("usebox", cell_info[i][j].usebox)
<< write_attribute("width", cell_info[i][j].p_width)
<< write_attribute("special", cell_info[i][j].align_special)
<< ">\n";

View File

@ -35,7 +35,18 @@ string const write_attribute(string const & name, bool const & b)
if (!b)
return string();
return write_attribute(name, int(b));
return write_attribute(name, tostr(b));
}
template <>
string const write_attribute(string const & name, int const & i)
{
// we write only true attribute values so we remove a bit of the
// file format bloat for tabulars.
if (!i)
return string();
return write_attribute(name, tostr(i));
}
template <>
@ -158,13 +169,13 @@ bool string2type(string const str, bool & num)
bool getTokenValue(string const & str, const char * token, string & ret)
{
ret.erase();
size_t token_length = strlen(token);
string::size_type pos = str.find(token);
if (pos == string::npos || pos + token_length + 1 >= str.length()
|| str[pos + token_length] != '=')
return false;
ret.erase();
pos += token_length + 1;
char ch = str[pos];
if ((ch != '"') && (ch != '\'')) { // only read till next space
@ -181,6 +192,7 @@ bool getTokenValue(string const & str, const char * token, string & ret)
bool getTokenValue(string const & str, const char * token, int & num)
{
string tmp;
num = 0;
if (!getTokenValue(str, token, tmp))
return false;
num = strToInt(tmp);

View File

@ -28,12 +28,17 @@
template<class T>
string const write_attribute(string const & name, T const & t)
{
if (tostr(t).empty())
return string();
string str = " " + name + "=\"" + tostr(t) + "\"";
return str;
}
template<>
string const write_attribute(string const & name, bool const & b);
template<>
string const write_attribute(string const & name, int const & b);
template<>
string const write_attribute(string const & name, LyXLength const & value);
string const tostr(LyXAlignment const & num);
string const tostr(LyXTabular::VAlignment const & num);