X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_plaintext.cpp;h=15e700eb8f1cf564d92b0eb273483d2942234a3a;hb=57b69a5efddf9f3c148007322f00dad6c253a2ed;hp=4ee3390b3acef4f80deb5cbcd104358e2de6fa20;hpb=aac50f83e5fff71e74d58e1d4a35098cde2335ee;p=lyx.git diff --git a/src/output_plaintext.cpp b/src/output_plaintext.cpp index 4ee3390b3a..15e700eb8f 100644 --- a/src/output_plaintext.cpp +++ b/src/output_plaintext.cpp @@ -3,7 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * * Full author contact details are available in file CREDITS. */ @@ -34,9 +34,15 @@ namespace lyx { void writePlaintextFile(Buffer const & buf, FileName const & fname, OutputParams const & runparams) { - odocfstream ofs; + 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); } @@ -45,7 +51,7 @@ void writePlaintextFile(Buffer const & buf, odocstream & os, OutputParams const & runparams) { bool ref_printed = false; - ParagraphList const par = buf.paragraphs(); + ParagraphList const & par = buf.paragraphs(); ParagraphList::const_iterator beg = par.begin(); ParagraphList::const_iterator end = par.end(); ParagraphList::const_iterator it = beg; @@ -66,11 +72,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 +121,7 @@ void writePlaintextParagraph(Buffer const & buf, string::size_type currlinelen = 0; + odocstringstream os; os << docstring(depth * 2, ' '); currlinelen += depth * 2; @@ -177,6 +185,9 @@ void writePlaintextParagraph(Buffer const & buf, if (par.isDeleted(i)) continue; + if (os.str().size() > max_length) + break; + char_type c = par.getUChar(buf.params(), i); if (par.isInset(i) || c == ' ') { @@ -195,7 +206,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 +217,7 @@ void writePlaintextParagraph(Buffer const & buf, switch (c) { case ' ': os << ' '; - currlinelen++; + ++currlinelen; break; case '\0': @@ -231,6 +242,7 @@ void writePlaintextParagraph(Buffer const & buf, } os << word; } + ods << os.str(); }