+std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
+ OutputParams const & runparams,
+ Font const & outerfont,
+ pos_type initial,
+ bool is_last_par,
+ bool ignore_fonts) const
+{
+ // Track whether we have opened these tags
+ DocBookFontState fs;
+
+ Layout const & style = *d->layout_;
+ FontInfo font_old =
+ style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
+
+ string const default_family =
+ buf.masterBuffer()->params().fonts_default_family;
+
+ vector<xml::FontTag> tagsToOpen;
+ vector<xml::EndFontTag> tagsToClose;
+
+ std::vector<docstring> generatedParagraphs;
+ DocBookFontState old_fs = fs;
+ odocstringstream os;
+ auto * xs = new XMLStream(os); // XMLStream has no copy constructor: to create a new object, the only solution
+ // is to hold a pointer to the XMLStream (xs = XMLStream(os) is not allowed once the first object is built).
+
+ // When a font tag ends with a space, output it after the closing font tag. This requires to store delayed
+ // characters at some point.
+ std::vector<char_type> delayedChars;
+
+ // Parsing main loop.
+ for (pos_type i = initial; i < size(); ++i) {
+ // Don't show deleted material in the output.
+ if (isDeleted(i))
+ continue;
+
+ // If this is an InsetNewline, generate a new paragraph. Also reset the fonts, so that tags are closed in
+ // this paragraph.
+ if (getInset(i) && getInset(i)->lyxCode() == NEWLINE_CODE) {
+ if (!ignore_fonts)
+ xs->closeFontTags();
+
+ // Output one paragraph (i.e. one string entry in generatedParagraphs).
+ generatedParagraphs.push_back(os.str());
+
+ // Create a new XMLStream for the new paragraph, completely independent from the previous one. This implies
+ // that the string stream must be reset.
+ os.str(from_ascii(""));
+ delete xs;
+ xs = new XMLStream(os);
+
+ // Restore the fonts for the new paragraph, so that the right tags are opened for the new entry.
+ if (!ignore_fonts) {
+ font_old = outerfont.fontInfo();
+ fs = old_fs;
+ }
+ }
+
+ // Determine which tags should be opened or closed regarding fonts.
+ Font const font = getFont(buf.masterBuffer()->params(), i, outerfont);
+ if (!ignore_fonts) {
+ tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs);
+
+ // FIXME XHTML
+ // Other such tags? What about the other text ranges?
+
+ vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
+ vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
+ for (; cit != cen; ++cit)
+ *xs << *cit;
+
+ // Deal with the delayed characters *after* closing font tags.
+ if (!delayedChars.empty()) {
+ for (char_type c: delayedChars)
+ *xs << c;
+ delayedChars.clear();
+ }
+
+ vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
+ vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
+ for (; sit != sen; ++sit)
+ *xs << *sit;
+
+ tagsToClose.clear();
+ tagsToOpen.clear();
+ }