X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_plaintext.cpp;h=9dae951f03915a0f9e2f14751e572d95014d9a1d;hb=0b9c27222a69f0ec657f008345ea812030596702;hp=97e3ab11270c5fab649507d74e8ae2a679c32a88;hpb=0778007050fd1b951f4ed03126893fb390f28b64;p=lyx.git diff --git a/src/output_plaintext.cpp b/src/output_plaintext.cpp index 97e3ab1127..9dae951f03 100644 --- a/src/output_plaintext.cpp +++ b/src/output_plaintext.cpp @@ -37,6 +37,12 @@ void writePlaintextFile(Buffer const & buf, FileName const & fname, ofdocstream ofs; if (!openFileWrite(ofs, fname)) return; + + // make sure we are ready to export + buf.updateBuffer(); + buf.updateMacroInstances(OutputUpdate); + buf.makeCitationLabels(); + writePlaintextFile(buf, ofs, runparams); } @@ -50,9 +56,11 @@ void writePlaintextFile(Buffer const & buf, odocstream & os, ParagraphList::const_iterator end = par.end(); ParagraphList::const_iterator it = beg; for (; it != end; ++it) { + bool const merged_par = (*it).parEndChange().deleted(); writePlaintextParagraph(buf, *it, os, runparams, ref_printed); - os << "\n"; - if (runparams.linelen > 0) + if (!merged_par) + os << "\n"; + if (runparams.linelen > 0 && !merged_par) os << "\n"; } } @@ -66,11 +74,12 @@ static pair addDepth(int depth, int ldepth) return make_pair(d, docstring(d, ' ')); } + void writePlaintextParagraph(Buffer const & buf, Paragraph const & par, - odocstream & os, + odocstream & ods, OutputParams const & runparams, - bool & ref_printed) + bool & ref_printed, size_t max_length) { int ltype = 0; depth_type ltype_depth = 0; @@ -114,6 +123,7 @@ void writePlaintextParagraph(Buffer const & buf, string::size_type currlinelen = 0; + odocstringstream os; os << docstring(depth * 2, ' '); currlinelen += depth * 2; @@ -177,7 +187,10 @@ void writePlaintextParagraph(Buffer const & buf, if (par.isDeleted(i)) continue; - char_type c = par.getUChar(buf.params(), i); + if (os.str().size() > max_length) + break; + + char_type c = par.getUChar(buf.params(), runparams, i); if (par.isInset(i) || c == ' ') { if (runparams.linelen > 0 && @@ -195,7 +208,7 @@ void writePlaintextParagraph(Buffer const & buf, if (par.isInset(i)) { OutputParams rp = runparams; rp.depth = par.params().depth(); - int len = par.getInset(i)->plaintext(os, rp); + int len = par.getInset(i)->plaintext(os, rp, max_length); if (len >= Inset::PLAINTEXT_NEWLINE) currlinelen = len - Inset::PLAINTEXT_NEWLINE; else @@ -206,7 +219,7 @@ void writePlaintextParagraph(Buffer const & buf, switch (c) { case ' ': os << ' '; - currlinelen++; + ++currlinelen; break; case '\0': @@ -231,6 +244,7 @@ void writePlaintextParagraph(Buffer const & buf, } os << word; } + ods << os.str(); }