*
* \author Asger Alstrup
* \author Lars Gullik Bjønnes
+ * \author Richard Heck (XHTML output)
* \author Jean-Marc Lasgouttes
* \author Angus Leeming
* \author John Levon
OutputParams const & runparams);
///
- void validate(LaTeXFeatures & features,
- Layout const & layout) const;
+ void validate(LaTeXFeatures & features) const;
/// Checks if the paragraph contains only text and no inset or font change.
bool onlyText(Buffer const & buf, Font const & outerfont,
}
-void Paragraph::Private::validate(LaTeXFeatures & features,
- Layout const & layout) const
+void Paragraph::Private::validate(LaTeXFeatures & features) const
{
// check the params.
if (!params_.spacing().isDefault())
features.require("setspace");
// then the layouts
- features.useLayout(layout.name());
+ features.useLayout(layout_->name());
// then the fonts
fontlist_.validate(features);
for (; icit != iend; ++icit) {
if (icit->inset) {
icit->inset->validate(features);
- if (layout.needprotect &&
+ if (layout_->needprotect &&
icit->inset->lyxCode() == FOOT_CODE)
features.require("NeedLyXFootnoteCode");
}
}
+namespace {
+
+// this shall be called just before every "os << ..." action.
+void flushString(ostream & os, docstring & s)
+{
+ os << to_utf8(s);
+ s.erase();
+}
+
+}
+
+
void Paragraph::write(ostream & os, BufferParams const & bparams,
depth_type & dth) const
{
Change running_change = Change(Change::UNCHANGED);
+ // this string is used as a buffer to avoid repetitive calls
+ // to to_utf8(), which turn out to be expensive (JMarc)
+ docstring write_buffer;
+
int column = 0;
for (pos_type i = 0; i <= size(); ++i) {
Change const change = lookupChange(i);
+ if (change != running_change)
+ flushString(os, write_buffer);
Changes::lyxMarkChange(os, bparams, column, running_change, change);
running_change = change;
Font font2 = getFontSettings(bparams, i);
font2.setMisspelled(false);
if (font2 != font1) {
+ flushString(os, write_buffer);
font2.lyxWriteChanges(font1, os);
column = 0;
font1 = font2;
switch (c) {
case META_INSET:
if (Inset const * inset = getInset(i)) {
+ flushString(os, write_buffer);
if (inset->directWrite()) {
// international char, let it write
// code directly so it's shorter in
}
break;
case '\\':
+ flushString(os, write_buffer);
os << "\n\\backslash\n";
column = 0;
break;
case '.':
+ flushString(os, write_buffer);
if (i + 1 < size() && d->text_[i + 1] == ' ') {
os << ".\n";
column = 0;
default:
if ((column > 70 && c == ' ')
|| column > 79) {
+ flushString(os, write_buffer);
os << '\n';
column = 0;
}
// this check is to amend a bug. LyX sometimes
// inserts '\0' this could cause problems.
if (c != '\0')
- os << to_utf8(docstring(1, c));
+ write_buffer.push_back(c);
else
LYXERR0("NUL char in structure.");
++column;
}
}
+ flushString(os, write_buffer);
os << "\n\\end_layout\n";
}
void Paragraph::validate(LaTeXFeatures & features) const
{
- d->validate(features, *d->layout_);
+ d->validate(features);
}
}
-pos_type Paragraph::firstWordLyXHTML(odocstream & os, OutputParams const & runparams)
+pos_type Paragraph::firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams)
const
{
pos_type i;
for (i = 0; i < size(); ++i) {
if (Inset const * inset = getInset(i)) {
- inset->xhtml(os, runparams);
+ inset->xhtml(xs, runparams);
} else {
char_type c = d->text_[i];
if (c == ' ')
break;
- os << html::escapeChar(c);
+ xs << html::escapeChar(c);
}
}
return i;
docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
- odocstream & os,
+ XHTMLStream & xs,
OutputParams const & runparams,
Font const & outerfont,
pos_type initial) const
FontInfo font_old =
style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
- //if (style.pass_thru && !d->onlyText(buf, outerfont, initial))
- // os << "]]>";
-
// parsing main loop
for (pos_type i = initial; i < size(); ++i) {
Font font = getFont(buf.params(), i, outerfont);
// emphasis
if (font_old.emph() != font.fontInfo().emph()) {
if (font.fontInfo().emph() == FONT_ON) {
- os << "<em>";
+ xs << StartTag("em");
emph_flag = true;
} else if (emph_flag && i != initial) {
- os << "</em>";
+ xs << EndTag("em");
emph_flag = false;
}
}
// bold
if (font_old.series() != font.fontInfo().series()) {
if (font.fontInfo().series() == BOLD_SERIES) {
- os << "<strong>";
+ xs << StartTag("strong");
bold_flag = true;
} else if (bold_flag && i != initial) {
- os << "</strong>";
+ xs << EndTag("strong");
bold_flag = false;
}
}
// FIXME Other such tags?
- if (Inset const * inset = getInset(i)) {
- retval += inset->xhtml(os, runparams);
+ Inset const * inset = getInset(i);
+ if (inset) {
+ InsetLayout const & il = inset->getLayout();
+ OutputParams np = runparams;
+ if (!il.htmlisblock())
+ np.html_in_par = true;
+ retval += inset->xhtml(xs, np);
} else {
char_type c = d->text_[i];
if (style.pass_thru)
- os.put(c);
+ xs << c;
else if (c == '-') {
docstring str;
int j = i + 1;
}
else
str += c;
- os << str;
+ xs << str;
} else
- os << html::escapeChar(c);
+ xs << c;
}
font_old = font.fontInfo();
}
- // FIXME This could be out of order. See above.
- if (emph_flag)
- os << "</em>";
- if (bold_flag)
- os << "</strong>";
-
+ xs.closeFontTags();
return retval;
}
// There was no inset at the beginning, so we need to create one with
// the key and label of the one we erased.
InsetBibitem * inset =
- new InsetBibitem(buffer, InsetCommandParams(BIBITEM_CODE));
+ new InsetBibitem(const_cast<Buffer *>(&buffer), InsetCommandParams(BIBITEM_CODE));
// restore values of previously deleted item in this par.
if (!oldkey.empty())
inset->setParam("key", oldkey);