X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_plaintext.cpp;h=8c5655d39b6e315b7ab85743cbb94f67ae9b5ea5;hb=a6e3c59b94589c9043cd55ceaa3700849b4484dc;hp=ca67db49284b9d697a5f71e4fb3c206fd3b0e991;hpb=2bf1c09376de37a3d66b79ca5f4304f29d5b4d06;p=lyx.git diff --git a/src/output_plaintext.cpp b/src/output_plaintext.cpp index ca67db4928..8c5655d39b 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; @@ -58,9 +64,7 @@ void writePlaintextFile(Buffer const & buf, odocstream & os, } -namespace { - -pair const addDepth(int depth, int ldepth) +static pair addDepth(int depth, int ldepth) { int d = depth * 2; if (ldepth > depth) @@ -68,21 +72,19 @@ pair const 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; depth_type depth = par.params().depth(); // First write the layout - string const tmp = to_utf8(par.layout()->name()); + string const tmp = to_utf8(par.layout().name()); if (compare_ascii_no_case(tmp, "itemize") == 0) { ltype = 1; ltype_depth = depth + 1; @@ -119,6 +121,7 @@ void writePlaintextParagraph(Buffer const & buf, string::size_type currlinelen = 0; + odocstringstream os; os << docstring(depth * 2, ' '); currlinelen += depth * 2; @@ -182,7 +185,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 && @@ -200,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(buf, os, rp); + int len = par.getInset(i)->plaintext(os, rp, max_length); if (len >= Inset::PLAINTEXT_NEWLINE) currlinelen = len - Inset::PLAINTEXT_NEWLINE; else @@ -211,11 +217,11 @@ void writePlaintextParagraph(Buffer const & buf, switch (c) { case ' ': os << ' '; - currlinelen++; + ++currlinelen; break; case '\0': - LYXERR(Debug::INFO, "writePlaintextFile: NULL char in structure."); + LYXERR(Debug::INFO, "writePlaintextFile: NUL char in structure."); break; default: @@ -236,6 +242,7 @@ void writePlaintextParagraph(Buffer const & buf, } os << word; } + ods << os.str(); }