From: John Levon Date: Wed, 12 Mar 2003 07:39:17 +0000 (+0000) Subject: Create ParagraphParameters::read(). JMarc, please note the change to LyXLex - is... X-Git-Tag: 1.6.10~17262 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c4bda8ac16c7ebe1cb00f1c17215287f976d2a06;p=lyx.git Create ParagraphParameters::read(). JMarc, please note the change to LyXLex - is this ok ? Works for me anyhoo git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6463 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index b1bce08ae4..0f0e006a0b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2003-03-12 John Levon + + * buffer.C: + * ParagraphParameters.C: move par params input to + a read() method + + * lyxlex_pimpl.C: make nextToken()/next() after a pushToken() + behave like a normal read from the stream wrt reading + a line vs. a \\token + 2003-03-12 John Levon * paragraph.C: diff --git a/src/ParagraphParameters.C b/src/ParagraphParameters.C index 76fb8aff4e..90ca29c730 100644 --- a/src/ParagraphParameters.C +++ b/src/ParagraphParameters.C @@ -5,6 +5,8 @@ #include "tex-strings.h" #include "lyxlex.h" +#include "support/lstrings.h" + #include using std::ostream; @@ -268,6 +270,86 @@ void ParagraphParameters::leftIndent(LyXLength const & li) void ParagraphParameters::read(LyXLex & lex) { + while (lex.isOK()) { + lex.nextToken(); + string const token = lex.getString(); + + if (token.empty()) + continue; + + if (token[0] != '\\') { + lex.pushToken(token); + break; + } + + if (token == "\\noindent") { + noindent(true); + } else if (token == "\\leftindent") { + lex.nextToken(); + LyXLength value(lex.getString()); + leftIndent(value); + } else if (token == "\\fill_top") { + spaceTop(VSpace(VSpace::VFILL)); + } else if (token == "\\fill_bottom") { + spaceBottom(VSpace(VSpace::VFILL)); + } else if (token == "\\line_top") { + lineTop(true); + } else if (token == "\\line_bottom") { + lineBottom(true); + } else if (token == "\\pagebreak_top") { + pagebreakTop(true); + } else if (token == "\\pagebreak_bottom") { + pagebreakBottom(true); + } else if (token == "\\start_of_appendix") { + startOfAppendix(true); + } else if (token == "\\paragraph_spacing") { + lex.next(); + string const tmp = rtrim(lex.getString()); + if (tmp == "single") { + spacing(Spacing(Spacing::Single)); + } else if (tmp == "onehalf") { + spacing(Spacing(Spacing::Onehalf)); + } else if (tmp == "double") { + spacing(Spacing(Spacing::Double)); + } else if (tmp == "other") { + lex.next(); + spacing(Spacing(Spacing::Other, + lex.getFloat())); + } else { + lex.printError("Unknown spacing token: '$$Token'"); + } + } else if (token == "\\align") { + int tmpret = lex.findToken(string_align); + if (tmpret == -1) + ++tmpret; + int const tmpret2 = int(pow(2.0, tmpret)); + align(LyXAlignment(tmpret2)); + } else if (token == "\\added_space_top") { + lex.nextToken(); + VSpace value = VSpace(lex.getString()); + // only add the length when value > 0 or + // with option keep + if ((value.length().len().value() != 0) || + value.keep() || + (value.kind() != VSpace::LENGTH)) + spaceTop(value); + } else if (token == "\\added_space_bottom") { + lex.nextToken(); + VSpace value = VSpace(lex.getString()); + // only add the length when value > 0 or + // with option keep + if ((value.length().len().value() != 0) || + value.keep() || + (value.kind() != VSpace::LENGTH)) + spaceBottom(value); + } else if (token == "\\labelwidthstring") { + lex.eatLine(); + labelWidthString(lex.getString()); + } else { + lex.pushToken(token); + break; + } + } } diff --git a/src/buffer.C b/src/buffer.C index 78e2e0795f..65819731e6 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -536,7 +536,6 @@ Buffer::readToken(LyXLex & lex, ParagraphList & pars, } else { #endif Paragraph * par = new Paragraph(); - par->layout(params.getLyXTextClass().defaultLayout()); if (params.tracking_changes) par->trackChanges(); pos = 0; @@ -546,6 +545,9 @@ Buffer::readToken(LyXLex & lex, ParagraphList & pars, if (!layout->obsoleted_by().empty()) par->layout(params.getLyXTextClass()[layout->obsoleted_by()]); par->params().depth(depth); + + par->params().read(lex); + // insert after if (pit != pars.end()) ++pit; @@ -652,69 +654,6 @@ Buffer::readToken(LyXLex & lex, ParagraphList & pars, } else --depth; - } else if (token == "\\noindent") { - pit->params().noindent(true); - } else if (token == "\\leftindent") { - lex.nextToken(); - LyXLength value(lex.getString()); - pit->params().leftIndent(value); - } else if (token == "\\fill_top") { - pit->params().spaceTop(VSpace(VSpace::VFILL)); - } else if (token == "\\fill_bottom") { - pit->params().spaceBottom(VSpace(VSpace::VFILL)); - } else if (token == "\\line_top") { - pit->params().lineTop(true); - } else if (token == "\\line_bottom") { - pit->params().lineBottom(true); - } else if (token == "\\pagebreak_top") { - pit->params().pagebreakTop(true); - } else if (token == "\\pagebreak_bottom") { - pit->params().pagebreakBottom(true); - } else if (token == "\\start_of_appendix") { - pit->params().startOfAppendix(true); - } else if (token == "\\paragraph_spacing") { - lex.next(); - string const tmp = rtrim(lex.getString()); - if (tmp == "single") { - pit->params().spacing(Spacing(Spacing::Single)); - } else if (tmp == "onehalf") { - pit->params().spacing(Spacing(Spacing::Onehalf)); - } else if (tmp == "double") { - pit->params().spacing(Spacing(Spacing::Double)); - } else if (tmp == "other") { - lex.next(); - pit->params().spacing(Spacing(Spacing::Other, - lex.getFloat())); - } else { - lex.printError("Unknown spacing token: '$$Token'"); - } - } else if (token == "\\align") { - int tmpret = lex.findToken(string_align); - if (tmpret == -1) - ++tmpret; - int const tmpret2 = int(pow(2.0, tmpret)); - pit->params().align(LyXAlignment(tmpret2)); - } else if (token == "\\added_space_top") { - lex.nextToken(); - VSpace value = VSpace(lex.getString()); - // only add the length when value > 0 or - // with option keep - if ((value.length().len().value() != 0) || - value.keep() || - (value.kind() != VSpace::LENGTH)) - pit->params().spaceTop(value); - } else if (token == "\\added_space_bottom") { - lex.nextToken(); - VSpace value = VSpace(lex.getString()); - // only add the length when value > 0 or - // with option keep - if ((value.length().len().value() != 0) || - value.keep() || - (value.kind() != VSpace::LENGTH)) - pit->params().spaceBottom(value); - } else if (token == "\\labelwidthstring") { - lex.eatLine(); - pit->params().labelWidthString(lex.getString()); // do not delete this token, it is still needed! } else if (token == "\\newline") { pit->insertChar(pos, Paragraph::META_NEWLINE, font, current_change); diff --git a/src/lyxlex_pimpl.C b/src/lyxlex_pimpl.C index 653d6fe04e..35d843f8df 100644 --- a/src/lyxlex_pimpl.C +++ b/src/lyxlex_pimpl.C @@ -144,7 +144,7 @@ bool LyXLex::Pimpl::next(bool esc /* = false */) // There can have been a whole line pushed so // we extract the first word and leaves the rest // in pushTok. (Lgb) - if (pushTok.find(' ') != string::npos) { + if (pushTok.find(' ') != string::npos && pushTok[0] == '\\') { string tmp; pushTok = split(pushTok, tmp, ' '); tmp.copy(buff, string::npos); @@ -434,7 +434,7 @@ bool LyXLex::Pimpl::nextToken() // There can have been a whole line pushed so // we extract the first word and leaves the rest // in pushTok. (Lgb) - if (pushTok.find(' ') != string::npos) { + if (pushTok.find(' ') != string::npos && pushTok[0] == '\\') { string tmp; pushTok = split(pushTok, tmp, ' '); tmp.copy(buff, string::npos);