- static LyXFont font;
- static Change change;
-
- BufferParams const & bp = buf.params();
-
- if (token[0] != '\\') {
- string::const_iterator cit = token.begin();
- for (; cit != token.end(); ++cit) {
- par.insertChar(par.size(), (*cit), font, change);
- }
- } else if (token == "\\begin_layout") {
- lex.eatLine();
- string layoutname = lex.getString();
-
- font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
- change = Change();
-
- LyXTextClass const & tclass = bp.getLyXTextClass();
-
- if (layoutname.empty()) {
- layoutname = tclass.defaultLayoutName();
- }
-
- bool hasLayout = tclass.hasLayout(layoutname);
-
- if (!hasLayout) {
- lyxerr << "Layout '" << layoutname << "' does not"
- << " exist in textclass '" << tclass.name()
- << "'." << endl;
- lyxerr << "Trying to use default layout instead."
- << endl;
- layoutname = tclass.defaultLayoutName();
- }
-
- par.layout(bp.getLyXTextClass()[layoutname]);
-
- // Test whether the layout is obsolete.
- LyXLayout_ptr const & layout = par.layout();
- if (!layout->obsoleted_by().empty())
- par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
-
- par.params().read(lex);
-
- } else if (token == "\\end_layout") {
- lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
- << "Missing \\begin_layout?.\n";
- } else if (token == "\\end_inset") {
- lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
- << "Missing \\begin_inset?.\n";
- } else if (token == "\\begin_inset") {
- InsetOld * inset = readInset(lex, buf);
- if (inset)
- par.insertInset(par.size(), inset, font, change);
- else {
- lex.eatLine();
- string line = lex.getString();
- buf.error(ErrorItem(_("Unknown Inset"), line,
- par.id(), 0, par.size()));
- return 1;
- }
- } else if (token == "\\family") {
- lex.next();
- font.setLyXFamily(lex.getString());
- } else if (token == "\\series") {
- lex.next();
- font.setLyXSeries(lex.getString());
- } else if (token == "\\shape") {
- lex.next();
- font.setLyXShape(lex.getString());
- } else if (token == "\\size") {
- lex.next();
- font.setLyXSize(lex.getString());
- } else if (token == "\\lang") {
- lex.next();
- string const tok = lex.getString();
- Language const * lang = languages.getLanguage(tok);
- if (lang) {
- font.setLanguage(lang);
- } else {
- font.setLanguage(bp.language);
- lex.printError("Unknown language `$$Token'");
- }
- } else if (token == "\\numeric") {
- lex.next();
- font.setNumber(font.setLyXMisc(lex.getString()));
- } else if (token == "\\emph") {
- lex.next();
- font.setEmph(font.setLyXMisc(lex.getString()));
- } else if (token == "\\bar") {
- lex.next();
- string const tok = lex.getString();
-
- if (tok == "under")
- font.setUnderbar(LyXFont::ON);
- else if (tok == "no")
- font.setUnderbar(LyXFont::OFF);
- else if (tok == "default")
- font.setUnderbar(LyXFont::INHERIT);
- else
- lex.printError("Unknown bar font flag "
- "`$$Token'");
- } else if (token == "\\noun") {
- lex.next();
- font.setNoun(font.setLyXMisc(lex.getString()));
- } else if (token == "\\color") {
- lex.next();
- font.setLyXColor(lex.getString());
- } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
-
- // Insets don't make sense in a free-spacing context! ---Kayvan
- if (par.isFreeSpacing()) {
- if (token == "\\InsetSpace")
- par.insertChar(par.size(), ' ', font, change);
- else if (lex.isOK()) {
- lex.next();
- string const next_token = lex.getString();
- if (next_token == "\\-")
- par.insertChar(par.size(), '-', font, change);
- else {
- lex.printError("Token `$$Token' "
- "is in free space "
- "paragraph layout!");
- }
- }
- } else {
- auto_ptr<InsetOld> inset;
- if (token == "\\SpecialChar" )
- inset.reset(new InsetSpecialChar);
- else
- inset.reset(new InsetSpace);
- inset->read(buf, lex);
- par.insertInset(par.size(), inset.release(),
- font, change);
- }
- } else if (token == "\\i") {
- auto_ptr<InsetOld> inset(new InsetLatexAccent);
- inset->read(buf, lex);
- par.insertInset(par.size(), inset.release(), font, change);
- } else if (token == "\\backslash") {
- par.insertChar(par.size(), '\\', font, change);
- } else if (token == "\\newline") {
- auto_ptr<InsetOld> inset(new InsetNewline);
- inset->read(buf, lex);
- par.insertInset(par.size(), inset.release(), font, change);
- } else if (token == "\\LyXTable") {
- auto_ptr<InsetOld> inset(new InsetTabular(buf));
- inset->read(buf, lex);
- par.insertInset(par.size(), inset.release(), font, change);
- } else if (token == "\\bibitem") {
- InsetCommandParams p("bibitem", "dummy");
- auto_ptr<InsetBibitem> inset(new InsetBibitem(p));
- inset->read(buf, lex);
- par.insertInset(par.size(), inset.release(), font, change);
- } else if (token == "\\hfill") {
- par.insertInset(par.size(), new InsetHFill, font, change);
- } else if (token == "\\lyxline") {
- par.insertInset(par.size(), new InsetLine, font, change);
- } else if (token == "\\newpage") {
- par.insertInset(par.size(), new InsetPagebreak, font, change);
- } else if (token == "\\change_unchanged") {
- // Hack ! Needed for empty paragraphs :/
- // FIXME: is it still ??
- if (!par.size())
- par.cleanChanges();
- change = Change(Change::UNCHANGED);
- } else if (token == "\\change_inserted") {
- lex.nextToken();
- istringstream is(lex.getString());
- int aid;
- lyx::time_type ct;
- is >> aid >> ct;
- change = Change(Change::INSERTED, bp.author_map[aid], ct);
- } else if (token == "\\change_deleted") {
- lex.nextToken();
- istringstream is(lex.getString());
- int aid;
- lyx::time_type ct;
- is >> aid >> ct;
- change = Change(Change::DELETED, bp.author_map[aid], ct);
- } else {
- lex.eatLine();
- string const s = bformat(_("Unknown token: %1$s %2$s\n"),
- token, lex.getString());
-
- buf.error(ErrorItem(_("Unknown token"), s,
- par.id(), 0, par.size()));
- return 1;
- }
- return 0;
-}
-
-}
-
-
-int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
-{
- int unknown = 0;
-
- lex.nextToken();
- string token = lex.getString();
-
- while (lex.isOK()) {
-
- unknown += readParToken(buf, par, lex, token);
-
- lex.nextToken();
- token = lex.getString();
-
- if (token.empty())
- continue;
-
- if (token == "\\end_layout") {
- //Ok, paragraph finished
- break;
- }
-
- lyxerr[Debug::PARSER] << "Handling paragraph token: `"
- << token << '\'' << endl;
- if (token == "\\begin_layout" || token == "\\end_document"
- || token == "\\end_inset" || token == "\\begin_deeper"
- || token == "\\end_deeper") {
- lex.pushToken(token);
- lyxerr << "Paragraph ended in line "
- << lex.getLineNo() << "\n"
- << "Missing \\end_layout.\n";
- break;
- }
- }
-
- return unknown;
-}
-
-
-LyXFont const outerFont(ParagraphList::iterator pit,
- ParagraphList const & plist)
-{
- Paragraph::depth_type par_depth = pit->getDepth();