Introduce max_length parameter for plaintext() output routines,

so we can write a limited amount when using this for TOC and
tooltip output.

This should solve the problem with slowness that Kornel noticed,
which was caused by our trying to write an entire plaintext
bibliography every time we updated the TOC. We did that because
he had a bibliography inside a branch, and we use plaintext for
creating the tooltip that goes with the branch list.

Other related bugs were fixed along the way. E.g., it turns out
that, if someone had an InsetInclude inside a branch, then we would
have been writing a *plaintext file* for that inset every time we
updated the TOC. I wonder if some of the other reports of slowness
we have received might be due to this kind of issue?
This commit is contained in:
Richard Heck 2013-03-08 14:52:18 -05:00
parent f6480263e5
commit ecef54500d
86 changed files with 267 additions and 150 deletions

View File

@ -30,7 +30,7 @@ OutputParams::OutputParams(Encoding const * enc)
par_begin(0), par_end(0), lastid(-1), lastpos(-1), isLastPar(false), par_begin(0), par_end(0), lastid(-1), lastpos(-1), isLastPar(false),
dryrun(false), pass_thru(false), dryrun(false), pass_thru(false),
html_disable_captions(false), html_in_par(false), html_disable_captions(false), html_in_par(false),
html_make_pars(true), for_toc(false), includeall(false) html_make_pars(true), for_toc(false), for_tooltip(false), includeall(false)
{ {
// Note: in PreviewLoader::Impl::dumpPreamble // Note: in PreviewLoader::Impl::dumpPreamble
// OutputParams runparams(0); // OutputParams runparams(0);

View File

@ -261,6 +261,9 @@ public:
/// Are we generating this material for inclusion in a TOC-like entity? /// Are we generating this material for inclusion in a TOC-like entity?
bool for_toc; bool for_toc;
/// Are we generating this material for inclusion in a tooltip?
bool for_tooltip;
/// Include all children notwithstanding the use of \includeonly /// Include all children notwithstanding the use of \includeonly
bool includeall; bool includeall;

View File

@ -1046,7 +1046,9 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
LASSERT(inset, /**/); LASSERT(inset, /**/);
if (style.pass_thru) { if (style.pass_thru) {
inset->plaintext(os.os(), runparams); odocstringstream ods;
inset->plaintext(ods, runparams);
os << ods.str();
return; return;
} }

View File

@ -231,14 +231,18 @@ Toc::iterator Toc::item(int depth, docstring const & str)
} }
void TocBackend::writePlaintextTocList(string const & type, odocstream & os) const void TocBackend::writePlaintextTocList(string const & type,
odocstringstream & os, size_t max_length) const
{ {
TocList::const_iterator cit = tocs_.find(type); TocList::const_iterator cit = tocs_.find(type);
if (cit != tocs_.end()) { if (cit != tocs_.end()) {
TocIterator ccit = cit->second.begin(); TocIterator ccit = cit->second.begin();
TocIterator end = cit->second.end(); TocIterator end = cit->second.end();
for (; ccit != end; ++ccit) for (; ccit != end; ++ccit) {
os << ccit->asString() << from_utf8("\n"); os << ccit->asString() << from_utf8("\n");
if (os.str().size() > max_length)
break;
}
} }
} }

View File

@ -128,7 +128,8 @@ public:
) const; ) const;
/// ///
void writePlaintextTocList(std::string const & type, odocstream & os) const; void writePlaintextTocList(std::string const & type,
odocstringstream & os, size_t max_length) const;
private: private:
/// ///

View File

@ -24,6 +24,8 @@
#include "support/strfwd.h" #include "support/strfwd.h"
#include "support/types.h" #include "support/types.h"
#include <climits>
namespace lyx { namespace lyx {
@ -314,7 +316,8 @@ public:
/// plain text output in ucs4 encoding /// plain text output in ucs4 encoding
/// return the number of characters; in case of multiple lines of /// return the number of characters; in case of multiple lines of
/// output, add PLAINTEXT_NEWLINE to the number of chars in the last line /// output, add PLAINTEXT_NEWLINE to the number of chars in the last line
virtual int plaintext(odocstream &, OutputParams const &) const = 0; virtual int plaintext(odocstringstream &, OutputParams const &,
size_t max_length = INT_MAX) const = 0;
/// docbook output /// docbook output
virtual int docbook(odocstream & os, OutputParams const &) const; virtual int docbook(odocstream & os, OutputParams const &) const;
/// XHTML output /// XHTML output

View File

@ -49,7 +49,7 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const { } void latex(otexstream &, OutputParams const &) const { }
/// ///
int plaintext(odocstream &, OutputParams const &) const { return 0; } int plaintext(odocstringstream &, OutputParams const &, int) const { return 0; }
/// ///
int docbook(odocstream &, OutputParams const &) const { return 0; } int docbook(odocstream &, OutputParams const &) const { return 0; }
/// ///

View File

@ -216,7 +216,8 @@ docstring InsetBibitem::screenLabel() const
} }
int InsetBibitem::plaintext(odocstream & os, OutputParams const &) const int InsetBibitem::plaintext(odocstringstream & os,
OutputParams const &, int) const
{ {
odocstringstream oss; odocstringstream oss;
oss << '[' << bibLabel() << "] "; oss << '[' << bibLabel() << "] ";

View File

@ -55,7 +55,8 @@ public:
/// ///
void read(Lexer & lex); void read(Lexer & lex);
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream &, OutputParams const &,
int max_length) const;
/// ///
docstring xhtml(XHTMLStream &, OutputParams const &) const; docstring xhtml(XHTMLStream &, OutputParams const &) const;
/// ///

View File

@ -928,12 +928,14 @@ void InsetBibtex::validate(LaTeXFeatures & features) const
} }
int InsetBibtex::plaintext(odocstream & os, OutputParams const &) const int InsetBibtex::plaintext(odocstringstream & os,
OutputParams const &, size_t max_length) const
{ {
BiblioInfo bibinfo = buffer().masterBibInfo(); BiblioInfo bibinfo = buffer().masterBibInfo();
bibinfo.makeCitationLabels(buffer()); bibinfo.makeCitationLabels(buffer());
vector<docstring> const & cites = bibinfo.citedEntries(); vector<docstring> const & cites = bibinfo.citedEntries();
size_t start_size = os.str().size();
docstring refoutput; docstring refoutput;
docstring const reflabel = buffer().B_("References"); docstring const reflabel = buffer().B_("References");
@ -943,6 +945,8 @@ int InsetBibtex::plaintext(odocstream & os, OutputParams const &) const
vector<docstring>::const_iterator vit = cites.begin(); vector<docstring>::const_iterator vit = cites.begin();
vector<docstring>::const_iterator const ven = cites.end(); vector<docstring>::const_iterator const ven = cites.end();
for (; vit != ven; ++vit) { for (; vit != ven; ++vit) {
if (start_size + refoutput.size() >= max_length)
break;
BiblioInfo::const_iterator const biit = bibinfo.find(*vit); BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
if (biit == bibinfo.end()) if (biit == bibinfo.end())
continue; continue;

View File

@ -52,7 +52,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
void collectBibKeys(InsetIterator const &) const; void collectBibKeys(InsetIterator const &) const;
/// ///

View File

@ -440,7 +440,8 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetBox::plaintext(odocstream & os, OutputParams const & runparams) const int InsetBox::plaintext(odocstringstream & os,
OutputParams const & runparams, size_t max_length) const
{ {
BoxType const btype = boxtranslator().find(params_.type); BoxType const btype = boxtranslator().find(params_.type);
@ -466,7 +467,7 @@ int InsetBox::plaintext(odocstream & os, OutputParams const & runparams) const
break; break;
} }
InsetText::plaintext(os, runparams); InsetText::plaintext(os, runparams, max_length);
int len = 0; int len = 0;
switch (btype) { switch (btype) {

View File

@ -114,7 +114,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -262,13 +262,13 @@ void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetBranch::plaintext(odocstream & os, int InsetBranch::plaintext(odocstringstream & os,
OutputParams const & runparams) const OutputParams const & runparams, size_t max_length) const
{ {
if (!isBranchSelected()) if (!isBranchSelected())
return 0; return 0;
int len = InsetText::plaintext(os, runparams); int len = InsetText::plaintext(os, runparams, max_length);
return len; return len;
} }

View File

@ -67,7 +67,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -279,11 +279,11 @@ void InsetCaption::latex(otexstream & os,
} }
int InsetCaption::plaintext(odocstream & os, int InsetCaption::plaintext(odocstringstream & os,
OutputParams const & runparams) const OutputParams const & runparams, size_t max_length) const
{ {
os << '[' << full_label_ << "\n"; os << '[' << full_label_ << "\n";
InsetText::plaintext(os, runparams); InsetText::plaintext(os, runparams, max_length);
os << "\n]"; os << "\n]";
return PLAINTEXT_NEWLINE + 1; // one char on a separate line return PLAINTEXT_NEWLINE + 1; // one char on a separate line
@ -350,7 +350,9 @@ int InsetCaption::getCaptionAsPlaintext(odocstream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
os << full_label_ << ' '; os << full_label_ << ' ';
return InsetText::plaintext(os, runparams); odocstringstream ods;
return InsetText::plaintext(ods, runparams);
os << ods.str();
} }

View File

@ -71,7 +71,8 @@ private:
/// ///
void latex(otexstream & os, OutputParams const &) const; void latex(otexstream & os, OutputParams const &) const;
/// ///
int plaintext(odocstream & os, OutputParams const & runparams) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream & os, OutputParams const & runparams) const; int docbook(odocstream & os, OutputParams const & runparams) const;
/// ///

View File

@ -342,7 +342,8 @@ void InsetCitation::addToToc(DocIterator const & cpit) const
} }
int InsetCitation::plaintext(odocstream & os, OutputParams const &) const int InsetCitation::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
string const & cmd = getCmdName(); string const & cmd = getCmdName();
if (cmd == "nocite") if (cmd == "nocite")
@ -396,7 +397,9 @@ docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const
void InsetCitation::toString(odocstream & os) const void InsetCitation::toString(odocstream & os) const
{ {
plaintext(os, OutputParams(0)); odocstringstream ods;
plaintext(ods, OutputParams(0));
os << ods.str();
} }

View File

@ -52,7 +52,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -126,7 +126,8 @@ void InsetCommand::latex(otexstream & os, OutputParams const & runparams_in) con
} }
int InsetCommand::plaintext(odocstream & os, OutputParams const &) const int InsetCommand::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
docstring const str = "[" + buffer().B_("LaTeX Command: ") docstring const str = "[" + buffer().B_("LaTeX Command: ")
+ from_utf8(getCmdName()) + "]"; + from_utf8(getCmdName()) + "]";

View File

@ -78,7 +78,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const & runparams) const; int docbook(odocstream &, OutputParams const & runparams) const;
/// ///

View File

@ -53,7 +53,8 @@ void InsetERT::write(ostream & os) const
} }
int InsetERT::plaintext(odocstream & os, OutputParams const & rp) const int InsetERT::plaintext(odocstringstream & os,
OutputParams const & rp, size_t max_length) const
{ {
if (!rp.inIndexEntry) if (!rp.inIndexEntry)
// do not output TeX code // do not output TeX code
@ -62,7 +63,7 @@ int InsetERT::plaintext(odocstream & os, OutputParams const & rp) const
ParagraphList::const_iterator par = paragraphs().begin(); ParagraphList::const_iterator par = paragraphs().begin();
ParagraphList::const_iterator end = paragraphs().end(); ParagraphList::const_iterator end = paragraphs().end();
while (par != end) { while (par != end && os.str().size() <= max_length) {
pos_type siz = par->size(); pos_type siz = par->size();
for (pos_type i = 0; i < siz; ++i) { for (pos_type i = 0; i < siz; ++i) {
char_type const c = par->getChar(i); char_type const c = par->getChar(i);

View File

@ -48,7 +48,8 @@ private:
/// ///
void write(std::ostream & os) const; void write(std::ostream & os) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -691,8 +691,8 @@ void InsetExternal::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetExternal::plaintext(odocstream & os, int InsetExternal::plaintext(odocstringstream & os,
OutputParams const & runparams) const OutputParams const & runparams, size_t) const
{ {
os << '\n'; // output external material on a new line os << '\n'; // output external material on a new line
external::writeExternal(params_, "Ascii", buffer(), os, external::writeExternal(params_, "Ascii", buffer(), os,

View File

@ -132,7 +132,8 @@ private:
/// ///
void read(Lexer & lex); void read(Lexer & lex);
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// For now, this does nothing. Someone who knows about this /// For now, this does nothing. Someone who knows about this

View File

@ -389,11 +389,11 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const
} }
int InsetFloat::plaintext(odocstream & os, OutputParams const & runparams) const int InsetFloat::plaintext(odocstringstream & os, OutputParams const & runparams, size_t max_length) const
{ {
os << '[' << buffer().B_("float") << ' ' os << '[' << buffer().B_("float") << ' '
<< floatName(params_.type) << ":\n"; << floatName(params_.type) << ":\n";
InsetText::plaintext(os, runparams); InsetText::plaintext(os, runparams, max_length);
os << "\n]"; os << "\n]";
return PLAINTEXT_NEWLINE + 1; // one char on a separate line return PLAINTEXT_NEWLINE + 1; // one char on a separate line

View File

@ -85,7 +85,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -160,11 +160,12 @@ void InsetFloatList::latex(otexstream & os, OutputParams const &) const
} }
int InsetFloatList::plaintext(odocstream & os, OutputParams const &) const int InsetFloatList::plaintext(odocstringstream & os,
OutputParams const &, size_t max_length) const
{ {
os << screenLabel() << "\n\n"; os << screenLabel() << "\n\n";
buffer().tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os); buffer().tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os, max_length);
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;
} }

View File

@ -42,7 +42,8 @@ public:
/// ///
int docbook(odocstream &, OutputParams const &) const { return 0; } int docbook(odocstream &, OutputParams const &) const { return 0; }
/// ///
int plaintext(odocstream &, OutputParams const & runparams) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
docstring xhtml(XHTMLStream &, OutputParams const &) const; docstring xhtml(XHTMLStream &, OutputParams const &) const;
/// ///

View File

@ -107,10 +107,11 @@ void InsetFoot::latex(otexstream & os, OutputParams const & runparams_in) const
} }
int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const int InsetFoot::plaintext(odocstringstream & os,
OutputParams const & runparams, size_t max_length) const
{ {
os << '[' << buffer().B_("footnote") << ":\n"; os << '[' << buffer().B_("footnote") << ":\n";
InsetText::plaintext(os, runparams); InsetText::plaintext(os, runparams, max_length);
os << "\n]"; os << "\n]";
return PLAINTEXT_NEWLINE + 1; // one char on a separate line return PLAINTEXT_NEWLINE + 1; // one char on a separate line

View File

@ -34,7 +34,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// Update the counters of this inset and of its contents /// Update the counters of this inset and of its contents

View File

@ -809,7 +809,8 @@ void InsetGraphics::latex(otexstream & os,
} }
int InsetGraphics::plaintext(odocstream & os, OutputParams const &) const int InsetGraphics::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
// No graphics in ascii output. Possible to use gifscii to convert // No graphics in ascii output. Possible to use gifscii to convert
// images to ascii approximation. // images to ascii approximation.

View File

@ -74,7 +74,8 @@ private:
*/ */
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -209,7 +209,8 @@ void InsetHyperlink::latex(otexstream & os,
} }
int InsetHyperlink::plaintext(odocstream & os, OutputParams const &) const int InsetHyperlink::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
odocstringstream oss; odocstringstream oss;
@ -250,7 +251,9 @@ docstring InsetHyperlink::xhtml(XHTMLStream & xs, OutputParams const &) const
void InsetHyperlink::toString(odocstream & os) const void InsetHyperlink::toString(odocstream & os) const
{ {
plaintext(os, OutputParams(0)); odocstringstream ods;
plaintext(ods, OutputParams(0), INT_MAX);
os << ods.str();
} }

View File

@ -48,7 +48,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -281,11 +281,11 @@ void InsetIPADeco::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetIPADeco::plaintext(odocstream & os, int InsetIPADeco::plaintext(odocstringstream & os,
OutputParams const & runparams) const OutputParams const & runparams, size_t max_length) const
{ {
odocstringstream ods; odocstringstream ods;
int h = (int)(InsetCollapsable::plaintext(ods, runparams) / 2); int h = (int)(InsetCollapsable::plaintext(ods, runparams, max_length) / 2);
docstring result = ods.str(); docstring result = ods.str();
docstring const before = result.substr(0, h); docstring const before = result.substr(0, h);
docstring const after = result.substr(h, result.size()); docstring const after = result.substr(h, result.size());
@ -512,7 +512,7 @@ void InsetIPAChar::latex(otexstream & os,
} }
int InsetIPAChar::plaintext(odocstream & os, OutputParams const &) const int InsetIPAChar::plaintext(odocstringstream & os, OutputParams const &, size_t) const
{ {
switch (kind_) { switch (kind_) {
case TONE_FALLING: case TONE_FALLING:
@ -588,7 +588,9 @@ docstring InsetIPAChar::xhtml(XHTMLStream & xs, OutputParams const &) const
void InsetIPAChar::toString(odocstream & os) const void InsetIPAChar::toString(odocstream & os) const
{ {
plaintext(os, OutputParams(0)); odocstringstream ods;
plaintext(ods, OutputParams(0));
os << ods.str();
} }

View File

@ -76,7 +76,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///
@ -146,7 +147,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -810,9 +810,11 @@ docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const
} }
int InsetInclude::plaintext(odocstream & os, OutputParams const & op) const int InsetInclude::plaintext(odocstringstream & os,
OutputParams const & op, size_t) const
{ {
if (isVerbatim(params()) || isListings(params())) { // don't write the file just because we're making a tooltip or toc entry!!
if (op.for_tooltip || op.for_toc || isVerbatim(params()) || isListings(params())) {
os << '[' << screenLabel() << '\n'; os << '[' << screenLabel() << '\n';
// FIXME: We don't know the encoding of the file, default to UTF-8. // FIXME: We don't know the encoding of the file, default to UTF-8.
os << includedFileName(buffer(), params()).fileContents("UTF-8"); os << includedFileName(buffer(), params()).fileContents("UTF-8");

View File

@ -91,7 +91,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -37,8 +37,8 @@
#include "frontends/alert.h" #include "frontends/alert.h"
#include <ostream>
#include <algorithm> #include <algorithm>
#include <ostream>
using namespace std; using namespace std;
using namespace lyx::support; using namespace lyx::support;

View File

@ -254,7 +254,8 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
} }
int InsetLabel::plaintext(odocstream & os, OutputParams const &) const int InsetLabel::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
docstring const str = getParam("name"); docstring const str = getParam("name");
os << '<' << str << '>'; os << '<' << str << '>';

View File

@ -48,7 +48,8 @@ public:
/// ///
InsetCode lyxCode() const { return LABEL_CODE; } InsetCode lyxCode() const { return LABEL_CODE; }
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -185,7 +185,8 @@ void InsetLine::latex(otexstream & os, OutputParams const &) const
} }
int InsetLine::plaintext(odocstream & os, OutputParams const &) const int InsetLine::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
os << "\n-------------------------------------------\n"; os << "\n-------------------------------------------\n";
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;

View File

@ -49,7 +49,8 @@ private:
void metrics(MetricsInfo &, Dimension &) const; void metrics(MetricsInfo &, Dimension &) const;
void draw(PainterInfo & pi, int x, int y) const; void draw(PainterInfo & pi, int x, int y) const;
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
void doDispatch(Cursor & cur, FuncRequest & cmd); void doDispatch(Cursor & cur, FuncRequest & cmd);
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
Inset * clone() const { return new InsetLine(*this); } Inset * clone() const { return new InsetLine(*this); }

View File

@ -29,11 +29,11 @@ InsetMarginal::InsetMarginal(Buffer * buf)
{} {}
int InsetMarginal::plaintext(odocstream & os, int InsetMarginal::plaintext(odocstringstream & os,
OutputParams const & runparams) const OutputParams const & runparams, size_t max_length) const
{ {
os << '[' << buffer().B_("margin") << ":\n"; os << '[' << buffer().B_("margin") << ":\n";
InsetText::plaintext(os, runparams); InsetText::plaintext(os, runparams, max_length);
os << "\n]"; os << "\n]";
return PLAINTEXT_NEWLINE + 1; // one char on a separate line return PLAINTEXT_NEWLINE + 1; // one char on a separate line

View File

@ -31,7 +31,8 @@ public:
/// ///
docstring layoutName() const { return from_ascii("Marginal"); } docstring layoutName() const { return from_ascii("Marginal"); }
/// ///
int plaintext(odocstream &, OutputParams const & runparams) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const & runparams) const; int docbook(odocstream &, OutputParams const & runparams) const;
/// ///

View File

@ -161,7 +161,8 @@ void InsetNewline::latex(otexstream & os, OutputParams const & rp) const
} }
int InsetNewline::plaintext(odocstream & os, OutputParams const &) const int InsetNewline::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
os << '\n'; os << '\n';
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;

View File

@ -62,7 +62,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -235,7 +235,8 @@ void InsetNewpage::latex(otexstream & os, OutputParams const &) const
} }
int InsetNewpage::plaintext(odocstream & os, OutputParams const &) const int InsetNewpage::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
os << '\n'; os << '\n';
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;

View File

@ -65,7 +65,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -253,8 +253,8 @@ void InsetNote::latex(otexstream & os, OutputParams const & runparams_in) const
} }
int InsetNote::plaintext(odocstream & os, int InsetNote::plaintext(odocstringstream & os,
OutputParams const & runparams_in) const OutputParams const & runparams_in, size_t max_length) const
{ {
if (params_.type == InsetNoteParams::Note) if (params_.type == InsetNoteParams::Note)
return 0; return 0;
@ -266,7 +266,7 @@ int InsetNote::plaintext(odocstream & os,
runparams.exportdata.reset(new ExportData); runparams.exportdata.reset(new ExportData);
} }
os << '[' << buffer().B_("note") << ":\n"; os << '[' << buffer().B_("note") << ":\n";
InsetText::plaintext(os, runparams); InsetText::plaintext(os, runparams, max_length);
os << "\n]"; os << "\n]";
return PLAINTEXT_NEWLINE + 1; // one char on a separate line return PLAINTEXT_NEWLINE + 1; // one char on a separate line

View File

@ -85,7 +85,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -320,8 +320,8 @@ void InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetPhantom::plaintext(odocstream & os, int InsetPhantom::plaintext(odocstringstream & os,
OutputParams const & runparams) const OutputParams const & runparams, size_t max_length) const
{ {
if (params_.type == InsetPhantomParams::Phantom) if (params_.type == InsetPhantomParams::Phantom)
os << '[' << buffer().B_("phantom") << ":"; os << '[' << buffer().B_("phantom") << ":";
@ -329,7 +329,7 @@ int InsetPhantom::plaintext(odocstream & os,
os << '[' << buffer().B_("hphantom") << ":"; os << '[' << buffer().B_("hphantom") << ":";
else if (params_.type == InsetPhantomParams::VPhantom) else if (params_.type == InsetPhantomParams::VPhantom)
os << '[' << buffer().B_("vphantom") << ":"; os << '[' << buffer().B_("vphantom") << ":";
InsetCollapsable::plaintext(os, runparams); InsetCollapsable::plaintext(os, runparams, max_length);
os << "]"; os << "]";
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;

View File

@ -78,7 +78,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// Makes no sense fof XHTML. /// Makes no sense fof XHTML.

View File

@ -298,7 +298,8 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetQuotes::plaintext(odocstream & os, OutputParams const &) const int InsetQuotes::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
docstring const str = displayString(); docstring const str = displayString();
os << str; os << str;

View File

@ -80,7 +80,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -172,7 +172,8 @@ void InsetRef::latex(otexstream & os, OutputParams const & rp) const
} }
int InsetRef::plaintext(odocstream & os, OutputParams const &) const int InsetRef::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
docstring const str = getParam("reference"); docstring const str = getParam("reference");
os << '[' << str << ']'; os << '[' << str << ']';
@ -246,7 +247,9 @@ docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const
void InsetRef::toString(odocstream & os) const void InsetRef::toString(odocstream & os) const
{ {
plaintext(os, OutputParams(0)); odocstringstream ods;
plaintext(ods, OutputParams(0));
os << ods.str();
} }

View File

@ -53,7 +53,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -313,11 +313,11 @@ docstring InsetScript::toolTip(BufferView const &, int, int) const
{ {
OutputParams rp(&buffer().params().encoding()); OutputParams rp(&buffer().params().encoding());
odocstringstream ods; odocstringstream ods;
InsetText::plaintext(ods, rp); InsetText::plaintext(ods, rp, 200);
docstring content_tip = ods.str(); docstring content_tip = ods.str();
// shorten it if necessary // shorten it if necessary
if (content_tip.size() > 200) if (content_tip.size() >= 200)
content_tip = content_tip.substr(0, 200) + "..."; content_tip = content_tip.substr(0, 197) + "...";
docstring res = scripttranslator_loc().find(params_.type); docstring res = scripttranslator_loc().find(params_.type);
if (!content_tip.empty()) if (!content_tip.empty())
res += from_ascii(": ") + content_tip; res += from_ascii(": ") + content_tip;
@ -325,10 +325,11 @@ docstring InsetScript::toolTip(BufferView const &, int, int) const
} }
int InsetScript::plaintext(odocstream & os, OutputParams const & runparams) const int InsetScript::plaintext(odocstringstream & os,
OutputParams const & runparams, size_t max_length) const
{ {
odocstringstream oss; odocstringstream oss;
InsetText::plaintext(oss, runparams); InsetText::plaintext(oss, runparams, max_length);
docstring const text = oss.str(); docstring const text = oss.str();
switch (params_.type) { switch (params_.type) {
case InsetScriptParams::Subscript: case InsetScriptParams::Subscript:
@ -352,7 +353,7 @@ int InsetScript::plaintext(odocstream & os, OutputParams const & runparams) cons
os << '[' << buffer().B_("superscript") << ':'; os << '[' << buffer().B_("superscript") << ':';
break; break;
} }
InsetText::plaintext(os, runparams); InsetText::plaintext(os, runparams, max_length);
os << ']'; os << ']';
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;

View File

@ -82,7 +82,8 @@ public:
/// ///
bool neverIndent() const { return true; } bool neverIndent() const { return true; }
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -621,7 +621,8 @@ void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetSpace::plaintext(odocstream & os, OutputParams const &) const int InsetSpace::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
switch (params_.kind) { switch (params_.kind) {
case InsetSpaceParams::HFILL: case InsetSpaceParams::HFILL:
@ -813,7 +814,9 @@ void InsetSpace::validate(LaTeXFeatures & features) const
void InsetSpace::toString(odocstream & os) const void InsetSpace::toString(odocstream & os) const
{ {
plaintext(os, OutputParams(0)); odocstringstream ods;
plaintext(ods, OutputParams(0));
os << ods.str();
} }

View File

@ -124,7 +124,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -239,7 +239,8 @@ void InsetSpecialChar::latex(otexstream & os,
} }
int InsetSpecialChar::plaintext(odocstream & os, OutputParams const &) const int InsetSpecialChar::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
switch (kind_) { switch (kind_) {
case HYPHENATION: case HYPHENATION:
@ -329,8 +330,11 @@ void InsetSpecialChar::toString(odocstream & os) const
// Spell checker would choke on it. // Spell checker would choke on it.
return; return;
default: default:
plaintext(os, OutputParams(0)); break;
} }
odocstringstream ods;
plaintext(ods, OutputParams(0));
os << ods.str();
} }

View File

@ -61,7 +61,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -110,10 +110,11 @@ void InsetTOC::validate(LaTeXFeatures & features) const
} }
int InsetTOC::plaintext(odocstream & os, OutputParams const &) const int InsetTOC::plaintext(odocstringstream & os,
OutputParams const &, size_t max_length) const
{ {
os << screenLabel() << "\n\n"; os << screenLabel() << "\n\n";
buffer().tocBackend().writePlaintextTocList(cmd2type(getCmdName()), os); buffer().tocBackend().writePlaintextTocList(cmd2type(getCmdName()), os, max_length);
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;
} }

View File

@ -38,7 +38,8 @@ public:
/// ///
virtual void validate(LaTeXFeatures &) const; virtual void validate(LaTeXFeatures &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -64,10 +64,10 @@
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <sstream> #include <cstring>
#include <iostream> #include <iostream>
#include <limits> #include <limits>
#include <cstring> #include <sstream>
using namespace std; using namespace std;
using namespace lyx::support; using namespace lyx::support;
@ -3086,7 +3086,7 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
} }
bool Tabular::plaintextTopHLine(odocstream & os, row_type row, bool Tabular::plaintextTopHLine(odocstringstream & os, row_type row,
vector<unsigned int> const & clen) const vector<unsigned int> const & clen) const
{ {
idx_type const fcell = getFirstCellInRow(row); idx_type const fcell = getFirstCellInRow(row);
@ -3134,7 +3134,7 @@ bool Tabular::plaintextTopHLine(odocstream & os, row_type row,
} }
bool Tabular::plaintextBottomHLine(odocstream & os, row_type row, bool Tabular::plaintextBottomHLine(odocstringstream & os, row_type row,
vector<unsigned int> const & clen) const vector<unsigned int> const & clen) const
{ {
idx_type const fcell = getFirstCellInRow(row); idx_type const fcell = getFirstCellInRow(row);
@ -3181,14 +3181,14 @@ bool Tabular::plaintextBottomHLine(odocstream & os, row_type row,
} }
void Tabular::plaintextPrintCell(odocstream & os, void Tabular::plaintextPrintCell(odocstringstream & os,
OutputParams const & runparams, OutputParams const & runparams,
idx_type cell, row_type row, col_type column, idx_type cell, row_type row, col_type column,
vector<unsigned int> const & clen, vector<unsigned int> const & clen,
bool onlydata) const bool onlydata, size_t max_length) const
{ {
odocstringstream sstr; odocstringstream sstr;
cellInset(cell)->plaintext(sstr, runparams); cellInset(cell)->plaintext(sstr, runparams, max_length);
if (onlydata) { if (onlydata) {
os << sstr.str(); os << sstr.str();
@ -3231,9 +3231,9 @@ void Tabular::plaintextPrintCell(odocstream & os,
} }
void Tabular::plaintext(odocstream & os, void Tabular::plaintext(odocstringstream & os,
OutputParams const & runparams, int const depth, OutputParams const & runparams, int const depth,
bool onlydata, char_type delim) const bool onlydata, char_type delim, size_t max_length) const
{ {
// first calculate the width of the single columns // first calculate the width of the single columns
vector<unsigned int> clen(ncols()); vector<unsigned int> clen(ncols());
@ -3247,7 +3247,7 @@ void Tabular::plaintext(odocstream & os,
if (isMultiColumn(cell)) if (isMultiColumn(cell))
continue; continue;
odocstringstream sstr; odocstringstream sstr;
cellInset(cell)->plaintext(sstr, runparams); cellInset(cell)->plaintext(sstr, runparams, max_length);
if (clen[c] < sstr.str().length()) if (clen[c] < sstr.str().length())
clen[c] = sstr.str().length(); clen[c] = sstr.str().length();
} }
@ -3259,7 +3259,7 @@ void Tabular::plaintext(odocstream & os,
if (cell_info[r][c].multicolumn != CELL_BEGIN_OF_MULTICOLUMN) if (cell_info[r][c].multicolumn != CELL_BEGIN_OF_MULTICOLUMN)
continue; continue;
odocstringstream sstr; odocstringstream sstr;
cellInset(cell)->plaintext(sstr, runparams); cellInset(cell)->plaintext(sstr, runparams, max_length);
int len = int(sstr.str().length()); int len = int(sstr.str().length());
idx_type const n = columnSpan(cell); idx_type const n = columnSpan(cell);
for (col_type k = c; len > 0 && k < c + n - 1; ++k) for (col_type k = c; len > 0 && k < c + n - 1; ++k)
@ -3280,8 +3280,10 @@ void Tabular::plaintext(odocstream & os,
// we don't use operator<< for single UCS4 character. // we don't use operator<< for single UCS4 character.
// see explanation in docstream.h // see explanation in docstream.h
os.put(delim); os.put(delim);
plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata); plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata, max_length);
++cell; ++cell;
if (os.str().size() > max_length)
break;
} }
os << endl; os << endl;
if (!onlydata) { if (!onlydata) {
@ -3289,6 +3291,8 @@ void Tabular::plaintext(odocstream & os,
if (plaintextBottomHLine(os, r, clen)) if (plaintextBottomHLine(os, r, clen))
os << docstring(depth * 2, ' '); os << docstring(depth * 2, ' ');
} }
if (os.str().size() > max_length)
break;
} }
} }
@ -4954,11 +4958,12 @@ void InsetTabular::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetTabular::plaintext(odocstream & os, OutputParams const & runparams) const int InsetTabular::plaintext(odocstringstream & os,
OutputParams const & runparams, size_t max_length) const
{ {
os << '\n'; // output table on a new line os << '\n'; // output table on a new line
int const dp = runparams.linelen > 0 ? runparams.depth : 0; int const dp = runparams.linelen > 0 ? runparams.depth : 0;
tabular.plaintext(os, runparams, dp, false, 0); tabular.plaintext(os, runparams, dp, false, 0, max_length);
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;
} }
@ -5999,7 +6004,7 @@ bool InsetTabular::copySelection(Cursor & cur)
odocstringstream os; odocstringstream os;
OutputParams const runparams(0); OutputParams const runparams(0);
paste_tabular->plaintext(os, runparams, 0, true, '\t'); paste_tabular->plaintext(os, runparams, 0, true, '\t', INT_MAX);
// Needed for the "Edit->Paste recent" menu and the system clipboard. // Needed for the "Edit->Paste recent" menu and the system clipboard.
cap::copySelection(cur, os.str()); cap::copySelection(cur, os.str());

View File

@ -30,6 +30,7 @@
#include "support/shared_ptr.h" #include "support/shared_ptr.h"
#include <climits>
#include <iosfwd> #include <iosfwd>
#include <vector> #include <vector>
@ -500,9 +501,9 @@ public:
/// ///
docstring xhtml(XHTMLStream & os, OutputParams const &) const; docstring xhtml(XHTMLStream & os, OutputParams const &) const;
/// ///
void plaintext(odocstream &, void plaintext(odocstringstream &,
OutputParams const & runparams, int const depth, OutputParams const & runparams, int const depth,
bool onlydata, char_type delim) const; bool onlydata, char_type delim, size_t max_length = INT_MAX) const;
/// ///
bool isMultiColumn(idx_type cell) const; bool isMultiColumn(idx_type cell) const;
/// ///
@ -783,17 +784,17 @@ public:
/// ///
// helper functions for plain text // helper functions for plain text
/// ///
bool plaintextTopHLine(odocstream &, row_type row, bool plaintextTopHLine(odocstringstream &, row_type row,
std::vector<unsigned int> const &) const; std::vector<unsigned int> const &) const;
/// ///
bool plaintextBottomHLine(odocstream &, row_type row, bool plaintextBottomHLine(odocstringstream &, row_type row,
std::vector<unsigned int> const &) const; std::vector<unsigned int> const &) const;
/// ///
void plaintextPrintCell(odocstream &, void plaintextPrintCell(odocstringstream &,
OutputParams const &, OutputParams const &,
idx_type cell, row_type row, col_type column, idx_type cell, row_type row, col_type column,
std::vector<unsigned int> const &, std::vector<unsigned int> const &,
bool onlydata) const; bool onlydata, size_t max_length) const;
/// auxiliary function for docbook /// auxiliary function for docbook
int docbookRow(odocstream & os, row_type, OutputParams const &) const; int docbookRow(odocstream & os, row_type, OutputParams const &) const;
/// ///
@ -857,7 +858,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -507,7 +507,8 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
} }
int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const int InsetText::plaintext(odocstringstream & os,
OutputParams const & runparams, size_t max_length) const
{ {
ParagraphList::const_iterator beg = paragraphs().begin(); ParagraphList::const_iterator beg = paragraphs().begin();
ParagraphList::const_iterator end = paragraphs().end(); ParagraphList::const_iterator end = paragraphs().end();
@ -521,12 +522,14 @@ int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const
os << '\n'; os << '\n';
} }
odocstringstream oss; odocstringstream oss;
writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed); writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed, max_length);
docstring const str = oss.str(); docstring const str = oss.str();
os << str; os << str;
// FIXME: len is not computed fully correctly; in principle, // FIXME: len is not computed fully correctly; in principle,
// we have to count the characters after the last '\n' // we have to count the characters after the last '\n'
len = str.size(); len = str.size();
if (os.str().size() >= max_length)
break;
} }
return len; return len;
@ -961,6 +964,7 @@ docstring InsetText::toolTipText(docstring prefix,
{ {
size_t const max_length = numlines * len; size_t const max_length = numlines * len;
OutputParams rp(&buffer().params().encoding()); OutputParams rp(&buffer().params().encoding());
rp.for_tooltip = true;
odocstringstream oss; odocstringstream oss;
oss << prefix; oss << prefix;
@ -973,9 +977,9 @@ docstring InsetText::toolTipText(docstring prefix,
for (; it != end; ++it) { for (; it != end; ++it) {
if (it != beg) if (it != beg)
oss << '\n'; oss << '\n';
writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed); writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, max_length);
str = oss.str(); str = oss.str();
if (str.length() > max_length) if (str.length() >= max_length)
break; break;
} }
return support::wrapParas(str, 4, len, numlines); return support::wrapParas(str, 4, len, numlines);

View File

@ -75,7 +75,8 @@ public:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -207,7 +207,8 @@ void InsetVSpace::latex(otexstream & os, OutputParams const &) const
} }
int InsetVSpace::plaintext(odocstream & os, OutputParams const &) const int InsetVSpace::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{ {
os << "\n\n"; os << "\n\n";
return PLAINTEXT_NEWLINE; return PLAINTEXT_NEWLINE;

View File

@ -45,7 +45,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// Note that this returns the inset rather than writing it, /// Note that this returns the inset rather than writing it,

View File

@ -35,6 +35,8 @@
#include "frontends/Application.h" #include "frontends/Application.h"
#include <climits>
using namespace std; using namespace std;
@ -201,11 +203,12 @@ void InsetWrap::latex(otexstream & os, OutputParams const & runparams_in) const
} }
int InsetWrap::plaintext(odocstream & os, OutputParams const & runparams) const int InsetWrap::plaintext(odocstringstream & os,
OutputParams const & runparams, size_t max_length) const
{ {
os << '[' << buffer().B_("wrap") << ' ' os << '[' << buffer().B_("wrap") << ' '
<< floatName(params_.type) << ":\n"; << floatName(params_.type) << ":\n";
InsetText::plaintext(os, runparams); InsetText::plaintext(os, runparams, max_length);
os << "\n]"; os << "\n]";
return PLAINTEXT_NEWLINE + 1; // one char on a separate line return PLAINTEXT_NEWLINE + 1; // one char on a separate line

View File

@ -67,7 +67,8 @@ private:
/// ///
void latex(otexstream &, OutputParams const &) const; void latex(otexstream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -84,7 +84,7 @@ void InsetFormulaMacro::latex(otexstream & os,
} }
int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const & runparams) const int InsetFormulaMacro::plaintext(odocstringstream & os, OutputParams const & runparams, int max_length) const
{ {
odocstringstream oss; odocstringstream oss;
WriteStream wi(oss, false, true, WriteStream::wsDefault, runparams.encoding); WriteStream wi(oss, false, true, WriteStream::wsDefault, runparams.encoding);

View File

@ -46,7 +46,7 @@ public:
/// ///
int latex(otexstream & os, OutputParams const &) const; int latex(otexstream & os, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream &, OutputParams const &, size_t) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;

View File

@ -84,7 +84,8 @@ void InsetMath::write(WriteStream & os) const
} }
int InsetMath::plaintext(odocstream &, OutputParams const &) const int InsetMath::plaintext(odocstringstream &,
OutputParams const &, size_t) const
{ {
// all math plain text output shall take place in InsetMathHull // all math plain text output shall take place in InsetMathHull
LASSERT(false, /**/); LASSERT(false, /**/);

View File

@ -200,7 +200,7 @@ public:
virtual void octave(OctaveStream &) const; virtual void octave(OctaveStream &) const;
/// plain text output in ucs4 encoding /// plain text output in ucs4 encoding
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream &, OutputParams const &, size_t) const;
/// dump content to stderr for debugging /// dump content to stderr for debugging
virtual void dump() const; virtual void dump() const;

View File

@ -1895,7 +1895,8 @@ bool InsetMathHull::readQuiet(Lexer & lex)
} }
int InsetMathHull::plaintext(odocstream & os, OutputParams const & op) const int InsetMathHull::plaintext(odocstringstream & os,
OutputParams const & op, size_t max_length) const
{ {
// disables ASCII-art for export of equations. See #2275. // disables ASCII-art for export of equations. See #2275.
if (0 && display()) { if (0 && display()) {
@ -1923,7 +1924,7 @@ int InsetMathHull::plaintext(odocstream & os, OutputParams const & op) const
wi << (c == 0 ? "" : "\t") << cell(index(r, c)); wi << (c == 0 ? "" : "\t") << cell(index(r, c));
// if it's for the TOC, we write just the first line // if it's for the TOC, we write just the first line
// and do not include the newline. // and do not include the newline.
if (op.for_toc) if (op.for_toc || op.for_tooltip || oss.str().size() >= max_length)
break; break;
wi << "\n"; wi << "\n";
} }
@ -2239,7 +2240,9 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
void InsetMathHull::toString(odocstream & os) const void InsetMathHull::toString(odocstream & os) const
{ {
plaintext(os, OutputParams(0)); odocstringstream ods;
plaintext(ods, OutputParams(0));
os << ods.str();
} }

View File

@ -126,7 +126,8 @@ public:
/// ///
bool readQuiet(Lexer & lex); bool readQuiet(Lexer & lex);
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream &, OutputParams const &,
size_t max_length = INT_MAX) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; int docbook(odocstream &, OutputParams const &) const;
/// ///

View File

@ -1252,8 +1252,8 @@ docstring MathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const
return docstring(); return docstring();
} }
int MathMacroTemplate::plaintext(odocstream & os, int MathMacroTemplate::plaintext(odocstringstream & os,
OutputParams const &) const OutputParams const &, size_t) const
{ {
static docstring const str = '[' + buffer().B_("math macro") + ']'; static docstring const str = '[' + buffer().B_("math macro") + ']';

View File

@ -56,7 +56,7 @@ public:
/// Nothing happens. This is simply to suppress the default output. /// Nothing happens. This is simply to suppress the default output.
docstring xhtml(XHTMLStream &, OutputParams const &) const; docstring xhtml(XHTMLStream &, OutputParams const &) const;
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstringstream &, OutputParams const &, size_t) const;
/// ///
bool inheritFont() const { return false; } bool inheritFont() const { return false; }

View File

@ -75,9 +75,9 @@ static pair<int, docstring> addDepth(int depth, int ldepth)
void writePlaintextParagraph(Buffer const & buf, void writePlaintextParagraph(Buffer const & buf,
Paragraph const & par, Paragraph const & par,
odocstream & os, odocstream & ods,
OutputParams const & runparams, OutputParams const & runparams,
bool & ref_printed) bool & ref_printed, size_t max_length)
{ {
int ltype = 0; int ltype = 0;
depth_type ltype_depth = 0; depth_type ltype_depth = 0;
@ -121,6 +121,7 @@ void writePlaintextParagraph(Buffer const & buf,
string::size_type currlinelen = 0; string::size_type currlinelen = 0;
odocstringstream os;
os << docstring(depth * 2, ' '); os << docstring(depth * 2, ' ');
currlinelen += depth * 2; currlinelen += depth * 2;
@ -184,6 +185,9 @@ void writePlaintextParagraph(Buffer const & buf,
if (par.isDeleted(i)) if (par.isDeleted(i))
continue; continue;
if (os.str().size() > max_length)
break;
char_type c = par.getUChar(buf.params(), i); char_type c = par.getUChar(buf.params(), i);
if (par.isInset(i) || c == ' ') { if (par.isInset(i) || c == ' ') {
@ -202,7 +206,7 @@ void writePlaintextParagraph(Buffer const & buf,
if (par.isInset(i)) { if (par.isInset(i)) {
OutputParams rp = runparams; OutputParams rp = runparams;
rp.depth = par.params().depth(); 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) if (len >= Inset::PLAINTEXT_NEWLINE)
currlinelen = len - Inset::PLAINTEXT_NEWLINE; currlinelen = len - Inset::PLAINTEXT_NEWLINE;
else else
@ -238,6 +242,7 @@ void writePlaintextParagraph(Buffer const & buf,
} }
os << word; os << word;
} }
ods << os.str();
} }

View File

@ -13,6 +13,9 @@
#define OUTPUT_PLAINTEXT_H #define OUTPUT_PLAINTEXT_H
#include "support/strfwd.h" #include "support/strfwd.h"
#include "support/types.h"
#include <climits>
namespace lyx { namespace lyx {
@ -36,7 +39,8 @@ void writePlaintextParagraph(Buffer const & buf,
Paragraph const & paragraphs, Paragraph const & paragraphs,
odocstream & ofs, odocstream & ofs,
OutputParams const &, OutputParams const &,
bool & ref_printed); bool & ref_printed,
size_t max_length = INT_MAX);
} // namespace lyx } // namespace lyx

View File

@ -80,9 +80,6 @@ public:
/// UCS4 input stringstream /// UCS4 input stringstream
typedef std::basic_istringstream<char_type> idocstringstream; typedef std::basic_istringstream<char_type> idocstringstream;
/// UCS4 output stringstream
typedef std::basic_ostringstream<char_type> odocstringstream;
/// UCS4 output manipulator /// UCS4 output manipulator
typedef odocstream & (*odocstream_manip)(odocstream &); typedef odocstream & (*odocstream_manip)(odocstream &);

View File

@ -44,9 +44,11 @@ typedef basic_string<char, char_traits<char>, allocator<char> > string;
template<class Char, class Traits> class basic_istream; template<class Char, class Traits> class basic_istream;
template<class Char, class Traits> class basic_ostream; template<class Char, class Traits> class basic_ostream;
template<class Char, class Traits, class Allocator> class basic_ostringstream;
typedef basic_istream<char, char_traits<char> > istream; typedef basic_istream<char, char_traits<char> > istream;
typedef basic_ostream<char, char_traits<char> > ostream; typedef basic_ostream<char, char_traits<char> > ostream;
typedef basic_ostringstream<char, char_traits<char>, allocator<char> > ostringstream;
} // namepace std } // namepace std
@ -63,6 +65,9 @@ typedef std::basic_istream<char_type, std::char_traits<char_type> > idocstream;
/// Base class for UCS4 output streams /// Base class for UCS4 output streams
typedef std::basic_ostream<char_type, std::char_traits<char_type> > odocstream; typedef std::basic_ostream<char_type, std::char_traits<char_type> > odocstream;
/// UCS4 output stringstream
typedef std::basic_ostringstream<char_type, std::char_traits<char_type>, std::allocator<char_type> > odocstringstream;
#if ! defined(USE_WCHAR_T) #if ! defined(USE_WCHAR_T)
extern odocstream & operator<<(odocstream &, char); extern odocstream & operator<<(odocstream &, char);
#endif #endif