mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
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:
parent
f6480263e5
commit
ecef54500d
@ -30,7 +30,7 @@ OutputParams::OutputParams(Encoding const * enc)
|
||||
par_begin(0), par_end(0), lastid(-1), lastpos(-1), isLastPar(false),
|
||||
dryrun(false), pass_thru(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
|
||||
// OutputParams runparams(0);
|
||||
|
@ -261,6 +261,9 @@ public:
|
||||
/// Are we generating this material for inclusion in a TOC-like entity?
|
||||
bool for_toc;
|
||||
|
||||
/// Are we generating this material for inclusion in a tooltip?
|
||||
bool for_tooltip;
|
||||
|
||||
/// Include all children notwithstanding the use of \includeonly
|
||||
bool includeall;
|
||||
|
||||
|
@ -1046,7 +1046,9 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
|
||||
LASSERT(inset, /**/);
|
||||
|
||||
if (style.pass_thru) {
|
||||
inset->plaintext(os.os(), runparams);
|
||||
odocstringstream ods;
|
||||
inset->plaintext(ods, runparams);
|
||||
os << ods.str();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
if (cit != tocs_.end()) {
|
||||
TocIterator ccit = cit->second.begin();
|
||||
TocIterator end = cit->second.end();
|
||||
for (; ccit != end; ++ccit)
|
||||
for (; ccit != end; ++ccit) {
|
||||
os << ccit->asString() << from_utf8("\n");
|
||||
if (os.str().size() > max_length)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,8 @@ public:
|
||||
) const;
|
||||
|
||||
///
|
||||
void writePlaintextTocList(std::string const & type, odocstream & os) const;
|
||||
void writePlaintextTocList(std::string const & type,
|
||||
odocstringstream & os, size_t max_length) const;
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "support/strfwd.h"
|
||||
#include "support/types.h"
|
||||
|
||||
#include <climits>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -314,7 +316,8 @@ public:
|
||||
/// plain text output in ucs4 encoding
|
||||
/// return the number of characters; in case of multiple lines of
|
||||
/// 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
|
||||
virtual int docbook(odocstream & os, OutputParams const &) const;
|
||||
/// XHTML output
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
///
|
||||
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; }
|
||||
///
|
||||
|
@ -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;
|
||||
oss << '[' << bibLabel() << "] ";
|
||||
|
@ -55,7 +55,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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();
|
||||
bibinfo.makeCitationLabels(buffer());
|
||||
vector<docstring> const & cites = bibinfo.citedEntries();
|
||||
|
||||
size_t start_size = os.str().size();
|
||||
docstring refoutput;
|
||||
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 const ven = cites.end();
|
||||
for (; vit != ven; ++vit) {
|
||||
if (start_size + refoutput.size() >= max_length)
|
||||
break;
|
||||
BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
|
||||
if (biit == bibinfo.end())
|
||||
continue;
|
||||
|
@ -52,7 +52,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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);
|
||||
|
||||
@ -466,7 +467,7 @@ int InsetBox::plaintext(odocstream & os, OutputParams const & runparams) const
|
||||
break;
|
||||
}
|
||||
|
||||
InsetText::plaintext(os, runparams);
|
||||
InsetText::plaintext(os, runparams, max_length);
|
||||
|
||||
int len = 0;
|
||||
switch (btype) {
|
||||
|
@ -114,7 +114,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -262,13 +262,13 @@ void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const
|
||||
}
|
||||
|
||||
|
||||
int InsetBranch::plaintext(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
int InsetBranch::plaintext(odocstringstream & os,
|
||||
OutputParams const & runparams, size_t max_length) const
|
||||
{
|
||||
if (!isBranchSelected())
|
||||
return 0;
|
||||
|
||||
int len = InsetText::plaintext(os, runparams);
|
||||
int len = InsetText::plaintext(os, runparams, max_length);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -279,11 +279,11 @@ void InsetCaption::latex(otexstream & os,
|
||||
}
|
||||
|
||||
|
||||
int InsetCaption::plaintext(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
int InsetCaption::plaintext(odocstringstream & os,
|
||||
OutputParams const & runparams, size_t max_length) const
|
||||
{
|
||||
os << '[' << full_label_ << "\n";
|
||||
InsetText::plaintext(os, runparams);
|
||||
InsetText::plaintext(os, runparams, max_length);
|
||||
os << "\n]";
|
||||
|
||||
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
||||
@ -350,7 +350,9 @@ int InsetCaption::getCaptionAsPlaintext(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
os << full_label_ << ' ';
|
||||
return InsetText::plaintext(os, runparams);
|
||||
odocstringstream ods;
|
||||
return InsetText::plaintext(ods, runparams);
|
||||
os << ods.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,7 +71,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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();
|
||||
if (cmd == "nocite")
|
||||
@ -396,7 +397,9 @@ docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const
|
||||
|
||||
void InsetCitation::toString(odocstream & os) const
|
||||
{
|
||||
plaintext(os, OutputParams(0));
|
||||
odocstringstream ods;
|
||||
plaintext(ods, OutputParams(0));
|
||||
os << ods.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,7 +52,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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: ")
|
||||
+ from_utf8(getCmdName()) + "]";
|
||||
|
@ -78,7 +78,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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)
|
||||
// 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 end = paragraphs().end();
|
||||
|
||||
while (par != end) {
|
||||
while (par != end && os.str().size() <= max_length) {
|
||||
pos_type siz = par->size();
|
||||
for (pos_type i = 0; i < siz; ++i) {
|
||||
char_type const c = par->getChar(i);
|
||||
|
@ -48,7 +48,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -691,8 +691,8 @@ void InsetExternal::latex(otexstream & os, OutputParams const & runparams) const
|
||||
}
|
||||
|
||||
|
||||
int InsetExternal::plaintext(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
int InsetExternal::plaintext(odocstringstream & os,
|
||||
OutputParams const & runparams, size_t) const
|
||||
{
|
||||
os << '\n'; // output external material on a new line
|
||||
external::writeExternal(params_, "Ascii", buffer(), os,
|
||||
|
@ -132,7 +132,8 @@ private:
|
||||
///
|
||||
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;
|
||||
/// For now, this does nothing. Someone who knows about this
|
||||
|
@ -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") << ' '
|
||||
<< floatName(params_.type) << ":\n";
|
||||
InsetText::plaintext(os, runparams);
|
||||
InsetText::plaintext(os, runparams, max_length);
|
||||
os << "\n]";
|
||||
|
||||
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
||||
|
@ -85,7 +85,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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";
|
||||
|
||||
buffer().tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os);
|
||||
buffer().tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os, max_length);
|
||||
|
||||
return PLAINTEXT_NEWLINE;
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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";
|
||||
InsetText::plaintext(os, runparams);
|
||||
InsetText::plaintext(os, runparams, max_length);
|
||||
os << "\n]";
|
||||
|
||||
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
||||
|
@ -34,7 +34,8 @@ private:
|
||||
///
|
||||
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;
|
||||
/// Update the counters of this inset and of its contents
|
||||
|
@ -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
|
||||
// images to ascii approximation.
|
||||
|
@ -74,7 +74,8 @@ private:
|
||||
*/
|
||||
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;
|
||||
///
|
||||
|
@ -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;
|
||||
|
||||
@ -250,7 +251,9 @@ docstring InsetHyperlink::xhtml(XHTMLStream & xs, OutputParams const &) const
|
||||
|
||||
void InsetHyperlink::toString(odocstream & os) const
|
||||
{
|
||||
plaintext(os, OutputParams(0));
|
||||
odocstringstream ods;
|
||||
plaintext(ods, OutputParams(0), INT_MAX);
|
||||
os << ods.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,7 +48,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -281,11 +281,11 @@ void InsetIPADeco::latex(otexstream & os, OutputParams const & runparams) const
|
||||
}
|
||||
|
||||
|
||||
int InsetIPADeco::plaintext(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
int InsetIPADeco::plaintext(odocstringstream & os,
|
||||
OutputParams const & runparams, size_t max_length) const
|
||||
{
|
||||
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 const before = result.substr(0, h);
|
||||
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_) {
|
||||
case TONE_FALLING:
|
||||
@ -588,7 +588,9 @@ docstring InsetIPAChar::xhtml(XHTMLStream & xs, OutputParams const &) const
|
||||
|
||||
void InsetIPAChar::toString(odocstream & os) const
|
||||
{
|
||||
plaintext(os, OutputParams(0));
|
||||
odocstringstream ods;
|
||||
plaintext(ods, OutputParams(0));
|
||||
os << ods.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,7 +76,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
@ -146,7 +147,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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';
|
||||
// FIXME: We don't know the encoding of the file, default to UTF-8.
|
||||
os << includedFileName(buffer(), params()).fileContents("UTF-8");
|
||||
|
@ -91,7 +91,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -37,8 +37,8 @@
|
||||
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <algorithm>
|
||||
#include <ostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
|
@ -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");
|
||||
os << '<' << str << '>';
|
||||
|
@ -48,7 +48,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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";
|
||||
return PLAINTEXT_NEWLINE;
|
||||
|
@ -49,7 +49,8 @@ private:
|
||||
void metrics(MetricsInfo &, Dimension &) const;
|
||||
void draw(PainterInfo & pi, int x, int y) 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);
|
||||
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
|
||||
Inset * clone() const { return new InsetLine(*this); }
|
||||
|
@ -29,11 +29,11 @@ InsetMarginal::InsetMarginal(Buffer * buf)
|
||||
{}
|
||||
|
||||
|
||||
int InsetMarginal::plaintext(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
int InsetMarginal::plaintext(odocstringstream & os,
|
||||
OutputParams const & runparams, size_t max_length) const
|
||||
{
|
||||
os << '[' << buffer().B_("margin") << ":\n";
|
||||
InsetText::plaintext(os, runparams);
|
||||
InsetText::plaintext(os, runparams, max_length);
|
||||
os << "\n]";
|
||||
|
||||
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
||||
|
@ -31,7 +31,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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';
|
||||
return PLAINTEXT_NEWLINE;
|
||||
|
@ -62,7 +62,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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';
|
||||
return PLAINTEXT_NEWLINE;
|
||||
|
@ -65,7 +65,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -253,8 +253,8 @@ void InsetNote::latex(otexstream & os, OutputParams const & runparams_in) const
|
||||
}
|
||||
|
||||
|
||||
int InsetNote::plaintext(odocstream & os,
|
||||
OutputParams const & runparams_in) const
|
||||
int InsetNote::plaintext(odocstringstream & os,
|
||||
OutputParams const & runparams_in, size_t max_length) const
|
||||
{
|
||||
if (params_.type == InsetNoteParams::Note)
|
||||
return 0;
|
||||
@ -266,7 +266,7 @@ int InsetNote::plaintext(odocstream & os,
|
||||
runparams.exportdata.reset(new ExportData);
|
||||
}
|
||||
os << '[' << buffer().B_("note") << ":\n";
|
||||
InsetText::plaintext(os, runparams);
|
||||
InsetText::plaintext(os, runparams, max_length);
|
||||
os << "\n]";
|
||||
|
||||
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
||||
|
@ -85,7 +85,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -320,8 +320,8 @@ void InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const
|
||||
}
|
||||
|
||||
|
||||
int InsetPhantom::plaintext(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
int InsetPhantom::plaintext(odocstringstream & os,
|
||||
OutputParams const & runparams, size_t max_length) const
|
||||
{
|
||||
if (params_.type == InsetPhantomParams::Phantom)
|
||||
os << '[' << buffer().B_("phantom") << ":";
|
||||
@ -329,7 +329,7 @@ int InsetPhantom::plaintext(odocstream & os,
|
||||
os << '[' << buffer().B_("hphantom") << ":";
|
||||
else if (params_.type == InsetPhantomParams::VPhantom)
|
||||
os << '[' << buffer().B_("vphantom") << ":";
|
||||
InsetCollapsable::plaintext(os, runparams);
|
||||
InsetCollapsable::plaintext(os, runparams, max_length);
|
||||
os << "]";
|
||||
|
||||
return PLAINTEXT_NEWLINE;
|
||||
|
@ -78,7 +78,8 @@ private:
|
||||
///
|
||||
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;
|
||||
/// Makes no sense fof XHTML.
|
||||
|
@ -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();
|
||||
os << str;
|
||||
|
@ -80,7 +80,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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");
|
||||
os << '[' << str << ']';
|
||||
@ -246,7 +247,9 @@ docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const
|
||||
|
||||
void InsetRef::toString(odocstream & os) const
|
||||
{
|
||||
plaintext(os, OutputParams(0));
|
||||
odocstringstream ods;
|
||||
plaintext(ods, OutputParams(0));
|
||||
os << ods.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +53,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -313,11 +313,11 @@ docstring InsetScript::toolTip(BufferView const &, int, int) const
|
||||
{
|
||||
OutputParams rp(&buffer().params().encoding());
|
||||
odocstringstream ods;
|
||||
InsetText::plaintext(ods, rp);
|
||||
InsetText::plaintext(ods, rp, 200);
|
||||
docstring content_tip = ods.str();
|
||||
// shorten it if necessary
|
||||
if (content_tip.size() > 200)
|
||||
content_tip = content_tip.substr(0, 200) + "...";
|
||||
if (content_tip.size() >= 200)
|
||||
content_tip = content_tip.substr(0, 197) + "...";
|
||||
docstring res = scripttranslator_loc().find(params_.type);
|
||||
if (!content_tip.empty())
|
||||
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;
|
||||
InsetText::plaintext(oss, runparams);
|
||||
InsetText::plaintext(oss, runparams, max_length);
|
||||
docstring const text = oss.str();
|
||||
switch (params_.type) {
|
||||
case InsetScriptParams::Subscript:
|
||||
@ -352,7 +353,7 @@ int InsetScript::plaintext(odocstream & os, OutputParams const & runparams) cons
|
||||
os << '[' << buffer().B_("superscript") << ':';
|
||||
break;
|
||||
}
|
||||
InsetText::plaintext(os, runparams);
|
||||
InsetText::plaintext(os, runparams, max_length);
|
||||
os << ']';
|
||||
|
||||
return PLAINTEXT_NEWLINE;
|
||||
|
@ -82,7 +82,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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) {
|
||||
case InsetSpaceParams::HFILL:
|
||||
@ -813,7 +814,9 @@ void InsetSpace::validate(LaTeXFeatures & features) const
|
||||
|
||||
void InsetSpace::toString(odocstream & os) const
|
||||
{
|
||||
plaintext(os, OutputParams(0));
|
||||
odocstringstream ods;
|
||||
plaintext(ods, OutputParams(0));
|
||||
os << ods.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,7 +124,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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_) {
|
||||
case HYPHENATION:
|
||||
@ -329,8 +330,11 @@ void InsetSpecialChar::toString(odocstream & os) const
|
||||
// Spell checker would choke on it.
|
||||
return;
|
||||
default:
|
||||
plaintext(os, OutputParams(0));
|
||||
break;
|
||||
}
|
||||
odocstringstream ods;
|
||||
plaintext(ods, OutputParams(0));
|
||||
os << ods.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,7 +61,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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";
|
||||
buffer().tocBackend().writePlaintextTocList(cmd2type(getCmdName()), os);
|
||||
buffer().tocBackend().writePlaintextTocList(cmd2type(getCmdName()), os, max_length);
|
||||
return PLAINTEXT_NEWLINE;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -64,10 +64,10 @@
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
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,
|
||||
idx_type cell, row_type row, col_type column,
|
||||
vector<unsigned int> const & clen,
|
||||
bool onlydata) const
|
||||
bool onlydata, size_t max_length) const
|
||||
{
|
||||
odocstringstream sstr;
|
||||
cellInset(cell)->plaintext(sstr, runparams);
|
||||
cellInset(cell)->plaintext(sstr, runparams, max_length);
|
||||
|
||||
if (onlydata) {
|
||||
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,
|
||||
bool onlydata, char_type delim) const
|
||||
bool onlydata, char_type delim, size_t max_length) const
|
||||
{
|
||||
// first calculate the width of the single columns
|
||||
vector<unsigned int> clen(ncols());
|
||||
@ -3247,7 +3247,7 @@ void Tabular::plaintext(odocstream & os,
|
||||
if (isMultiColumn(cell))
|
||||
continue;
|
||||
odocstringstream sstr;
|
||||
cellInset(cell)->plaintext(sstr, runparams);
|
||||
cellInset(cell)->plaintext(sstr, runparams, max_length);
|
||||
if (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)
|
||||
continue;
|
||||
odocstringstream sstr;
|
||||
cellInset(cell)->plaintext(sstr, runparams);
|
||||
cellInset(cell)->plaintext(sstr, runparams, max_length);
|
||||
int len = int(sstr.str().length());
|
||||
idx_type const n = columnSpan(cell);
|
||||
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.
|
||||
// see explanation in docstream.h
|
||||
os.put(delim);
|
||||
plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata);
|
||||
plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata, max_length);
|
||||
++cell;
|
||||
if (os.str().size() > max_length)
|
||||
break;
|
||||
}
|
||||
os << endl;
|
||||
if (!onlydata) {
|
||||
@ -3289,6 +3291,8 @@ void Tabular::plaintext(odocstream & os,
|
||||
if (plaintextBottomHLine(os, r, clen))
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
@ -5999,7 +6004,7 @@ bool InsetTabular::copySelection(Cursor & cur)
|
||||
|
||||
odocstringstream os;
|
||||
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.
|
||||
cap::copySelection(cur, os.str());
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "support/shared_ptr.h"
|
||||
|
||||
#include <climits>
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
@ -500,9 +501,9 @@ public:
|
||||
///
|
||||
docstring xhtml(XHTMLStream & os, OutputParams const &) const;
|
||||
///
|
||||
void plaintext(odocstream &,
|
||||
void plaintext(odocstringstream &,
|
||||
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;
|
||||
///
|
||||
@ -783,17 +784,17 @@ public:
|
||||
///
|
||||
// helper functions for plain text
|
||||
///
|
||||
bool plaintextTopHLine(odocstream &, row_type row,
|
||||
bool plaintextTopHLine(odocstringstream &, row_type row,
|
||||
std::vector<unsigned int> const &) const;
|
||||
///
|
||||
bool plaintextBottomHLine(odocstream &, row_type row,
|
||||
bool plaintextBottomHLine(odocstringstream &, row_type row,
|
||||
std::vector<unsigned int> const &) const;
|
||||
///
|
||||
void plaintextPrintCell(odocstream &,
|
||||
void plaintextPrintCell(odocstringstream &,
|
||||
OutputParams const &,
|
||||
idx_type cell, row_type row, col_type column,
|
||||
std::vector<unsigned int> const &,
|
||||
bool onlydata) const;
|
||||
bool onlydata, size_t max_length) const;
|
||||
/// auxiliary function for docbook
|
||||
int docbookRow(odocstream & os, row_type, OutputParams const &) const;
|
||||
///
|
||||
@ -857,7 +858,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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 end = paragraphs().end();
|
||||
@ -521,12 +522,14 @@ int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const
|
||||
os << '\n';
|
||||
}
|
||||
odocstringstream oss;
|
||||
writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed);
|
||||
writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed, max_length);
|
||||
docstring const str = oss.str();
|
||||
os << str;
|
||||
// FIXME: len is not computed fully correctly; in principle,
|
||||
// we have to count the characters after the last '\n'
|
||||
len = str.size();
|
||||
if (os.str().size() >= max_length)
|
||||
break;
|
||||
}
|
||||
|
||||
return len;
|
||||
@ -961,6 +964,7 @@ docstring InsetText::toolTipText(docstring prefix,
|
||||
{
|
||||
size_t const max_length = numlines * len;
|
||||
OutputParams rp(&buffer().params().encoding());
|
||||
rp.for_tooltip = true;
|
||||
odocstringstream oss;
|
||||
oss << prefix;
|
||||
|
||||
@ -973,9 +977,9 @@ docstring InsetText::toolTipText(docstring prefix,
|
||||
for (; it != end; ++it) {
|
||||
if (it != beg)
|
||||
oss << '\n';
|
||||
writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed);
|
||||
writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, max_length);
|
||||
str = oss.str();
|
||||
if (str.length() > max_length)
|
||||
if (str.length() >= max_length)
|
||||
break;
|
||||
}
|
||||
return support::wrapParas(str, 4, len, numlines);
|
||||
|
@ -75,7 +75,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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";
|
||||
return PLAINTEXT_NEWLINE;
|
||||
|
@ -45,7 +45,8 @@ private:
|
||||
///
|
||||
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;
|
||||
/// Note that this returns the inset rather than writing it,
|
||||
|
@ -35,6 +35,8 @@
|
||||
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include <climits>
|
||||
|
||||
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") << ' '
|
||||
<< floatName(params_.type) << ":\n";
|
||||
InsetText::plaintext(os, runparams);
|
||||
InsetText::plaintext(os, runparams, max_length);
|
||||
os << "\n]";
|
||||
|
||||
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
||||
|
@ -67,7 +67,8 @@ private:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -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;
|
||||
WriteStream wi(oss, false, true, WriteStream::wsDefault, runparams.encoding);
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
///
|
||||
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;
|
||||
|
||||
|
@ -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
|
||||
LASSERT(false, /**/);
|
||||
|
@ -200,7 +200,7 @@ public:
|
||||
virtual void octave(OctaveStream &) const;
|
||||
|
||||
/// 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
|
||||
virtual void dump() const;
|
||||
|
@ -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.
|
||||
if (0 && display()) {
|
||||
@ -1923,7 +1924,7 @@ int InsetMathHull::plaintext(odocstream & os, OutputParams const & op) const
|
||||
wi << (c == 0 ? "" : "\t") << cell(index(r, c));
|
||||
// if it's for the TOC, we write just the first line
|
||||
// and do not include the newline.
|
||||
if (op.for_toc)
|
||||
if (op.for_toc || op.for_tooltip || oss.str().size() >= max_length)
|
||||
break;
|
||||
wi << "\n";
|
||||
}
|
||||
@ -2239,7 +2240,9 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
|
||||
|
||||
void InsetMathHull::toString(odocstream & os) const
|
||||
{
|
||||
plaintext(os, OutputParams(0));
|
||||
odocstringstream ods;
|
||||
plaintext(ods, OutputParams(0));
|
||||
os << ods.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -126,7 +126,8 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -1252,8 +1252,8 @@ docstring MathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const
|
||||
return docstring();
|
||||
}
|
||||
|
||||
int MathMacroTemplate::plaintext(odocstream & os,
|
||||
OutputParams const &) const
|
||||
int MathMacroTemplate::plaintext(odocstringstream & os,
|
||||
OutputParams const &, size_t) const
|
||||
{
|
||||
static docstring const str = '[' + buffer().B_("math macro") + ']';
|
||||
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
/// Nothing happens. This is simply to suppress the default output.
|
||||
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; }
|
||||
|
||||
|
@ -75,9 +75,9 @@ static pair<int, docstring> addDepth(int depth, int ldepth)
|
||||
|
||||
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;
|
||||
@ -121,6 +121,7 @@ void writePlaintextParagraph(Buffer const & buf,
|
||||
|
||||
string::size_type currlinelen = 0;
|
||||
|
||||
odocstringstream os;
|
||||
os << docstring(depth * 2, ' ');
|
||||
currlinelen += depth * 2;
|
||||
|
||||
@ -184,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 == ' ') {
|
||||
@ -202,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
|
||||
@ -238,6 +242,7 @@ void writePlaintextParagraph(Buffer const & buf,
|
||||
}
|
||||
os << word;
|
||||
}
|
||||
ods << os.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,6 +13,9 @@
|
||||
#define OUTPUT_PLAINTEXT_H
|
||||
|
||||
#include "support/strfwd.h"
|
||||
#include "support/types.h"
|
||||
|
||||
#include <climits>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -36,7 +39,8 @@ void writePlaintextParagraph(Buffer const & buf,
|
||||
Paragraph const & paragraphs,
|
||||
odocstream & ofs,
|
||||
OutputParams const &,
|
||||
bool & ref_printed);
|
||||
bool & ref_printed,
|
||||
size_t max_length = INT_MAX);
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -80,9 +80,6 @@ public:
|
||||
/// UCS4 input stringstream
|
||||
typedef std::basic_istringstream<char_type> idocstringstream;
|
||||
|
||||
/// UCS4 output stringstream
|
||||
typedef std::basic_ostringstream<char_type> odocstringstream;
|
||||
|
||||
/// UCS4 output manipulator
|
||||
typedef odocstream & (*odocstream_manip)(odocstream &);
|
||||
|
||||
|
@ -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_ostream;
|
||||
template<class Char, class Traits, class Allocator> class basic_ostringstream;
|
||||
|
||||
typedef basic_istream<char, char_traits<char> > istream;
|
||||
typedef basic_ostream<char, char_traits<char> > ostream;
|
||||
typedef basic_ostringstream<char, char_traits<char>, allocator<char> > ostringstream;
|
||||
|
||||
} // namepace std
|
||||
|
||||
@ -63,6 +65,9 @@ typedef std::basic_istream<char_type, std::char_traits<char_type> > idocstream;
|
||||
/// Base class for UCS4 output streams
|
||||
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)
|
||||
extern odocstream & operator<<(odocstream &, char);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user