-#ifdef USE_CAPTION
- // The is the compability reading of layout caption.
- // It can be removed in LyX version 1.3.0. (Lgb)
- if (compare_ascii_no_case(layoutname, "caption") == 0) {
- // We expect that the par we are now working on is
- // really inside a InsetText inside a InsetFloat.
- // We also know that captions can only be
- // one paragraph. (Lgb)
-
- // We should now read until the next "\layout"
- // is reached.
- // This is probably not good enough, what if the
- // caption is the last par in the document (Lgb)
- istream & ist = lex.getStream();
- stringstream ss;
- string line;
- int begin = 0;
- while (true) {
- getline(ist, line);
- if (prefixIs(line, "\\layout")) {
- lex.pushToken(line);
- break;
- }
- if (prefixIs(line, "\\begin_inset"))
- ++begin;
- if (prefixIs(line, "\\end_inset")) {
- if (begin)
- --begin;
- else {
- lex.pushToken(line);
- break;
- }
- }
-
- ss << line << '\n';
- }
- // Now we should have the whole layout in ss
- // we should now be able to give this to the
- // caption inset.
- ss << "\\end_inset\n";
-
- // This seems like a bug in stringstream.
- // We really should be able to use ss
- // directly. (Lgb)
- istringstream is(ss.str());
- LyXLex tmplex(0, 0);
- tmplex.setStream(is);
- Inset * inset = new InsetCaption;
- inset->Read(this, tmplex);
- par->InsertInset(pos, inset, font);
- ++pos;
- } else {
-#endif
- if (!first_par)
- first_par = par;
- else {
- par = new Paragraph(par);
- par->layout(params.getLyXTextClass().defaultLayout());
- if (params.tracking_changes)
- par->trackChanges();
- }
- pos = 0;
- par->layout(params.getLyXTextClass()[layoutname]);
- // Test whether the layout is obsolete.
- LyXLayout_ptr const & layout = par->layout();
- if (!layout->obsoleted_by().empty())
- par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
- par->params().depth(depth);
-#if USE_CAPTION
- }
-#endif
-
- } else if (token == "\\end_inset") {
- lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
- << "Missing \\begin_inset?.\n";
- // Simply ignore this. The insets do not have
- // to read this.
- // But insets should read it, it is a part of
- // the inset isn't it? Lgb.
- } else if (token == "\\begin_inset") {
- readInset(lex, par, pos, font);
- } 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(params.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();
- // This is dirty, but gone with LyX3. (Asger)
- 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 == "\\SpecialChar") {
- LyXLayout_ptr const & layout = par->layout();
-
- // Insets don't make sense in a free-spacing context! ---Kayvan
- if (layout->free_spacing || par->isFreeSpacing()) {
- if (lex.isOK()) {
- lex.next();
- string const next_token = lex.getString();
- if (next_token == "\\-") {
- par->insertChar(pos, '-', font, current_change);
- } else if (next_token == "~") {
- par->insertChar(pos, ' ', font, current_change);
- } else {
- lex.printError("Token `$$Token' "
- "is in free space "
- "paragraph layout!");
- --pos;
- }
- }
- } else {
- Inset * inset = new InsetSpecialChar;
- inset->read(this, lex);
- par->insertInset(pos, inset, font, current_change);
- }
- ++pos;
- } else if (token == "\\i") {
- Inset * inset = new InsetLatexAccent;
- inset->read(this, lex);
- par->insertInset(pos, inset, font, current_change);
- ++pos;
- } else if (token == "\\backslash") {
- par->insertChar(pos, '\\', font, current_change);
- ++pos;
- } else if (token == "\\begin_deeper") {
- ++depth;
- } else if (token == "\\end_deeper") {
- if (!depth) {
- lex.printError("\\end_deeper: "
- "depth is already null");
- }
- else
- --depth;
- } else if (token == "\\noindent") {
- par->params().noindent(true);
- } else if (token == "\\leftindent") {
- lex.nextToken();
- LyXLength value(lex.getString());
- par->params().leftIndent(value);
- } else if (token == "\\fill_top") {
- par->params().spaceTop(VSpace(VSpace::VFILL));
- } else if (token == "\\fill_bottom") {
- par->params().spaceBottom(VSpace(VSpace::VFILL));
- } else if (token == "\\line_top") {
- par->params().lineTop(true);
- } else if (token == "\\line_bottom") {
- par->params().lineBottom(true);
- } else if (token == "\\pagebreak_top") {
- par->params().pagebreakTop(true);
- } else if (token == "\\pagebreak_bottom") {
- par->params().pagebreakBottom(true);
- } else if (token == "\\start_of_appendix") {
- par->params().startOfAppendix(true);
- } else if (token == "\\paragraph_spacing") {
- lex.next();
- string const tmp = rtrim(lex.getString());
- if (tmp == "single") {
- par->params().spacing(Spacing(Spacing::Single));
- } else if (tmp == "onehalf") {
- par->params().spacing(Spacing(Spacing::Onehalf));
- } else if (tmp == "double") {
- par->params().spacing(Spacing(Spacing::Double));
- } else if (tmp == "other") {
- lex.next();
- par->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));
- par->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))
- par->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))
- par->params().spaceBottom(value);
- } else if (token == "\\labelwidthstring") {
- lex.eatLine();
- par->params().labelWidthString(lex.getString());
- // do not delete this token, it is still needed!
- } else if (token == "\\newline") {
- par->insertChar(pos, Paragraph::META_NEWLINE, font, current_change);
- ++pos;
- } else if (token == "\\LyXTable") {
- Inset * inset = new InsetTabular(*this);
- inset->read(this, lex);
- par->insertInset(pos, inset, font, current_change);
- ++pos;
- } else if (token == "\\bibitem") { // ale970302
- InsetCommandParams p("bibitem", "dummy");
- InsetBibitem * inset = new InsetBibitem(p);
- inset->read(this, lex);
- par->insertInset(pos, inset, font, current_change);
- ++pos;
- } else if (token == "\\hfill") {
- par->insertInset(pos, new InsetHFill(),
- LyXFont(LyXFont::ALL_INHERIT, params.language));
- ++pos;
- } else if (token == "\\change_unchanged") {
- // Hack ! Needed for empty paragraphs :/
- if (!pos)
- par->cleanChanges();
- current_change = Change(Change::UNCHANGED);
- } else if (token == "\\change_inserted") {
- lex.nextToken();
- istringstream istr(lex.getString());
- int aid;
- lyx::time_type ct;
- istr >> aid;
- istr >> ct;
- current_change = Change(Change::INSERTED, params.author_ids[aid], ct);
- } else if (token == "\\change_deleted") {
- lex.nextToken();
- istringstream istr(lex.getString());
- int aid;
- lyx::time_type ct;
- istr >> aid;
- istr >> ct;
- current_change = Change(Change::DELETED, params.author_ids[aid], ct);
- } else {
- // This should be insurance for the future: (Asger)
- ++unknown;
- lex.eatLine();
-#if USE_BOOST_FORMAT
- boost::format fmt(_("Unknown token: %1$s %2$s\n"));
- fmt % token % lex.text();
- string const s = fmt.str();
-#else
- string const s = _("Unknown token: ") + token
- + ' ' + lex.text() + '\n';
-#endif
- // we can do this here this way because we're actually reading
- // the buffer and don't care about LyXText right now.
- InsetError * new_inset = new InsetError(s);
- par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
- params.language));