X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_plaintext.cpp;h=b0450bda9f3a731d68b19e8953f183e996cba7b7;hb=7261fa94482916cb9bf2ba0d21c4df390ea58320;hp=6252056646124da202544a9835069a8a23dfdd47;hpb=a746aa52146257c0e7a2d60123f63dccad5b2751;p=lyx.git diff --git a/src/output_plaintext.cpp b/src/output_plaintext.cpp index 6252056646..b0450bda9f 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. */ @@ -14,36 +14,37 @@ #include "Buffer.h" #include "BufferParams.h" -#include "debug.h" -#include "gettext.h" +#include "Layout.h" #include "output.h" #include "OutputParams.h" #include "Paragraph.h" #include "ParagraphList.h" #include "ParagraphParameters.h" +#include "insets/Inset.h" + +#include "support/debug.h" +#include "support/gettext.h" #include "support/lstrings.h" +using namespace std; +using namespace lyx::support; namespace lyx { -using support::ascii_lowercase; -using support::compare_ascii_no_case; -using support::contains; -using support::FileName; - -using std::endl; -using std::ostream; -using std::pair; -using std::string; - 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); } @@ -52,22 +53,22 @@ 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; 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"; } } -namespace { - -pair const addDepth(int depth, int ldepth) +static pair addDepth(int depth, int ldepth) { int d = depth * 2; if (ldepth > depth) @@ -75,21 +76,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 = 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; @@ -126,12 +125,13 @@ void writePlaintextParagraph(Buffer const & buf, string::size_type currlinelen = 0; + odocstringstream os; os << docstring(depth * 2, ' '); currlinelen += depth * 2; //-- // we should probably change to the paragraph language in the - // gettext here (if possible) so that strings are output in + // support/gettext.here (if possible) so that strings are output in // the correct language! (20012712 Jug) //-- switch (ltype) { @@ -189,9 +189,12 @@ 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 (c == Paragraph::META_INSET || c == ' ') { + if (par.isInset(i) || c == ' ') { if (runparams.linelen > 0 && currlinelen + word.length() > runparams.linelen) { os << '\n'; @@ -204,26 +207,25 @@ void writePlaintextParagraph(Buffer const & buf, word.erase(); } - switch (c) { - case Paragraph::META_INSET: { + 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 currlinelen += len; - break; + continue; } + switch (c) { case ' ': os << ' '; - currlinelen++; + ++currlinelen; break; case '\0': - LYXERR(Debug::INFO) << - "writePlaintextFile: NULL char in structure." << endl; + LYXERR(Debug::INFO, "writePlaintextFile: NUL char in structure."); break; default: @@ -244,6 +246,7 @@ void writePlaintextParagraph(Buffer const & buf, } os << word; } + ods << os.str(); }