Make use of otexstream also in external::writeExternal

This was not necessary when LyX was generously outputting newlines.
As it may happen that the output produced by writeExternal (the
result of an external inset) starts right at the beginning of a
line, if otexstream does not know that something is already on
the line, the iomanip-like variable 'breakln' fails to actually
break the line.
This commit is contained in:
Enrico Forestieri 2014-05-16 14:21:48 +02:00
parent 371fdb8649
commit 15e1f5eb39
3 changed files with 37 additions and 32 deletions

View File

@ -333,23 +333,23 @@ string const substituteOptions(InsetExternalParams const & params,
} // namespace anon
int writeExternal(InsetExternalParams const & params,
string const & format,
Buffer const & buffer, odocstream & os,
ExportData & exportdata,
bool external_in_tmpdir,
bool dryrun)
void writeExternal(InsetExternalParams const & params,
string const & format,
Buffer const & buffer, otexstream & os,
ExportData & exportdata,
bool external_in_tmpdir,
bool dryrun)
{
Template const * const et_ptr = getTemplatePtr(params);
if (!et_ptr)
return 0;
return;
Template const & et = *et_ptr;
Template::Formats::const_iterator cit = et.formats.find(format);
if (cit == et.formats.end()) {
LYXERR(Debug::EXTERNAL, "External template format '" << format
<< "' not specified in template " << params.templatename());
return 0;
return;
}
if (!dryrun || contains(cit->second.product, "$$Contents"))
@ -383,7 +383,7 @@ int writeExternal(InsetExternalParams const & params,
str = substituteOptions(params, str, format);
// FIXME UNICODE
os << from_utf8(str);
return int(count(str.begin(), str.end(),'\n'));
return;
}
namespace {

View File

@ -60,13 +60,13 @@ std::string const doSubstitution(InsetExternalParams const & params,
If \p external_in_tmpdir == true, then the generated file is
place in the buffer's temporary directory.
*/
int writeExternal(InsetExternalParams const &,
std::string const & format,
Buffer const &,
odocstream &,
ExportData &,
bool external_in_tmpdir,
bool dryrun);
void writeExternal(InsetExternalParams const &,
std::string const & format,
Buffer const &,
otexstream &,
ExportData &,
bool external_in_tmpdir,
bool dryrun);
} // namespace external
} // namespace lyx

View File

@ -673,21 +673,19 @@ void InsetExternal::latex(otexstream & os, OutputParams const & runparams) const
et.formats.find("PDFLaTeX");
if (cit != et.formats.end()) {
int l = external::writeExternal(params_, "PDFLaTeX",
buffer(), os.os(),
*(runparams.exportdata),
external_in_tmpdir,
dryrun);
os.texrow().newlines(l);
external::writeExternal(params_, "PDFLaTeX",
buffer(), os,
*(runparams.exportdata),
external_in_tmpdir,
dryrun);
return;
}
}
int l = external::writeExternal(params_, "LaTeX", buffer(), os.os(),
*(runparams.exportdata),
external_in_tmpdir,
dryrun);
os.texrow().newlines(l);
external::writeExternal(params_, "LaTeX", buffer(), os,
*(runparams.exportdata),
external_in_tmpdir,
dryrun);
}
@ -698,8 +696,10 @@ int InsetExternal::plaintext(odocstringstream & os,
if (runparams.for_tooltip)
return 0;
os << '\n'; // output external material on a new line
external::writeExternal(params_, "Ascii", buffer(), os,
TexRow texrow;
otexstream ots(os, texrow);
ots << '\n'; // output external material on a new line
external::writeExternal(params_, "Ascii", buffer(), ots,
*(runparams.exportdata), false,
runparams.dryrun || runparams.inComment);
return PLAINTEXT_NEWLINE;
@ -709,9 +709,14 @@ int InsetExternal::plaintext(odocstringstream & os,
int InsetExternal::docbook(odocstream & os,
OutputParams const & runparams) const
{
return external::writeExternal(params_, "DocBook", buffer(), os,
*(runparams.exportdata), false,
runparams.dryrun || runparams.inComment);
TexRow texrow;
odocstringstream ods;
otexstream ots(ods, texrow);
external::writeExternal(params_, "DocBook", buffer(), ots,
*(runparams.exportdata), false,
runparams.dryrun || runparams.inComment);
os << ods.str();
return int(count(ods.str().begin(), ods.str().end(), '\n'));
}