From 8b67659646c6850377cb9f44a2a0a22c0e80840c Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Thu, 19 Oct 2006 16:51:30 +0000 Subject: [PATCH] Use UTF8 for LaTeX export. Known problems: - No space is output after a \hfill. I probably broke this with the InsetCommand patch. I'll have a look later. - Although the encoding is now UTF8 the arguments of the inputenc package are still the old ones, so LaTeX will not run. - Labels and references with non-ASCII characters are broken. This needs to be fixed in lyx::support::escape(), but this is a file format change. - Something seems to be wrong with index entries, but this is probably also due to the InsetCommand changes. Have fun! git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15378 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 52 ++++++--- src/buffer.h | 4 +- src/bufferparams.C | 53 ++++----- src/bufferparams.h | 2 +- src/changes.C | 12 ++- src/changes.h | 5 +- src/cursor.C | 5 +- src/frontends/controllers/ControlViewSource.C | 5 +- src/frontends/controllers/ControlViewSource.h | 2 +- src/graphics/PreviewLoader.C | 22 ++-- src/insets/ExternalSupport.C | 8 +- src/insets/ExternalSupport.h | 5 +- src/insets/insetbase.C | 5 +- src/insets/insetbase.h | 2 +- src/insets/insetbibitem.C | 3 +- src/insets/insetbibtex.C | 17 +-- src/insets/insetbibtex.h | 2 +- src/insets/insetbox.C | 23 ++-- src/insets/insetbox.h | 2 +- src/insets/insetbranch.C | 5 +- src/insets/insetbranch.h | 2 +- src/insets/insetcaption.C | 8 +- src/insets/insetcaption.h | 2 +- src/insets/insetcharstyle.C | 14 +-- src/insets/insetcharstyle.h | 2 +- src/insets/insetcite.C | 19 ++-- src/insets/insetcite.h | 2 +- src/insets/insetcommand.C | 6 +- src/insets/insetcommand.h | 4 +- src/insets/insetcommandparams.C | 6 +- src/insets/insetcommandparams.h | 2 +- src/insets/insetenv.C | 11 +- src/insets/insetenv.h | 2 +- src/insets/insetert.C | 9 +- src/insets/insetert.h | 2 +- src/insets/insetexternal.C | 29 ++--- src/insets/insetexternal.h | 2 +- src/insets/insetfloat.C | 9 +- src/insets/insetfloat.h | 2 +- src/insets/insetfloatlist.C | 13 +-- src/insets/insetfloatlist.h | 2 +- src/insets/insetfoot.C | 3 +- src/insets/insetfoot.h | 2 +- src/insets/insetgraphics.C | 9 +- src/insets/insetgraphics.h | 2 +- src/insets/insethfill.C | 5 +- src/insets/insethfill.h | 2 +- src/insets/insetinclude.C | 35 +++--- src/insets/insetinclude.h | 2 +- src/insets/insetlabel.C | 5 +- src/insets/insetlabel.h | 2 +- src/insets/insetlatexaccent.C | 9 +- src/insets/insetlatexaccent.h | 2 +- src/insets/insetline.C | 8 +- src/insets/insetline.h | 2 +- src/insets/insetmarginal.C | 3 +- src/insets/insetmarginal.h | 2 +- src/insets/insetnewline.C | 6 +- src/insets/insetnewline.h | 2 +- src/insets/insetnote.C | 15 +-- src/insets/insetnote.h | 2 +- src/insets/insetoptarg.C | 13 +-- src/insets/insetoptarg.h | 4 +- src/insets/insetpagebreak.C | 5 +- src/insets/insetpagebreak.h | 2 +- src/insets/insetquotes.C | 9 +- src/insets/insetquotes.h | 2 +- src/insets/insetref.C | 7 +- src/insets/insetref.h | 2 +- src/insets/insetspace.C | 8 +- src/insets/insetspace.h | 2 +- src/insets/insetspecialchar.C | 7 +- src/insets/insetspecialchar.h | 2 +- src/insets/insettabular.C | 5 +- src/insets/insettabular.h | 2 +- src/insets/insettext.C | 5 +- src/insets/insettext.h | 2 +- src/insets/insettheorem.C | 2 +- src/insets/insettheorem.h | 2 +- src/insets/insettoc.C | 3 +- src/insets/inseturl.C | 14 +-- src/insets/inseturl.h | 2 +- src/insets/insetvspace.C | 7 +- src/insets/insetvspace.h | 2 +- src/insets/insetwrap.C | 13 ++- src/insets/insetwrap.h | 2 +- src/insets/render_preview.C | 8 +- src/insets/render_preview.h | 5 +- src/lyxfont.C | 11 +- src/lyxfont.h | 7 +- src/mathed/InsetFormulaMacro.C | 5 +- src/mathed/InsetFormulaMacro.h | 2 +- src/mathed/InsetMath.C | 18 +++- src/mathed/InsetMath.h | 5 +- src/mathed/InsetMathCommand.C | 7 +- src/mathed/InsetMathGrid.C | 7 +- src/mathed/InsetMathHull.C | 50 +++++---- src/mathed/InsetMathMBox.C | 2 +- src/mathed/InsetMathMBox.h | 2 +- src/mathed/InsetMathNest.C | 7 +- src/mathed/InsetMathNest.h | 2 +- src/mathed/MathData.C | 27 ++++- src/mathed/MathData.h | 5 +- src/mathed/MathExtern.C | 52 ++++----- src/mathed/MathExtern.h | 4 +- src/mathed/MathMLStream.C | 8 +- src/mathed/MathMLStream.h | 46 ++++---- src/mathed/MathMacroTemplate.C | 6 +- src/mathed/MathStream.C | 19 ++-- src/mathed/MathSupport.C | 15 +-- src/mathed/TextPainter.C | 15 +-- src/mathed/TextPainter.h | 14 +-- src/output_latex.C | 101 ++++++++++-------- src/output_latex.h | 4 +- src/paragraph.C | 23 ++-- src/paragraph.h | 9 +- src/paragraph_pimpl.C | 31 +++--- src/paragraph_pimpl.h | 4 +- src/rowpainter.C | 4 + src/support/lstrings.C | 12 ++- src/support/lstrings.h | 2 +- src/support/unicode.C | 2 +- src/tabular.C | 44 ++++---- src/tabular.h | 14 +-- 124 files changed, 698 insertions(+), 525 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index b14f3be740..efcb980715 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -94,6 +94,7 @@ namespace io = boost::iostreams; using lyx::docstring; +using lyx::odocstream; using lyx::pos_type; using lyx::pit_type; @@ -824,7 +825,10 @@ void Buffer::makeLaTeXFile(string const & fname, { lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl; - ofstream ofs; + // FIXME UNICODE + // This creates an utf8 encoded file, but the inputenc commands + // specify other encodings + lyx::odocfstream ofs; if (!openFileWrite(ofs, fname)) return; @@ -837,7 +841,7 @@ void Buffer::makeLaTeXFile(string const & fname, } -void Buffer::writeLaTeXSource(ostream & os, +void Buffer::writeLaTeXSource(odocstream & os, string const & original_path, OutputParams const & runparams_in, bool const output_preamble, bool const output_body) @@ -883,11 +887,13 @@ void Buffer::writeLaTeXSource(ostream & os, texrow().newline(); } if (!original_path.empty()) { - string const inputpath = latex_path(original_path); + // FIXME UNICODE + // We don't know the encoding of inputpath + docstring const inputpath = lyx::from_utf8(latex_path(original_path)); os << "\\makeatletter\n" - << "\\def\\input@path{{" - << inputpath << "/}}\n" - << "\\makeatother\n"; + << "\\def\\input@path{{" + << inputpath << "/}}\n" + << "\\makeatother\n"; texrow().newline(); texrow().newline(); texrow().newline(); @@ -906,9 +912,11 @@ void Buffer::writeLaTeXSource(ostream & os, lyxerr[Debug::INFO] << "preamble finished, now the body." << endl; if (!lyxrc.language_auto_begin) { - os << subst(lyxrc.language_command_begin, "$$lang", - params().language->babel()) - << endl; + // FIXME UNICODE + os << lyx::from_utf8(subst(lyxrc.language_command_begin, + "$$lang", + params().language->babel())) + << '\n'; texrow().newline(); } @@ -933,9 +941,10 @@ void Buffer::writeLaTeXSource(ostream & os, texrow().newline(); if (!lyxrc.language_auto_end) { - os << subst(lyxrc.language_command_end, "$$lang", - params().language->babel()) - << endl; + os << lyx::from_utf8(subst(lyxrc.language_command_end, + "$$lang", + params().language->babel())) + << '\n'; texrow().newline(); } @@ -1590,7 +1599,7 @@ void Buffer::changeRefsIfUnique(string const & from, string const & to, InsetBas } -void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source) +void Buffer::getSourceCode(odocstream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source) { OutputParams runparams; runparams.nice = true; @@ -1603,8 +1612,12 @@ void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type os << "% Preview source code\n\n"; if (isLatex()) writeLaTeXSource(os, filePath(), runparams, true, true); - else - writeDocBookSource(os, fileName(), runparams, false); + else { + // FIXME UNICODE + ostringstream oss; + writeDocBookSource(oss, fileName(), runparams, false); + os << lyx::from_utf8(oss.str()); + } } else { runparams.par_begin = par_begin; runparams.par_end = par_end; @@ -1616,8 +1629,13 @@ void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type if (isLatex()) { texrow().reset(); latexParagraphs(*this, paragraphs(), os, texrow(), runparams); - } else // DocBook - docbookParagraphs(paragraphs(), *this, os, runparams); + } else { + // DocBook + // FIXME UNICODE + ostringstream oss; + docbookParagraphs(paragraphs(), *this, oss, runparams); + os << lyx::from_utf8(oss.str()); + } } } diff --git a/src/buffer.h b/src/buffer.h index 301622f9d2..bbb28b15c2 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -146,7 +146,7 @@ public: bool output_preamble = true, bool output_body = true); /// - void writeLaTeXSource(std::ostream & os, + void writeLaTeXSource(lyx::odocstream & os, std::string const & original_path, OutputParams const &, bool output_preamble = true, @@ -339,7 +339,7 @@ public: void changeRefsIfUnique(std::string const & from, std::string const & to, InsetBase::Code code); /// get source code (latex/docbook) for some paragraphs, or all paragraphs /// including preamble - void getSourceCode(std::ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source); + void getSourceCode(lyx::odocstream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source); /// errorLists_ accessors. //@{ diff --git a/src/bufferparams.C b/src/bufferparams.C index d45bbe0c0d..fa34a76207 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -49,6 +49,7 @@ namespace support = lyx::support; using lyx::docstring; +using lyx::odocstream; using lyx::support::bformat; using lyx::support::rtrim; using lyx::support::tokenPos; @@ -714,7 +715,7 @@ void BufferParams::writeFile(ostream & os) const } -bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, +bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, TexRow & texrow) const { os << "\\documentclass"; @@ -811,10 +812,11 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, string strOptions(clsoptions.str()); if (!strOptions.empty()) { strOptions = rtrim(strOptions, ","); - os << '[' << strOptions << ']'; + // FIXME UNICODE + os << '[' << lyx::from_utf8(strOptions) << ']'; } - os << '{' << tclass.latexname() << "}\n"; + os << '{' << lyx::from_ascii(tclass.latexname()) << "}\n"; texrow.newline(); // end of \documentclass defs @@ -824,15 +826,15 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, fontsTypewriter, fontsSC, fontsOSF, fontsSansScale, fontsTypewriterScale); if (!fonts.empty()) { - os << fonts; + os << lyx::from_ascii(fonts); texrow.newline(); } if (fontsDefaultFamily != "default") os << "\\renewcommand{\\familydefault}{\\" - << fontsDefaultFamily << "}\n"; + << lyx::from_ascii(fontsDefaultFamily) << "}\n"; // this one is not per buffer if (lyxrc.fontenc != "default") { - os << "\\usepackage[" << lyxrc.fontenc + os << "\\usepackage[" << lyx::from_ascii(lyxrc.fontenc) << "]{fontenc}\n"; texrow.newline(); } @@ -847,12 +849,14 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, features.getEncodingSet(doc_encoding); os << "\\usepackage["; - std::copy(encodings.begin(), encodings.end(), - std::ostream_iterator(os, ",")); - os << doc_encoding << "]{inputenc}\n"; + std::set::const_iterator it = encodings.begin(); + std::set::const_iterator const end = encodings.end(); + for (; it != end; ++it) + os << lyx::from_ascii(*it) << ','; + os << lyx::from_ascii(doc_encoding) << "]{inputenc}\n"; texrow.newline(); } else if (inputenc != "default") { - os << "\\usepackage[" << inputenc + os << "\\usepackage[" << lyx::from_ascii(inputenc) << "]{inputenc}\n"; texrow.newline(); } @@ -867,10 +871,10 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, case PAPER_CUSTOM: if (!paperwidth.empty()) os << ",paperwidth=" - << paperwidth; + << lyx::from_ascii(paperwidth); if (!paperheight.empty()) os << ",paperheight=" - << paperheight; + << lyx::from_ascii(paperheight); break; case PAPER_USLETTER: os << ",letterpaper"; @@ -931,19 +935,19 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, } } if (!topmargin.empty()) - os << ",tmargin=" << topmargin; + os << ",tmargin=" << lyx::from_ascii(topmargin); if (!bottommargin.empty()) - os << ",bmargin=" << bottommargin; + os << ",bmargin=" << lyx::from_ascii(bottommargin); if (!leftmargin.empty()) - os << ",lmargin=" << leftmargin; + os << ",lmargin=" << lyx::from_ascii(leftmargin); if (!rightmargin.empty()) - os << ",rmargin=" << rightmargin; + os << ",rmargin=" << lyx::from_ascii(rightmargin); if (!headheight.empty()) - os << ",headheight=" << headheight; + os << ",headheight=" << lyx::from_ascii(headheight); if (!headsep.empty()) - os << ",headsep=" << headsep; + os << ",headsep=" << lyx::from_ascii(headsep); if (!footskip.empty()) - os << ",footskip=" << footskip; + os << ",footskip=" << lyx::from_ascii(footskip); os << "}\n"; texrow.newline(); } @@ -954,7 +958,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, os << "\\usepackage{fancyhdr}\n"; texrow.newline(); } - os << "\\pagestyle{" << pagestyle << "}\n"; + os << "\\pagestyle{" << lyx::from_ascii(pagestyle) << "}\n"; texrow.newline(); } @@ -987,7 +991,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, break; case VSpace::LENGTH: os << "\\setlength\\parskip{" - << getDefSkip().length().asLatexString() + << lyx::from_ascii(getDefSkip().length().asLatexString()) << "}\n"; break; default: // should never happen // Then delete it. @@ -1002,9 +1006,9 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, // If we use jurabib, we have to call babel here. if (use_babel && features.isRequired("jurabib")) { - os << babelCall(language_options.str()) + os << lyx::from_ascii(babelCall(language_options.str())) << '\n' - << features.getBabelOptions(); + << lyx::from_ascii(features.getBabelOptions()); texrow.newline(); } @@ -1101,7 +1105,8 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features, texrow.newline(); } - os << lyxpreamble; + // FIXME UNICODE + os << lyx::from_utf8(lyxpreamble); return use_babel; } diff --git a/src/bufferparams.h b/src/bufferparams.h index 3ea4bc7cf8..45e29a8540 100644 --- a/src/bufferparams.h +++ b/src/bufferparams.h @@ -86,7 +86,7 @@ public: * the BufferParams and a LyXRC variable). * This returned value can then be passed to the insets... */ - bool writeLaTeX(std::ostream &, LaTeXFeatures &, TexRow &) const; + bool writeLaTeX(lyx::odocstream &, LaTeXFeatures &, TexRow &) const; /// void useClassDefaults(); diff --git a/src/changes.C b/src/changes.C index 3f688d827d..0f45939dc0 100644 --- a/src/changes.C +++ b/src/changes.C @@ -17,6 +17,8 @@ #include +using lyx::docstring; +using lyx::odocstream; using lyx::pos_type; using std::endl; @@ -450,17 +452,17 @@ void Changes::check() const } -int Changes::latexMarkChange(std::ostream & os, +int Changes::latexMarkChange(odocstream & os, Change::Type const old, Change::Type const change, bool const & output) { if (!output || old == change) return 0; - string const start("\\changestart{}"); - string const end("\\changeend{}"); - string const son("\\overstrikeon{}"); - string const soff("\\overstrikeoff{}"); + static docstring const start(lyx::from_ascii("\\changestart{}")); + static docstring const end(lyx::from_ascii("\\changeend{}")); + static docstring const son(lyx::from_ascii("\\overstrikeon{}")); + static docstring const soff(lyx::from_ascii("\\overstrikeoff{}")); int column = 0; diff --git a/src/changes.h b/src/changes.h index 9ef77e03c7..75c83e3c44 100644 --- a/src/changes.h +++ b/src/changes.h @@ -14,11 +14,10 @@ #ifndef CHANGES_H #define CHANGES_H -#include "support/types.h" +#include "support/docstream.h" #include "support/lyxtime.h" #include -#include class Change { @@ -84,7 +83,7 @@ public: /// output latex to mark a transition between two changetypes /// returns length of text outputted - static int latexMarkChange(std::ostream & os, Change::Type old, + static int latexMarkChange(lyx::odocstream & os, Change::Type old, Change::Type change, bool const & output); /// output .lyx file format for transitions between changes diff --git a/src/cursor.C b/src/cursor.C index 8bf0a5788b..d37ff98a72 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -970,9 +970,10 @@ void LCursor::normalize() lyxerr << "this should not really happen - 2: " << pos() << ' ' << lastpos() << " in idx: " << idx() << " in atom: '"; - WriteStream wi(lyxerr, false, true); + lyx::odocstringstream os; + WriteStream wi(os, false, true); inset().asInsetMath()->write(wi); - lyxerr << endl; + lyxerr << lyx::to_utf8(os.str()) << endl; pos() = lastpos(); } } diff --git a/src/frontends/controllers/ControlViewSource.C b/src/frontends/controllers/ControlViewSource.C index 47a7bca30f..fc778a8c3c 100644 --- a/src/frontends/controllers/ControlViewSource.C +++ b/src/frontends/controllers/ControlViewSource.C @@ -21,7 +21,6 @@ #include using std::string; -using std::ostringstream; namespace lyx { namespace frontend { @@ -36,7 +35,7 @@ bool ControlViewSource::initialiseParams(string const & /*source*/) return true; } -string const ControlViewSource::updateContent(bool fullSource) +docstring const ControlViewSource::updateContent(bool fullSource) { // get the *top* level paragraphs that contain the cursor, // or the selected text @@ -53,7 +52,7 @@ string const ControlViewSource::updateContent(bool fullSource) } if (par_begin > par_end) std::swap(par_begin, par_end); - ostringstream ostr; + lyx::odocstringstream ostr; view->buffer()->getSourceCode(ostr, par_begin, par_end + 1, fullSource); return ostr.str(); } diff --git a/src/frontends/controllers/ControlViewSource.h b/src/frontends/controllers/ControlViewSource.h index 16598cfbf6..f55ca2d222 100644 --- a/src/frontends/controllers/ControlViewSource.h +++ b/src/frontends/controllers/ControlViewSource.h @@ -42,7 +42,7 @@ public: /** get the source code of selected paragraphs, or the whole document \param fullSource get full source code */ - std::string const updateContent(bool fullSource); + lyx::docstring const updateContent(bool fullSource); }; } // namespace frontend diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 57d100d722..f98ae0161f 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -43,6 +43,8 @@ namespace support = lyx::support; +using lyx::odocstream; + using std::endl; using std::find; using std::fill; @@ -54,8 +56,6 @@ using boost::bind; using std::ifstream; using std::list; using std::map; -using std::ofstream; -using std::ostream; using std::ostringstream; using std::pair; using std::vector; @@ -149,9 +149,9 @@ private: /// Called by the Forkedcall process that generated the bitmap files. void finishedGenerating(pid_t, int); /// - void dumpPreamble(ostream &) const; + void dumpPreamble(odocstream &) const; /// - void dumpData(ostream &, BitmapFile const &) const; + void dumpData(odocstream &, BitmapFile const &) const; /** cache_ allows easy retrieval of already-generated images * using the LaTeX snippet as the identifier. @@ -481,7 +481,10 @@ void PreviewLoader::Impl::startLoading() // Output the LaTeX file. string const latexfile = filename_base + ".tex"; - ofstream of(latexfile.c_str()); + // FIXME UNICODE + // This creates an utf8 encoded file, but the proper inputenc + // command is missing. + lyx::odocfstream of(latexfile.c_str()); if (!of) { lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()\n" << "Unable to create LaTeX file\n" @@ -582,7 +585,7 @@ void PreviewLoader::Impl::finishedGenerating(pid_t pid, int retval) } -void PreviewLoader::Impl::dumpPreamble(ostream & os) const +void PreviewLoader::Impl::dumpPreamble(odocstream & os) const { // Why on earth is Buffer::makeLaTeXFile a non-const method? Buffer & tmp = const_cast(buffer_); @@ -596,7 +599,7 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const // FIXME! This is a HACK! The proper fix is to control the 'true' // passed to WriteStream below: - // int InsetFormula::latex(Buffer const &, ostream & os, + // int InsetFormula::latex(Buffer const &, odocstream & os, // OutputParams const & runparams) const // { // WriteStream wi(os, runparams.moving_arg, true); @@ -629,7 +632,7 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const } -void PreviewLoader::Impl::dumpData(ostream & os, +void PreviewLoader::Impl::dumpData(odocstream & os, BitmapFile const & vec) const { if (vec.empty()) @@ -639,8 +642,9 @@ void PreviewLoader::Impl::dumpData(ostream & os, BitmapFile::const_iterator end = vec.end(); for (; it != end; ++it) { + // FIXME UNICODE os << "\\begin{preview}\n" - << it->first + << lyx::from_utf8(it->first) << "\n\\end{preview}\n\n"; } } diff --git a/src/insets/ExternalSupport.C b/src/insets/ExternalSupport.C index 7018d37db4..5795a2d5f6 100644 --- a/src/insets/ExternalSupport.C +++ b/src/insets/ExternalSupport.C @@ -32,13 +32,10 @@ #include "support/package.h" #include "support/path.h" -#include "support/std_ostream.h" - namespace support = lyx::support; using std::endl; -using std::ostream; using std::string; using std::vector; @@ -334,7 +331,7 @@ string const substituteOptions(InsetExternalParams const & params, int writeExternal(InsetExternalParams const & params, string const & format, - Buffer const & buffer, ostream & os, + Buffer const & buffer, lyx::odocstream & os, ExportData & exportdata, bool external_in_tmpdir, bool external_in_comment) @@ -362,7 +359,8 @@ int writeExternal(InsetExternalParams const & params, use_latex_path, external_in_tmpdir); str = substituteCommands(params, str, format); str = substituteOptions(params, str, format); - os << str; + // FIXME UNICODE + os << lyx::from_utf8(str); return int(lyx::count(str.begin(), str.end(),'\n')); } diff --git a/src/insets/ExternalSupport.h b/src/insets/ExternalSupport.h index e2a8d66b00..5fcbe40407 100644 --- a/src/insets/ExternalSupport.h +++ b/src/insets/ExternalSupport.h @@ -13,8 +13,7 @@ #ifndef EXTERNALSUPPORT_H #define EXTERNALSUPPORT_H -#include -#include +#include "support/docstream.h" class Buffer; class ExportData; @@ -63,7 +62,7 @@ std::string const doSubstitution(InsetExternalParams const & params, int writeExternal(InsetExternalParams const &, std::string const & format, Buffer const &, - std::ostream &, + lyx::odocstream &, ExportData &, bool external_in_tmpdir, bool external_in_comment); diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 8fe2477d24..4a9de2f6e7 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -34,6 +34,9 @@ #include +using lyx::odocstream; + + namespace { class InsetName { @@ -221,7 +224,7 @@ bool InsetBase::idxUpDown(LCursor &, bool) const int InsetBase::plaintext(Buffer const &, - lyx::odocstream &, OutputParams const &) const + odocstream &, OutputParams const &) const { return 0; } diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 3f99b98e6c..4f20e90216 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -356,7 +356,7 @@ public: /// read inset in .lyx format virtual void read(Buffer const &, LyXLex &) {} /// returns the number of rows (\n's) of generated tex code. - virtual int latex(Buffer const &, std::ostream &, + virtual int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const { return 0; } /// returns true to override begin and end inset in file virtual bool directWrite() const; diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index 1a973127d1..8939ff6dfa 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -26,6 +26,7 @@ #include "support/convert.h" using lyx::docstring; +using lyx::odocstream; using lyx::support::prefixIs; using std::max; @@ -109,7 +110,7 @@ docstring const InsetBibitem::getScreenLabel(Buffer const &) const } -int InsetBibitem::plaintext(Buffer const &, lyx::odocstream & os, +int InsetBibitem::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << '[' << getCounter() << "] "; diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index 3760f8f8af..ae89a8696a 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -37,6 +37,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::support::absolutePath; using lyx::support::ascii_lowercase; using lyx::support::changeExtension; @@ -126,7 +127,7 @@ string normalize_name(Buffer const & buffer, OutputParams const & runparams, } -int InsetBibtex::latex(Buffer const & buffer, ostream & os, +int InsetBibtex::latex(Buffer const & buffer, odocstream & os, OutputParams const & runparams) const { // the sequence of the commands: @@ -234,8 +235,9 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os, << endl; } } + // FIXME UNICODE os << "\\bibliographystyle{" - << latex_path(normalize_name(buffer, runparams, base, ".bst")) + << lyx::from_utf8(latex_path(normalize_name(buffer, runparams, base, ".bst"))) << "}\n"; nlines += 1; } @@ -244,18 +246,18 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os, static bool warned_about_bst_spaces = false; if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) { warned_about_bst_spaces = true; - // FIXME UNICODE Alert::warning(_("Export Warning!"), _("There are spaces in the path to your BibTeX style file.\n" "BibTeX will be unable to find it.")); } if (!db_out.empty() && buffer.params().use_bibtopic){ - os << "\\begin{btSect}{" << db_out << "}\n"; - string btprint = getSecOptions(); + // FIXME UNICODE + os << "\\begin{btSect}{" << lyx::from_utf8(db_out) << "}\n"; + docstring btprint = getParam("btprint"); if (btprint.empty()) // default - btprint = "btPrintCited"; + btprint = lyx::from_ascii("btPrintCited"); os << "\\" << btprint << "\n" << "\\end{btSect}\n"; nlines += 3; @@ -287,7 +289,8 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os, } if (!db_out.empty() && !buffer.params().use_bibtopic){ - os << "\\bibliography{" << db_out << "}\n"; + // FIXME UNICODE + os << "\\bibliography{" << lyx::from_utf8(db_out) << "}\n"; nlines += 1; } diff --git a/src/insets/insetbibtex.h b/src/insets/insetbibtex.h index 09ba9816f8..78e2d7b41e 100644 --- a/src/insets/insetbibtex.h +++ b/src/insets/insetbibtex.h @@ -31,7 +31,7 @@ public: /// bool display() const { return true; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// void fillWithBibKeys(Buffer const & buffer, diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index c87311d5e0..88a4716cf6 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -31,6 +31,7 @@ #include using lyx::docstring; +using lyx::odocstream; using std::auto_ptr; using std::string; @@ -245,7 +246,7 @@ bool InsetBox::getStatus(LCursor & cur, FuncRequest const & cmd, } -int InsetBox::latex(Buffer const & buf, ostream & os, +int InsetBox::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { BoxType btype = boxtranslator().find(params_.type); @@ -292,11 +293,14 @@ int InsetBox::latex(Buffer const & buf, ostream & os, if (!params_.inner_box) { os << "{\\makebox"; // Special widths, see usrguide §3.5 + // FIXME UNICODE if (params_.special != "none") { os << "[" << params_.width.value() - << "\\" << params_.special << "]"; + << '\\' << lyx::from_utf8(params_.special) + << ']'; } else - os << "[" << width_string << "]"; + os << '[' << lyx::from_ascii(width_string) + << ']'; if (params_.hor_pos != 'c') os << "[" << params_.hor_pos << "]"; } @@ -325,16 +329,21 @@ int InsetBox::latex(Buffer const & buf, ostream & os, os << "[" << params_.pos << "]"; if (params_.height_special == "none") { - os << "[" << params_.height.asLatexString() << "]"; + // FIXME UNICODE + os << '[' << lyx::from_ascii(params_.height.asLatexString()) + << ']'; } else { // Special heights + // FIXME UNICODE os << "[" << params_.height.value() - << "\\" << params_.height_special << "]"; + << '\\' << lyx::from_utf8(params_.height_special) + << ']'; } if (params_.inner_pos != params_.pos) os << "[" << params_.inner_pos << "]"; - os << "{" << width_string << "}"; + // FIXME UNICODE + os << '{' << lyx::from_ascii(width_string) << '}'; if (params_.use_parbox) os << "{"; @@ -381,7 +390,7 @@ int InsetBox::docbook(Buffer const & buf, std::ostream & os, } -int InsetBox::plaintext(Buffer const & buf, lyx::odocstream & os, +int InsetBox::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { BoxType const btype = boxtranslator().find(params_.type); diff --git a/src/insets/insetbox.h b/src/insets/insetbox.h index c3ff251896..f3c77eacf4 100644 --- a/src/insets/insetbox.h +++ b/src/insets/insetbox.h @@ -82,7 +82,7 @@ public: /// bool noFontChange() const { return true; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index fd3932db64..e215b444e8 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -27,6 +27,7 @@ #include using lyx::docstring; +using lyx::odocstream; using std::string; using std::auto_ptr; @@ -220,7 +221,7 @@ bool InsetBranch::isBranchSelected(Buffer const & buffer) const } -int InsetBranch::latex(Buffer const & buf, ostream & os, +int InsetBranch::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { return isBranchSelected(buf) ? @@ -236,7 +237,7 @@ int InsetBranch::docbook(Buffer const & buf, std::ostream & os, } -int InsetBranch::plaintext(Buffer const & buf, lyx::odocstream & os, +int InsetBranch::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { return isBranchSelected(buf) ? diff --git a/src/insets/insetbranch.h b/src/insets/insetbranch.h index 65e2310fb6..c811790ccf 100644 --- a/src/insets/insetbranch.h +++ b/src/insets/insetbranch.h @@ -53,7 +53,7 @@ public: /// bool showInsetDialog(BufferView *) const; /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index bf4c5c976e..791e4566a4 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -35,13 +35,13 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::support::bformat; using std::auto_ptr; using std::endl; using std::string; using std::ostream; -using std::ostringstream; InsetCaption::InsetCaption(BufferParams const & bp) @@ -176,7 +176,7 @@ InsetBase * InsetCaption::editXY(LCursor & cur, int x, int y) } -int InsetCaption::latex(Buffer const & buf, ostream & os, +int InsetCaption::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { // This is a bit too simplistic to take advantage of @@ -184,14 +184,14 @@ int InsetCaption::latex(Buffer const & buf, ostream & os, // This code is currently only able to handle the simple // \caption{...}, later we will make it take advantage // of the one of the caption packages. (Lgb) - ostringstream ost; + lyx::odocstringstream ost; int const l = InsetText::latex(buf, ost, runparams); os << "\\caption{" << ost.str() << "}\n"; return l + 1; } -int InsetCaption::plaintext(Buffer const & /*buf*/, lyx::odocstream & /*os*/, +int InsetCaption::plaintext(Buffer const & /*buf*/, odocstream & /*os*/, OutputParams const & /*runparams*/) const { // FIXME: Implement me! diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index ab6d971155..ed4607d235 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -48,7 +48,7 @@ public: /// virtual InsetBase * editXY(LCursor & cur, int x, int y); /// - virtual int latex(Buffer const & buf, std::ostream & os, + virtual int latex(Buffer const & buf, lyx::odocstream & os, OutputParams const &) const; /// int plaintext(Buffer const & buf, lyx::odocstream & os, diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index c187b4f4e9..1f5a0520b1 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -39,6 +39,7 @@ #include using lyx::docstring; +using lyx::odocstream; using std::string; using std::auto_ptr; @@ -282,14 +283,15 @@ bool InsetCharStyle::getStatus(LCursor & cur, FuncRequest const & cmd, } -int InsetCharStyle::latex(Buffer const & buf, ostream & os, +int InsetCharStyle::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { if (!undefined()) { - os << "\\" << params_.latexname; + // FIXME UNICODE + os << '\\' << lyx::from_utf8(params_.latexname); if (!params_.latexparam.empty()) - os << params_.latexparam; - os << "{"; + os << lyx::from_utf8(params_.latexparam); + os << '{'; } int i = InsetText::latex(buf, os, runparams); if (!undefined()) @@ -322,14 +324,14 @@ int InsetCharStyle::docbook(Buffer const & buf, ostream & os, } -int InsetCharStyle::plaintext(Buffer const & buf, lyx::odocstream & os, +int InsetCharStyle::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { return InsetText::plaintext(buf, os, runparams); } -int InsetCharStyle::textString(Buffer const & buf, lyx::odocstream & os, +int InsetCharStyle::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetcharstyle.h b/src/insets/insetcharstyle.h index a497a81dbb..8fa1e9b58c 100644 --- a/src/insets/insetcharstyle.h +++ b/src/insets/insetcharstyle.h @@ -73,7 +73,7 @@ public: /// bool forceDefaultParagraphs(idx_type) const { return true; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 1d8a16cf4b..7ec2e87b48 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -31,6 +31,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::support::ascii_lowercase; using lyx::support::contains; using lyx::support::getStringFromVector; @@ -357,7 +358,7 @@ docstring const InsetCitation::getScreenLabel(Buffer const & buffer) const } -int InsetCitation::plaintext(Buffer const & buffer, lyx::odocstream & os, +int InsetCitation::plaintext(Buffer const & buffer, odocstream & os, OutputParams const &) const { if (cache.params == params() && @@ -398,7 +399,7 @@ int InsetCitation::docbook(Buffer const &, ostream & os, OutputParams const &) c } -int InsetCitation::textString(Buffer const & buf, lyx::odocstream & os, +int InsetCitation::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); @@ -409,23 +410,25 @@ int InsetCitation::textString(Buffer const & buf, lyx::odocstream & os, // the \cite command is valid. Eg, the user has natbib enabled, inputs some // citations and then changes his mind, turning natbib support off. The output // should revert to \cite[]{} -int InsetCitation::latex(Buffer const & buffer, ostream & os, +int InsetCitation::latex(Buffer const & buffer, odocstream & os, OutputParams const &) const { biblio::CiteEngine const cite_engine = buffer.params().cite_engine; - string const cite_str = - biblio::asValidLatexCommand(getCmdName(), cite_engine); + // FIXME UNICODE + docstring const cite_str = lyx::from_utf8( + biblio::asValidLatexCommand(getCmdName(), cite_engine)); os << "\\" << cite_str; - string const before = getSecOptions(); - string const after = getOptions(); + docstring const & before = getParam("before"); + docstring const & after = getParam("after"); if (!before.empty() && cite_engine != biblio::ENGINE_BASIC) os << '[' << before << "][" << after << ']'; else if (!after.empty()) os << '[' << after << ']'; - os << '{' << cleanupWhitespace(getContents()) << '}'; + // FIXME UNICODE + os << '{' << lyx::from_utf8(cleanupWhitespace(getContents())) << '}'; return 0; } diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index 4a05147a11..34d43d4c1e 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -33,7 +33,7 @@ public: /// int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 12f6f386fa..764b63d90d 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -23,6 +23,8 @@ #include +using lyx::odocstream; + using std::string; using std::istringstream; using std::ostream; @@ -70,7 +72,7 @@ void InsetCommand::setParams(InsetCommandParams const & p) } -int InsetCommand::latex(Buffer const &, ostream & os, +int InsetCommand::latex(Buffer const &, odocstream & os, OutputParams const &) const { os << getCommand(); @@ -78,7 +80,7 @@ int InsetCommand::latex(Buffer const &, ostream & os, } -int InsetCommand::plaintext(Buffer const &, lyx::odocstream &, +int InsetCommand::plaintext(Buffer const &, odocstream &, OutputParams const &) const { return 0; diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 7a98c8d2be..af224f7846 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -48,7 +48,7 @@ public: /// FIXME remove void scanCommand(std::string const & c) { p_.scanCommand(c); }; /// - virtual int latex(Buffer const &, std::ostream &, + virtual int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, @@ -95,7 +95,7 @@ protected: /// bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const; /// - std::string const getCommand() const { return p_.getCommand(); } + lyx::docstring const getCommand() const { return p_.getCommand(); } /// std::string const & getCmdName() const { return p_.getCmdName(); } /// diff --git a/src/insets/insetcommandparams.C b/src/insets/insetcommandparams.C index 80bb576d5a..288f885609 100644 --- a/src/insets/insetcommandparams.C +++ b/src/insets/insetcommandparams.C @@ -228,7 +228,7 @@ void InsetCommandParams::scanCommand(string const & cmd) if (lyxerr.debugging(Debug::PARSER)) lyxerr << "Command <" << cmd - << "> == <" << getCommand() + << "> == <" << lyx::to_utf8(getCommand()) << "> == <" << getCmdName() << '|' << getContents() << '|' << getOptions() @@ -284,7 +284,7 @@ void InsetCommandParams::write(ostream & os) const } -string const InsetCommandParams::getCommand() const +docstring const InsetCommandParams::getCommand() const { docstring s = '\\' + lyx::from_ascii(name_); for (size_t i = 0; i < info_->n; ++i) { @@ -306,7 +306,7 @@ string const InsetCommandParams::getCommand() const } else s += '{' + params_[i] + '}'; } - return lyx::to_utf8(s); + return s; } diff --git a/src/insets/insetcommandparams.h b/src/insets/insetcommandparams.h index 97f871ba92..3b26fbce7c 100644 --- a/src/insets/insetcommandparams.h +++ b/src/insets/insetcommandparams.h @@ -34,7 +34,7 @@ public: /// void write(std::ostream &) const; /// Build the complete LaTeX command - std::string const getCommand() const; + lyx::docstring const getCommand() const; /// Return the command name std::string const & getCmdName() const { return name_; } /// FIXME remove diff --git a/src/insets/insetenv.C b/src/insets/insetenv.C index 5bfb58db25..a8e7a13575 100644 --- a/src/insets/insetenv.C +++ b/src/insets/insetenv.C @@ -18,10 +18,9 @@ #include "output_latex.h" #include "texrow.h" -#include "support/std_ostream.h" - using lyx::docstring; +using lyx::odocstream; using std::string; using std::auto_ptr; @@ -69,14 +68,16 @@ docstring const InsetEnvironment::editMessage() const } -int InsetEnvironment::latex(Buffer const & buf, ostream & os, +int InsetEnvironment::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - os << layout_->latexheader; + // FIXME UNICODE + os << lyx::from_utf8(layout_->latexheader); TexRow texrow; latexParagraphs(buf, paragraphs(), os, texrow, runparams, layout_->latexparagraph); - os << layout_->latexfooter; + // FIXME UNICODE + os << lyx::from_utf8(layout_->latexfooter); return texrow.rows(); } diff --git a/src/insets/insetenv.h b/src/insets/insetenv.h index 51592f29c2..8a10862c70 100644 --- a/src/insets/insetenv.h +++ b/src/insets/insetenv.h @@ -27,7 +27,7 @@ public: /// InsetBase::Code lyxCode() const { return InsetBase::ENVIRONMENT_CODE; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// virtual lyx::docstring const editMessage() const; diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 4bc0275f61..2bc7bc89b4 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -36,6 +36,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::pos_type; using lyx::support::token; @@ -143,7 +144,7 @@ docstring const InsetERT::editMessage() const } -int InsetERT::latex(Buffer const &, ostream & os, +int InsetERT::latex(Buffer const &, odocstream & os, OutputParams const &) const { ParagraphList::const_iterator par = paragraphs().begin(); @@ -157,7 +158,7 @@ int InsetERT::latex(Buffer const &, ostream & os, if (par->isDeleted(i)) continue; - os << par->getChar(i); + os.put(par->getChar(i)); } ++par; if (par != end) { @@ -170,7 +171,7 @@ int InsetERT::latex(Buffer const &, ostream & os, } -int InsetERT::plaintext(Buffer const &, lyx::odocstream &, +int InsetERT::plaintext(Buffer const &, odocstream &, OutputParams const & /*runparams*/) const { return 0; @@ -187,7 +188,7 @@ int InsetERT::docbook(Buffer const &, ostream & os, while (par != end) { pos_type siz = par->size(); for (pos_type i = 0; i < siz; ++i) - os << par->getChar(i); + os.put(par->getChar(i)); ++par; if (par != end) { os << "\n"; diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 801f4e4a44..3a93e067db 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -49,7 +49,7 @@ public: /// bool insetAllowed(InsetBase::Code code) const; /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 586b46cfd8..51fd1a8916 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -49,6 +49,8 @@ namespace external = lyx::external; namespace graphics = lyx::graphics; using lyx::docstring; +using lyx::odocstream; + using std::endl; using std::string; using std::auto_ptr; @@ -676,12 +678,13 @@ void InsetExternal::read(Buffer const & buffer, LyXLex & lex) } -int InsetExternal::latex(Buffer const & buf, ostream & os, +int InsetExternal::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { if (params_.draft) { + // FIXME UNICODE os << "\\fbox{\\ttfamily{}" - << params_.filename.outputFilename(buf.filePath()) + << lyx::from_utf8(params_.filename.outputFilename(buf.filePath())) << "}\n"; return 1; } @@ -717,25 +720,25 @@ int InsetExternal::latex(Buffer const & buf, ostream & os, } -int InsetExternal::plaintext(Buffer const & buf, lyx::odocstream & os, +int InsetExternal::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - std::ostringstream oss; - int const retval = external::writeExternal(params_, "Ascii", buf, oss, + return external::writeExternal(params_, "Ascii", buf, os, *(runparams.exportdata), false, runparams.inComment); - // FIXME UNICODE - os << lyx::from_utf8(oss.str()); - return retval; } int InsetExternal::docbook(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - return external::writeExternal(params_, "DocBook", buf, os, + lyx::odocstringstream oss; + int const retval = external::writeExternal(params_, "DocBook", buf, oss, *(runparams.exportdata), false, runparams.inComment); + // FIXME UNICODE + os << lyx::to_utf8(oss.str()); + return retval; } @@ -802,9 +805,9 @@ bool preview_wanted(InsetExternalParams const & params) } -string const latex_string(InsetExternal const & inset, Buffer const & buffer) +docstring const latex_string(InsetExternal const & inset, Buffer const & buffer) { - ostringstream os; + lyx::odocstringstream os; OutputParams runparams; runparams.flavor = OutputParams::LATEX; inset.latex(buffer, os, runparams); @@ -822,7 +825,7 @@ void add_preview_and_start_loading(RenderMonitoredPreview & renderer, if (RenderPreview::status() != LyXRC::PREVIEW_OFF && preview_wanted(params)) { renderer.setAbsFile(params.filename.absFilename()); - string const snippet = latex_string(inset, buffer); + docstring const snippet = latex_string(inset, buffer); renderer.addPreview(snippet, buffer); renderer.startLoading(buffer); } @@ -839,7 +842,7 @@ void InsetExternal::addPreview(graphics::PreviewLoader & ploader) const if (preview_wanted(params())) { ptr->setAbsFile(params_.filename.absFilename()); - string const snippet = latex_string(*this, ploader.buffer()); + docstring const snippet = latex_string(*this, ploader.buffer()); ptr->addPreview(snippet, ploader); } } diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 7ad563a070..fefcc2a840 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -123,7 +123,7 @@ public: virtual void read(Buffer const &, LyXLex & lex); /// \returns the number of rows (\n's) of generated code. - virtual int latex(Buffer const &, std::ostream &, + virtual int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// virtual int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 6e617210a4..5af4753fea 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -37,6 +37,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::support::contains; using std::endl; @@ -279,7 +280,7 @@ docstring const InsetFloat::editMessage() const } -int InsetFloat::latex(Buffer const & buf, ostream & os, +int InsetFloat::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { FloatList const & floats = buf.params().getLyXTextClass().floats(); @@ -310,11 +311,11 @@ int InsetFloat::latex(Buffer const & buf, ostream & os, // The \n is used to force \begin{} to appear in a new line. // The % is needed to prevent two consecutive \n chars in the case // when the current output line is empty. - os << "%\n\\begin{" << tmptype << '}'; + os << "%\n\\begin{" << lyx::from_ascii(tmptype) << '}'; // We only output placement if different from the def_placement. // sidewaysfloats always use their own page if (!placement.empty() && !params_.sideways) { - os << '[' << placement << ']'; + os << '[' << lyx::from_ascii(placement) << ']'; } os << '\n'; @@ -322,7 +323,7 @@ int InsetFloat::latex(Buffer const & buf, ostream & os, // The \n is used to force \end{} to appear in a new line. // In this case, we do not case if the current output line is empty. - os << "\n\\end{" << tmptype << "}\n"; + os << "\n\\end{" << lyx::from_ascii(tmptype) << "}\n"; return i + 4; } diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index 0303197b57..10774bb296 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -54,7 +54,7 @@ public: /// InsetBase::Code lyxCode() const { return InsetBase::FLOAT_CODE; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index 0064f2dede..11d40d24ff 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -28,6 +28,7 @@ #include "support/lstrings.h" using lyx::docstring; +using lyx::odocstream; using lyx::support::bformat; using std::endl; @@ -79,7 +80,7 @@ void InsetFloatList::read(Buffer const & buf, LyXLex & lex) } -int InsetFloatList::latex(Buffer const & buf, ostream & os, +int InsetFloatList::latex(Buffer const & buf, odocstream & os, OutputParams const &) const { FloatList const & floats = buf.params().getLyXTextClass().floats(); @@ -98,20 +99,20 @@ int InsetFloatList::latex(Buffer const & buf, ostream & os, } } else { // FIXME UNICODE - os << "\\listof{" << getCmdName() << "}{" - << lyx::to_utf8(buf.B_(cit->second.listName())) << "}\n"; + os << "\\listof{" << lyx::from_ascii(getCmdName()) << "}{" + << buf.B_(cit->second.listName()) << "}\n"; } } else { // FIXME UNICODE - os << "%%\\listof{" << getCmdName() << "}{" - << lyx::to_utf8(bformat(_("List of %1$s"), lyx::from_utf8(cit->second.name()))) + os << "%%\\listof{" << lyx::from_ascii(getCmdName()) << "}{" + << bformat(_("List of %1$s"), lyx::from_utf8(cit->second.name())) << "}\n"; } return 1; } -int InsetFloatList::plaintext(Buffer const & buffer, lyx::odocstream & os, +int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os, OutputParams const &) const { os << getScreenLabel(buffer) << "\n\n"; diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index 301d14c8a0..9392089e0d 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -36,7 +36,7 @@ public: /// void read(Buffer const &, LyXLex &); /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 3ba32488b7..43bad6df97 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -24,6 +24,7 @@ #include "support/std_ostream.h" using lyx::docstring; +using lyx::odocstream; using std::string; using std::auto_ptr; @@ -58,7 +59,7 @@ docstring const InsetFoot::editMessage() const } -int InsetFoot::latex(Buffer const & buf, ostream & os, +int InsetFoot::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams_in) const { OutputParams runparams = runparams_in; diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index 640014c133..2d35572338 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -25,7 +25,7 @@ public: /// InsetBase::Code lyxCode() const { return InsetBase::FOOT_CODE; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index cceb22e3fa..12a810ae9d 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -87,6 +87,8 @@ TODO #include +using lyx::odocstream; + namespace support = lyx::support; using lyx::support::absolutePath; @@ -735,7 +737,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf, } -int InsetGraphics::latex(Buffer const & buf, ostream & os, +int InsetGraphics::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { // If there is no file specified or not existing, @@ -795,7 +797,8 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os, // (when there are several versions in different formats) latex_str += prepareFile(buf, runparams); latex_str += '}' + after; - os << latex_str; + // FIXME UNICODE + os << lyx::from_utf8(latex_str); lyxerr[Debug::GRAPHICS] << "InsetGraphics::latex outputting:\n" << latex_str << endl; @@ -804,7 +807,7 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os, } -int InsetGraphics::plaintext(Buffer const &, lyx::odocstream & os, +int InsetGraphics::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { // No graphics in ascii output. Possible to use gifscii to convert diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index effe8489e0..3d3a89ea6f 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -43,7 +43,7 @@ public: #fragile == true# means, that the inset should take care about fragile commands by adding a #\protect# before. */ - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insethfill.C b/src/insets/insethfill.C index 03d7abb2fa..dbf49cb9c1 100644 --- a/src/insets/insethfill.C +++ b/src/insets/insethfill.C @@ -15,6 +15,7 @@ #include "support/std_ostream.h" using lyx::docstring; +using lyx::odocstream; using std::ostream; @@ -45,7 +46,7 @@ docstring const InsetHFill::getScreenLabel(Buffer const &) const } -int InsetHFill::latex(Buffer const &, ostream & os, +int InsetHFill::latex(Buffer const &, odocstream & os, OutputParams const &) const { os << getCommand(); @@ -53,7 +54,7 @@ int InsetHFill::latex(Buffer const &, ostream & os, } -int InsetHFill::plaintext(Buffer const &, lyx::odocstream & os, +int InsetHFill::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << '\t'; diff --git a/src/insets/insethfill.h b/src/insets/insethfill.h index cd66169d10..309d4975f8 100644 --- a/src/insets/insethfill.h +++ b/src/insets/insethfill.h @@ -26,7 +26,7 @@ public: /// InsetBase::Code lyxCode() const { return InsetBase::HFILL_CODE; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index a25756aede..682f78b303 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -54,6 +54,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::support::addName; using lyx::support::absolutePath; using lyx::support::bformat; @@ -258,7 +259,7 @@ void InsetInclude::write(Buffer const &, ostream & os) const void InsetInclude::write(ostream & os) const { - os << "Include " << params_.getCommand() << '\n' + os << "Include " << lyx::to_utf8(params_.getCommand()) << '\n' << "preview " << convert(params_.preview()) << '\n'; } @@ -350,7 +351,7 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params) } // namespace anon -int InsetInclude::latex(Buffer const & buffer, ostream & os, +int InsetInclude::latex(Buffer const & buffer, odocstream & os, OutputParams const & runparams) const { string incfile(params_.getContents()); @@ -435,7 +436,9 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, "latex" : "pdflatex"; if (isVerbatim(params_)) { incfile = latex_path(incfile); - os << '\\' << params_.getCmdName() << '{' << incfile << '}'; + // FIXME UNICODE + os << '\\' << lyx::from_ascii(params_.getCmdName()) << '{' + << lyx::from_utf8(incfile) << '}'; } else if (type(params_) == INPUT) { runparams.exportdata->addExternalFile(tex_format, writefile, exportfile); @@ -443,13 +446,15 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, // \input wants file with extension (default is .tex) if (!isLyXFilename(included_file)) { incfile = latex_path(incfile); - os << '\\' << params_.getCmdName() << '{' << incfile << '}'; + // FIXME UNICODE + os << '\\' << lyx::from_ascii(params_.getCmdName()) + << '{' << lyx::from_utf8(incfile) << '}'; } else { incfile = changeExtension(incfile, ".tex"); incfile = latex_path(incfile); - os << '\\' << params_.getCmdName() << '{' - << incfile - << '}'; + // FIXME UNICODE + os << '\\' << lyx::from_ascii(params_.getCmdName()) + << '{' << lyx::from_utf8(incfile) << '}'; } } else { runparams.exportdata->addExternalFile(tex_format, writefile, @@ -459,16 +464,16 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, // file really have .tex incfile = changeExtension(incfile, string()); incfile = latex_path(incfile); - os << '\\' << params_.getCmdName() << '{' - << incfile - << '}'; + // FIXME UNICODE + os << '\\' << lyx::from_ascii(params_.getCmdName()) << '{' + << lyx::from_utf8(incfile) << '}'; } return 0; } -int InsetInclude::plaintext(Buffer const & buffer, lyx::odocstream & os, +int InsetInclude::plaintext(Buffer const & buffer, odocstream & os, OutputParams const &) const { if (isVerbatim(params_)) { @@ -708,9 +713,9 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer) } -string const latex_string(InsetInclude const & inset, Buffer const & buffer) +docstring const latex_string(InsetInclude const & inset, Buffer const & buffer) { - ostringstream os; + lyx::odocstringstream os; OutputParams runparams; runparams.flavor = OutputParams::LATEX; inset.latex(buffer, os, runparams); @@ -726,7 +731,7 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset, if (RenderPreview::status() != LyXRC::PREVIEW_OFF && preview_wanted(params, buffer)) { renderer.setAbsFile(includedFilename(buffer, params)); - string const snippet = latex_string(inset, buffer); + docstring const snippet = latex_string(inset, buffer); renderer.addPreview(snippet, buffer); } } @@ -739,7 +744,7 @@ void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const Buffer const & buffer = ploader.buffer(); if (preview_wanted(params(), buffer)) { preview_->setAbsFile(includedFilename(buffer, params())); - string const snippet = latex_string(*this, buffer); + docstring const snippet = latex_string(*this, buffer); preview_->addPreview(snippet, ploader); } } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 6b911ce563..cf0a660643 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -75,7 +75,7 @@ public: /// void read(Buffer const &, LyXLex &); /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 53b53e29b8..98110bdc14 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -27,6 +27,7 @@ #include "support/std_ostream.h" using lyx::docstring; +using lyx::odocstream; using lyx::support::escape; using std::string; @@ -84,7 +85,7 @@ void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd) } -int InsetLabel::latex(Buffer const &, ostream & os, +int InsetLabel::latex(Buffer const &, odocstream & os, OutputParams const &) const { os << escape(getCommand()); @@ -92,7 +93,7 @@ int InsetLabel::latex(Buffer const &, ostream & os, } -int InsetLabel::plaintext(Buffer const &, lyx::odocstream & os, +int InsetLabel::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { // FIXME UNICODE diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index 255f503f42..a67e2f7c29 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -27,7 +27,7 @@ public: /// Appends \c list with this label void getLabelList(Buffer const &, std::vector & list) const; /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 901fa926fb..720c858fc4 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -26,6 +26,7 @@ using lyx::char_type; using lyx::docstring; +using lyx::odocstream; using lyx::support::contains; using lyx::support::trim; @@ -571,15 +572,15 @@ void InsetLatexAccent::read(Buffer const &, LyXLex & lex) } -int InsetLatexAccent::latex(Buffer const &, ostream & os, +int InsetLatexAccent::latex(Buffer const &, odocstream & os, OutputParams const &) const { - os << contents; + os << lyx::from_ascii(contents); return 0; } -int InsetLatexAccent::plaintext(Buffer const &, lyx::odocstream & os, +int InsetLatexAccent::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << lyx::from_ascii(contents); @@ -595,7 +596,7 @@ int InsetLatexAccent::docbook(Buffer const &, ostream & os, } -int InsetLatexAccent::textString(Buffer const & buf, lyx::odocstream & os, +int InsetLatexAccent::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 4e3fd9cc06..a96358dfb5 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -43,7 +43,7 @@ public: /// void read(Buffer const &, LyXLex & lex); /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetline.C b/src/insets/insetline.C index 8a83f7c17c..f6390c91b6 100644 --- a/src/insets/insetline.C +++ b/src/insets/insetline.C @@ -21,6 +21,7 @@ #include "frontends/Painter.h" +using lyx::odocstream; using lyx::frontend::Painter; using std::endl; @@ -55,15 +56,16 @@ void InsetLine::draw(PainterInfo & pi, int x, int y) const } -int InsetLine::latex(Buffer const &, ostream & os, +int InsetLine::latex(Buffer const &, odocstream & os, OutputParams const & runparams) const { - os << "\\lyxline{\\" << runparams.local_font->latexSize() << '}'; + os << "\\lyxline{\\" + << lyx::from_ascii(runparams.local_font->latexSize()) << '}'; return 0; } -int InsetLine::plaintext(Buffer const &, lyx::odocstream & os, +int InsetLine::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << "-------------------------------------------"; diff --git a/src/insets/insetline.h b/src/insets/insetline.h index 1297b6fcc2..5950b47d98 100644 --- a/src/insets/insetline.h +++ b/src/insets/insetline.h @@ -26,7 +26,7 @@ public: void draw(PainterInfo & pi, int x, int y) const; - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetmarginal.C b/src/insets/insetmarginal.C index 4498db12e4..b106cc152d 100644 --- a/src/insets/insetmarginal.C +++ b/src/insets/insetmarginal.C @@ -19,6 +19,7 @@ #include "support/std_ostream.h" using lyx::docstring; +using lyx::odocstream; using std::string; using std::auto_ptr; @@ -53,7 +54,7 @@ docstring const InsetMarginal::editMessage() const } -int InsetMarginal::latex(Buffer const & buf, ostream & os, +int InsetMarginal::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { os << "%\n\\marginpar{"; diff --git a/src/insets/insetmarginal.h b/src/insets/insetmarginal.h index 3552a49bae..68d595d9d6 100644 --- a/src/insets/insetmarginal.h +++ b/src/insets/insetmarginal.h @@ -26,7 +26,7 @@ public: /// InsetBase::Code lyxCode() const { return InsetBase::MARGIN_CODE; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetnewline.C b/src/insets/insetnewline.C index 0079488fe5..6057da5080 100644 --- a/src/insets/insetnewline.C +++ b/src/insets/insetnewline.C @@ -22,6 +22,8 @@ #include "frontends/FontMetrics.h" #include "frontends/Painter.h" +using lyx::odocstream; + using std::endl; using std::ostream; @@ -49,7 +51,7 @@ void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const } -int InsetNewline::latex(Buffer const &, ostream &, +int InsetNewline::latex(Buffer const &, odocstream &, OutputParams const &) const { lyxerr << "Eek, calling InsetNewline::latex !" << endl; @@ -57,7 +59,7 @@ int InsetNewline::latex(Buffer const &, ostream &, } -int InsetNewline::plaintext(Buffer const &, lyx::odocstream & os, +int InsetNewline::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << '\n'; diff --git a/src/insets/insetnewline.h b/src/insets/insetnewline.h index b8e2da897a..2a17ae4d0f 100644 --- a/src/insets/insetnewline.h +++ b/src/insets/insetnewline.h @@ -26,7 +26,7 @@ public: virtual void draw(PainterInfo & pi, int x, int y) const; - virtual int latex(Buffer const &, std::ostream &, + virtual int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; virtual int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 33916d7cae..decb4785a2 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -35,6 +35,7 @@ #include using lyx::docstring; +using lyx::odocstream; using std::string; using std::auto_ptr; @@ -250,7 +251,7 @@ bool InsetNote::getStatus(LCursor & cur, FuncRequest const & cmd, } -int InsetNote::latex(Buffer const & buf, ostream & os, +int InsetNote::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams_in) const { if (params_.type == InsetNoteParams::Note) @@ -270,10 +271,10 @@ int InsetNote::latex(Buffer const & buf, ostream & os, else if (params_.type == InsetNoteParams::Shaded) type = "shaded"; - ostringstream ss; - ss << "%\n\\begin{" << type << "}\n"; + lyx::odocstringstream ss; + ss << "%\n\\begin{" << lyx::from_ascii(type) << "}\n"; InsetText::latex(buf, ss, runparams); - ss << "\n\\end{" << type << "}\n"; + ss << "\n\\end{" << lyx::from_ascii(type) << "}\n"; // the space after the comment in 'a[comment] b' will be eaten by the // comment environment since the space before b is ignored with the // following latex output: @@ -288,10 +289,10 @@ int InsetNote::latex(Buffer const & buf, ostream & os, if (params_.type == InsetNoteParams::Comment) ss << "{}"; - string const str = ss.str(); + docstring const str = ss.str(); os << str; // Return how many newlines we issued. - return int(lyx::count(str.begin(), str.end(),'\n')); + return int(lyx::count(str.begin(), str.end(), '\n')); } @@ -322,7 +323,7 @@ int InsetNote::docbook(Buffer const & buf, std::ostream & os, } -int InsetNote::plaintext(Buffer const & buf, lyx::odocstream & os, +int InsetNote::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams_in) const { if (params_.type == InsetNoteParams::Note) diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index 4fe09a452e..3b4d739a85 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -57,7 +57,7 @@ public: /// show the note dialog bool showInsetDialog(BufferView * bv) const; /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetoptarg.C b/src/insets/insetoptarg.C index 7eb44dafc4..e78ce9076c 100644 --- a/src/insets/insetoptarg.C +++ b/src/insets/insetoptarg.C @@ -20,6 +20,7 @@ #include using lyx::docstring; +using lyx::odocstream; using std::string; using std::auto_ptr; @@ -66,7 +67,7 @@ void InsetOptArg::write(Buffer const & buf, ostream & os) const } -int InsetOptArg::latex(Buffer const &, ostream &, +int InsetOptArg::latex(Buffer const &, odocstream &, OutputParams const &) const { return 0; @@ -79,20 +80,20 @@ int InsetOptArg::docbook(Buffer const &, ostream &, } -int InsetOptArg::plaintext(Buffer const &, lyx::odocstream &, +int InsetOptArg::plaintext(Buffer const &, odocstream &, OutputParams const &) const { return 0; } -int InsetOptArg::latexOptional(Buffer const & buf, ostream & os, +int InsetOptArg::latexOptional(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - ostringstream ss; + lyx::odocstringstream ss; int ret = InsetText::latex(buf, ss, runparams); - string str = ss.str(); - if (str.find(']') != string::npos) + docstring str = ss.str(); + if (str.find(']') != docstring::npos) str = '{' + str + '}'; os << '[' << str << ']'; return ret; diff --git a/src/insets/insetoptarg.h b/src/insets/insetoptarg.h index 0454519740..09f7f70f3c 100644 --- a/src/insets/insetoptarg.h +++ b/src/insets/insetoptarg.h @@ -30,7 +30,7 @@ public: virtual lyx::docstring const editMessage() const; /// Standard LaTeX output -- short-circuited - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// Standard DocBook output -- short-circuited int docbook(Buffer const &, std::ostream &, @@ -41,7 +41,7 @@ public: OutputParams const &) const; /// Outputting the optional parameter of a LaTeX command - int latexOptional(Buffer const &, std::ostream &, + int latexOptional(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// Write out tothe .lyx file void write(Buffer const & buf, std::ostream & os) const; diff --git a/src/insets/insetpagebreak.C b/src/insets/insetpagebreak.C index 9c55d83d88..e63e8039f1 100644 --- a/src/insets/insetpagebreak.C +++ b/src/insets/insetpagebreak.C @@ -22,6 +22,7 @@ #include "frontends/Painter.h" using lyx::docstring; +using lyx::odocstream; using lyx::frontend::Painter; using std::endl; @@ -75,7 +76,7 @@ void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const } -int InsetPagebreak::latex(Buffer const &, ostream & os, +int InsetPagebreak::latex(Buffer const &, odocstream & os, OutputParams const &) const { os << "\\newpage{}"; @@ -83,7 +84,7 @@ int InsetPagebreak::latex(Buffer const &, ostream & os, } -int InsetPagebreak::plaintext(Buffer const &, lyx::odocstream & os, +int InsetPagebreak::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << '\n'; diff --git a/src/insets/insetpagebreak.h b/src/insets/insetpagebreak.h index 8ee273ec06..9e3f627482 100644 --- a/src/insets/insetpagebreak.h +++ b/src/insets/insetpagebreak.h @@ -26,7 +26,7 @@ public: void draw(PainterInfo & pi, int x, int y) const; - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 378a6e34ce..c18861011e 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -31,6 +31,7 @@ using lyx::docstring; +using lyx::odocstream; using lyx::support::prefixIs; using std::endl; @@ -268,7 +269,7 @@ void InsetQuotes::read(Buffer const &, LyXLex & lex) } -int InsetQuotes::latex(Buffer const &, ostream & os, +int InsetQuotes::latex(Buffer const &, odocstream & os, OutputParams const & runparams) const { const int quoteind = quote_index[side_][language_]; @@ -296,12 +297,12 @@ int InsetQuotes::latex(Buffer const &, ostream & os, if (prefixIs(qstr, "`")) qstr.insert(0, "{}"); - os << qstr; + os << lyx::from_ascii(qstr); return 0; } -int InsetQuotes::plaintext(Buffer const &, lyx::odocstream & os, +int InsetQuotes::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << '"'; @@ -327,7 +328,7 @@ int InsetQuotes::docbook(Buffer const &, ostream & os, } -int InsetQuotes::textString(Buffer const & buf, lyx::odocstream & os, +int InsetQuotes::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index 0d51ecfb55..bc39895d08 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -84,7 +84,7 @@ public: /// void read(Buffer const &, LyXLex & lex); /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetref.C b/src/insets/insetref.C index 2955e72055..5ae1406d10 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -25,6 +25,7 @@ using lyx::docstring; +using lyx::odocstream; using lyx::support::escape; using std::string; @@ -84,7 +85,7 @@ docstring const InsetRef::getScreenLabel(Buffer const &) const } -int InsetRef::latex(Buffer const &, ostream & os, +int InsetRef::latex(Buffer const &, odocstream & os, OutputParams const &) const { // Don't output p_["name"], this is only used in docbook @@ -95,7 +96,7 @@ int InsetRef::latex(Buffer const &, ostream & os, } -int InsetRef::plaintext(Buffer const &, lyx::odocstream & os, +int InsetRef::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { // FIXME UNICODE @@ -120,7 +121,7 @@ int InsetRef::docbook(Buffer const & buf, ostream & os, } -int InsetRef::textString(Buffer const & buf, lyx::odocstream & os, +int InsetRef::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 35550dde37..cbeba3fbc1 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -44,7 +44,7 @@ public: /// bool display() const { return false; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetspace.C b/src/insets/insetspace.C index bd7faede4a..e41017b33c 100644 --- a/src/insets/insetspace.C +++ b/src/insets/insetspace.C @@ -25,6 +25,8 @@ #include "frontends/Painter.h" +using lyx::odocstream; + using std::string; using std::max; using std::auto_ptr; @@ -162,7 +164,7 @@ void InsetSpace::read(Buffer const &, LyXLex & lex) } -int InsetSpace::latex(Buffer const &, ostream & os, +int InsetSpace::latex(Buffer const &, odocstream & os, OutputParams const & runparams) const { switch (kind_) { @@ -195,7 +197,7 @@ int InsetSpace::latex(Buffer const &, ostream & os, } -int InsetSpace::plaintext(Buffer const &, lyx::odocstream & os, +int InsetSpace::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { switch (kind_) { @@ -235,7 +237,7 @@ int InsetSpace::docbook(Buffer const &, ostream & os, } -int InsetSpace::textString(Buffer const & buf, lyx::odocstream & os, +int InsetSpace::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetspace.h b/src/insets/insetspace.h index 4d84e7c0c0..4dd793e643 100644 --- a/src/insets/insetspace.h +++ b/src/insets/insetspace.h @@ -61,7 +61,7 @@ public: /// Will not be used when lyxf3 void read(Buffer const &, LyXLex & lex); /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index 386fca533a..853fdfaec1 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -24,6 +24,7 @@ #include "frontends/Painter.h" using lyx::docstring; +using lyx::odocstream; using std::string; using std::auto_ptr; @@ -164,7 +165,7 @@ void InsetSpecialChar::read(Buffer const &, LyXLex & lex) } -int InsetSpecialChar::latex(Buffer const &, ostream & os, +int InsetSpecialChar::latex(Buffer const &, odocstream & os, OutputParams const &) const { switch (kind_) { @@ -188,7 +189,7 @@ int InsetSpecialChar::latex(Buffer const &, ostream & os, } -int InsetSpecialChar::plaintext(Buffer const &, lyx::odocstream & os, +int InsetSpecialChar::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { switch (kind_) { @@ -230,7 +231,7 @@ int InsetSpecialChar::docbook(Buffer const &, ostream & os, } -int InsetSpecialChar::textString(Buffer const & buf, lyx::odocstream & os, +int InsetSpecialChar::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 3606f9633f..2b4ef0e7db 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -53,7 +53,7 @@ public: /// Will not be used when lyxf3 void read(Buffer const &, LyXLex & lex); /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index df79c6718e..a3c5c67a5a 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -47,6 +47,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::Point; using lyx::cap::dirtyTabularStack; @@ -1054,14 +1055,14 @@ bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd, } -int InsetTabular::latex(Buffer const & buf, ostream & os, +int InsetTabular::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { return tabular.latex(buf, os, runparams); } -int InsetTabular::plaintext(Buffer const & buf, lyx::odocstream & os, +int InsetTabular::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { int const dp = runparams.linelen ? runparams.depth : 0; diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 2c4505e147..4d9971ec6b 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -84,7 +84,7 @@ public: /// bool display() const { return tabular.isLongTabular(); } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 7e6449879f..5079038526 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -53,6 +53,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::pos_type; using lyx::graphics::PreviewLoader; @@ -260,7 +261,7 @@ bool InsetText::getStatus(LCursor & cur, FuncRequest const & cmd, } -int InsetText::latex(Buffer const & buf, ostream & os, +int InsetText::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { TexRow texrow; @@ -269,7 +270,7 @@ int InsetText::latex(Buffer const & buf, ostream & os, } -int InsetText::plaintext(Buffer const & buf, lyx::odocstream & os, +int InsetText::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { ParagraphList::const_iterator beg = paragraphs().begin(); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index d7d93eedf8..578109343f 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -61,7 +61,7 @@ public: /// InsetText const * asTextInset() const { return this; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insettheorem.C b/src/insets/insettheorem.C index 4b168ca38f..ceb90555ba 100644 --- a/src/insets/insettheorem.C +++ b/src/insets/insettheorem.C @@ -87,7 +87,7 @@ string const InsetTheorem::editMessage() const } -int InsetTheorem::latex(Buffer const * buf, ostream & os, +int InsetTheorem::latex(Buffer const * buf, odocstream & os, OutputParams const & runparams) const { os << "\\begin{theorem}%\n"; diff --git a/src/insets/insettheorem.h b/src/insets/insettheorem.h index ed9b88f81c..b516d87c31 100644 --- a/src/insets/insettheorem.h +++ b/src/insets/insettheorem.h @@ -31,7 +31,7 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// virtual lyx::docstring const editMessage() const; diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index c08da017e2..0a454b4e6a 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -21,6 +21,7 @@ #include "support/std_ostream.h" using lyx::docstring; +using lyx::odocstream; using std::string; using std::ostream; @@ -54,7 +55,7 @@ InsetBase::Code InsetTOC::lyxCode() const } -int InsetTOC::plaintext(Buffer const & buffer, lyx::odocstream & os, +int InsetTOC::plaintext(Buffer const & buffer, odocstream & os, OutputParams const &) const { os << getScreenLabel(buffer) << "\n\n"; diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index ffceee1cf9..b6d87341e6 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -23,6 +23,7 @@ #include "support/std_ostream.h" using lyx::docstring; +using lyx::odocstream; using lyx::support::subst; using std::string; @@ -56,19 +57,20 @@ docstring const InsetUrl::getScreenLabel(Buffer const &) const } -int InsetUrl::latex(Buffer const &, ostream & os, +int InsetUrl::latex(Buffer const &, odocstream & os, OutputParams const & runparams) const { - if (!getOptions().empty()) - os << getOptions() + ' '; + docstring const & name = getParam("name"); + if (!name.empty()) + os << name + ' '; if (runparams.moving_arg) os << "\\protect"; - os << "\\url{" << getContents() << '}'; + os << "\\url{" << getParam("target") << '}'; return 0; } -int InsetUrl::plaintext(Buffer const &, lyx::odocstream & os, +int InsetUrl::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { // FIXME UNICODE @@ -91,7 +93,7 @@ int InsetUrl::docbook(Buffer const &, ostream & os, } -int InsetUrl::textString(Buffer const & buf, lyx::odocstream & os, +int InsetUrl::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index a509ea60e1..014b7c9c20 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -35,7 +35,7 @@ public: /// bool display() const { return false; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetvspace.C b/src/insets/insetvspace.C index 65cb980c0d..7aca1a8221 100644 --- a/src/insets/insetvspace.C +++ b/src/insets/insetvspace.C @@ -29,6 +29,7 @@ #include using lyx::docstring; +using lyx::odocstream; using std::istringstream; using std::ostream; @@ -202,15 +203,15 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const } -int InsetVSpace::latex(Buffer const & buf, ostream & os, +int InsetVSpace::latex(Buffer const & buf, odocstream & os, OutputParams const &) const { - os << space_.asLatexCommand(buf.params()) << '\n'; + os << lyx::from_ascii(space_.asLatexCommand(buf.params())) << '\n'; return 1; } -int InsetVSpace::plaintext(Buffer const &, lyx::odocstream & os, +int InsetVSpace::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << "\n\n"; diff --git a/src/insets/insetvspace.h b/src/insets/insetvspace.h index e96024dd43..ecfe67cc4d 100644 --- a/src/insets/insetvspace.h +++ b/src/insets/insetvspace.h @@ -30,7 +30,7 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int plaintext(Buffer const &, lyx::odocstream &, diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index f3903c16d3..06d4bca32c 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -32,9 +32,8 @@ #include "support/convert.h" -#include - using lyx::docstring; +using lyx::odocstream; using std::string; using std::endl; @@ -180,15 +179,15 @@ docstring const InsetWrap::editMessage() const } -int InsetWrap::latex(Buffer const & buf, ostream & os, +int InsetWrap::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - os << "\\begin{floating" << params_.type << '}'; + os << "\\begin{floating" << lyx::from_ascii(params_.type) << '}'; if (!params_.placement.empty()) - os << '[' << params_.placement << ']'; - os << '{' << params_.width.asLatexString() << "}%\n"; + os << '[' << lyx::from_ascii(params_.placement) << ']'; + os << '{' << lyx::from_ascii(params_.width.asLatexString()) << "}%\n"; int const i = InsetText::latex(buf, os, runparams); - os << "\\end{floating" << params_.type << "}%\n"; + os << "\\end{floating" << lyx::from_ascii(params_.type) << "}%\n"; return i + 2; } diff --git a/src/insets/insetwrap.h b/src/insets/insetwrap.h index 0754176465..516c6ba27e 100644 --- a/src/insets/insetwrap.h +++ b/src/insets/insetwrap.h @@ -50,7 +50,7 @@ public: /// InsetBase::Code lyxCode() const { return InsetBase::WRAP_CODE; } /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/render_preview.C b/src/insets/render_preview.C index d88289181d..f7ebd00a0a 100644 --- a/src/insets/render_preview.C +++ b/src/insets/render_preview.C @@ -184,7 +184,7 @@ void RenderPreview::startLoading(Buffer const & buffer) const } -void RenderPreview::addPreview(string const & latex_snippet, +void RenderPreview::addPreview(docstring const & latex_snippet, Buffer const & buffer) { if (status() == LyXRC::PREVIEW_OFF) @@ -195,13 +195,15 @@ void RenderPreview::addPreview(string const & latex_snippet, } -void RenderPreview::addPreview(string const & latex_snippet, +void RenderPreview::addPreview(docstring const & latex_snippet, graphics::PreviewLoader & ploader) { if (status() == LyXRC::PREVIEW_OFF) return; - snippet_ = support::trim(latex_snippet); + // FIXME UNICODE + // We have to make sure that we call latex with the right encoding + snippet_ = support::trim(lyx::to_utf8(latex_snippet)); if (snippet_.empty()) return; diff --git a/src/insets/render_preview.h b/src/insets/render_preview.h index ecec3237a0..672dccc889 100644 --- a/src/insets/render_preview.h +++ b/src/insets/render_preview.h @@ -19,6 +19,7 @@ #include "render_base.h" #include "support/FileMonitor.h" +#include "support/docstring.h" #include #include @@ -56,12 +57,12 @@ public: /** Find the PreviewLoader and add a LaTeX snippet to it. * Do not start the loading process. */ - void addPreview(std::string const & latex_snippet, Buffer const &); + void addPreview(lyx::docstring const & latex_snippet, Buffer const &); /** Add a LaTeX snippet to the PreviewLoader. * Do not start the loading process. */ - void addPreview(std::string const & latex_snippet, + void addPreview(lyx::docstring const & latex_snippet, lyx::graphics::PreviewLoader & ploader); /// Begin the loading process. diff --git a/src/lyxfont.C b/src/lyxfont.C index cebd9954fb..2ab85fd7b5 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -26,8 +26,7 @@ #include "support/lstrings.h" -#include - +using lyx::odocstream; using lyx::support::ascii_lowercase; using lyx::support::bformat; using lyx::support::rtrim; @@ -743,7 +742,7 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, /// Writes the head of the LaTeX needed to impose this font // Returns number of chars written. -int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, +int LyXFont::latexWriteStartChanges(odocstream & os, LyXFont const & base, LyXFont const & prev) const { int count = 0; @@ -763,7 +762,7 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, string const tmp = subst(lyxrc.language_command_local, "$$lang", language()->babel()); - os << tmp; + os << lyx::from_ascii(tmp); count += tmp.length(); } } @@ -800,7 +799,7 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, } if (f.color() != LColor::inherit && f.color() != LColor::ignore) { os << "\\textcolor{" - << lcolor.getLaTeXName(f.color()) + << lyx::from_ascii(lcolor.getLaTeXName(f.color())) << "}{"; count += lcolor.getLaTeXName(f.color()).length() + 13; env = true; //We have opened a new environment @@ -839,7 +838,7 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, /// Writes ending block of LaTeX needed to close use of this font // Returns number of chars written // This one corresponds to latexWriteStartChanges(). (Asger) -int LyXFont::latexWriteEndChanges(ostream & os, LyXFont const & base, +int LyXFont::latexWriteEndChanges(odocstream & os, LyXFont const & base, LyXFont const & next) const { int count = 0; diff --git a/src/lyxfont.h b/src/lyxfont.h index 8d0d3a2610..e5b38c0cde 100644 --- a/src/lyxfont.h +++ b/src/lyxfont.h @@ -16,9 +16,8 @@ #define LYXFONT_H #include "LColor.h" +#include "support/docstream.h" -#include -#include class LyXLex; class BufferParams; @@ -295,14 +294,14 @@ public: to this font. Returns number of chars written. Base is the font state active now. */ - int latexWriteStartChanges(std::ostream &, LyXFont const & base, + int latexWriteStartChanges(lyx::odocstream &, LyXFont const & base, LyXFont const & prev) const; /** Writes the tail of the LaTeX needed to change to this font. Returns number of chars written. Base is the font state we want to achieve. */ - int latexWriteEndChanges(std::ostream &, LyXFont const & base, + int latexWriteEndChanges(lyx::odocstream &, LyXFont const & base, LyXFont const & next) const; /// Build GUI description of font state diff --git a/src/mathed/InsetFormulaMacro.C b/src/mathed/InsetFormulaMacro.C index 1c0df28003..f0f76de90d 100644 --- a/src/mathed/InsetFormulaMacro.C +++ b/src/mathed/InsetFormulaMacro.C @@ -31,6 +31,7 @@ #include +using lyx::odocstream; using lyx::support::bformat; using std::string; @@ -75,7 +76,7 @@ void InsetFormulaMacro::write(Buffer const &, ostream & os) const } -int InsetFormulaMacro::latex(Buffer const &, ostream & os, +int InsetFormulaMacro::latex(Buffer const &, odocstream & os, OutputParams const & runparams) const { //lyxerr << "InsetFormulaMacro::latex" << endl; @@ -85,7 +86,7 @@ int InsetFormulaMacro::latex(Buffer const &, ostream & os, } -int InsetFormulaMacro::plaintext(Buffer const &, lyx::odocstream & os, +int InsetFormulaMacro::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { WriteStream wi(os, false, true); diff --git a/src/mathed/InsetFormulaMacro.h b/src/mathed/InsetFormulaMacro.h index 5c0a325957..b32ac58234 100644 --- a/src/mathed/InsetFormulaMacro.h +++ b/src/mathed/InsetFormulaMacro.h @@ -44,7 +44,7 @@ public: int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// - int latex(Buffer const &, std::ostream & os, + int latex(Buffer const &, lyx::odocstream & os, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/mathed/InsetMath.C b/src/mathed/InsetMath.C index 57fed3d604..967904dc87 100644 --- a/src/mathed/InsetMath.C +++ b/src/mathed/InsetMath.C @@ -20,8 +20,9 @@ #include +using lyx::odocstream; + using std::string; -using std::ostream; using std::endl; @@ -44,8 +45,10 @@ MathArray const & InsetMath::cell(idx_type) const void InsetMath::dump() const { lyxerr << "---------------------------------------------" << endl; - WriteStream wi(lyxerr, false, true); + lyx::odocstringstream os; + WriteStream wi(os, false, true); write(wi); + lyxerr << lyx::to_utf8(os.str()); lyxerr << "\n---------------------------------------------" << endl; } @@ -131,7 +134,16 @@ string InsetMath::name() const } -ostream & operator<<(ostream & os, MathAtom const & at) +std::ostream & operator<<(std::ostream & os, MathAtom const & at) +{ + lyx::odocstringstream oss; + WriteStream wi(oss, false, false); + at->write(wi); + return os << lyx::to_utf8(oss.str()); +} + + +odocstream & operator<<(odocstream & os, MathAtom const & at) { WriteStream wi(os, false, false); at->write(wi); diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index 91a1d1d86b..40d54df7b0 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -17,8 +17,6 @@ #include "insets/insetbase.h" -#include - enum HullType { hullNone, hullSimple, @@ -198,7 +196,10 @@ public: virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; } }; +/// std::ostream & operator<<(std::ostream &, MathAtom const &); +/// +lyx::odocstream & operator<<(lyx::odocstream &, MathAtom const &); // initialize math void initMath(); diff --git a/src/mathed/InsetMathCommand.C b/src/mathed/InsetMathCommand.C index a001ff4132..070517924d 100644 --- a/src/mathed/InsetMathCommand.C +++ b/src/mathed/InsetMathCommand.C @@ -22,7 +22,6 @@ using lyx::docstring; using std::string; using std::auto_ptr; -using std::ostringstream; CommandInset::CommandInset(string const & name) @@ -80,10 +79,10 @@ docstring const CommandInset::screenLabel() const string const CommandInset::createDialogStr(string const & name) const { - ostringstream os; - os << name << " LatexCommand "; + lyx::odocstringstream os; + os << lyx::from_ascii(name) << " LatexCommand "; WriteStream ws(os); write(ws); ws << "\n\\end_inset\n\n"; - return os.str(); + return lyx::to_utf8(os.str()); } diff --git a/src/mathed/InsetMathGrid.C b/src/mathed/InsetMathGrid.C index 63d96f6a3e..8c160fc639 100644 --- a/src/mathed/InsetMathGrid.C +++ b/src/mathed/InsetMathGrid.C @@ -44,7 +44,6 @@ using std::string; using std::auto_ptr; using std::istream; using std::istringstream; -using std::ostringstream; using std::vector; @@ -60,12 +59,12 @@ public: /// virtual string const inset2string(Buffer const &) const { - ostringstream data; + lyx::odocstringstream data; //data << name() << " active_cell " << inset.getActCell() << '\n'; - data << name() << " active_cell " << 0 << '\n'; + data << lyx::from_utf8(name()) << " active_cell " << 0 << '\n'; WriteStream ws(data); inset_.write(ws); - return data.str(); + return lyx::to_utf8(data.str()); } protected: diff --git a/src/mathed/InsetMathHull.C b/src/mathed/InsetMathHull.C index 4a640da966..d8666be8bb 100644 --- a/src/mathed/InsetMathHull.C +++ b/src/mathed/InsetMathHull.C @@ -61,6 +61,8 @@ #include using lyx::docstring; +using lyx::odocstream; +using lyx::odocstringstream; using lyx::cap::grabAndEraseSelection; using lyx::support::bformat; using lyx::support::subst; @@ -360,7 +362,7 @@ void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const if (display()) { InsetMathGrid::metricsT(mi, dim); } else { - ostringstream os; + odocstringstream os; WriteStream wi(os, false, true); write(wi); dim.wid = os.str().size(); @@ -375,7 +377,7 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const if (display()) { InsetMathGrid::drawT(pain, x, y); } else { - ostringstream os; + odocstringstream os; WriteStream wi(os, false, true); write(wi); pain.draw(x, y, os.str().c_str()); @@ -385,9 +387,9 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const namespace { -string const latex_string(InsetMathHull const & inset) +docstring const latex_string(InsetMathHull const & inset) { - ostringstream ls; + odocstringstream ls; WriteStream wi(ls, false, false); inset.write(wi); return ls.str(); @@ -399,7 +401,7 @@ string const latex_string(InsetMathHull const & inset) void InsetMathHull::addPreview(lyx::graphics::PreviewLoader & ploader) const { if (RenderPreview::status() == LyXRC::PREVIEW_ON) { - string const snippet = latex_string(*this); + docstring const snippet = latex_string(*this); preview_->addPreview(snippet, ploader); } } @@ -409,7 +411,7 @@ bool InsetMathHull::notifyCursorLeaves(LCursor & cur) { if (RenderPreview::status() == LyXRC::PREVIEW_ON) { Buffer const & buffer = cur.buffer(); - string const snippet = latex_string(*this); + docstring const snippet = latex_string(*this); preview_->addPreview(snippet, buffer); preview_->startLoading(buffer); } @@ -951,12 +953,13 @@ void InsetMathHull::check() const void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func) { - string lang; - string extra; - istringstream iss(lyx::to_utf8(func.argument())); - iss >> lang >> extra; + docstring dlang; + docstring extra; + lyx::idocstringstream iss(func.argument()); + iss >> dlang >> extra; if (extra.empty()) - extra = "noextra"; + extra = lyx::from_ascii("noextra"); + string const lang = lyx::to_ascii(dlang); #ifdef WITH_WARNINGS #warning temporarily disabled @@ -1412,9 +1415,11 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str, void InsetMathHull::write(Buffer const &, std::ostream & os) const { - WriteStream wi(os, false, false); - os << "Formula "; + odocstringstream oss; + WriteStream wi(oss, false, false); + oss << "Formula "; write(wi); + os << lyx::to_utf8(oss.str()); } @@ -1426,7 +1431,7 @@ void InsetMathHull::read(Buffer const &, LyXLex & lex) } -int InsetMathHull::plaintext(Buffer const &, lyx::odocstream & os, +int InsetMathHull::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { if (0 && display()) { @@ -1440,11 +1445,8 @@ int InsetMathHull::plaintext(Buffer const &, lyx::odocstream & os, //metrics(); return tpain.textheight(); } else { - std::ostringstream oss; - WriteStream wi(oss, false, true); + WriteStream wi(os, false, true); wi << cell(0); - // FIXME UNICODE - os << lyx::from_utf8(oss.str()); return wi.line(); } } @@ -1453,7 +1455,8 @@ int InsetMathHull::plaintext(Buffer const &, lyx::odocstream & os, int InsetMathHull::docbook(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - MathMLStream ms(os); + odocstringstream oss; + MathMLStream ms(oss); int res = 0; string name; if (getType() == hullSimple) @@ -1466,7 +1469,7 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os, bname += " id=\"" + sgml::cleanID(buf, runparams, label(0)) + "\""; ms << MTag(bname.c_str()); - ostringstream ls; + odocstringstream ls; if (runparams.flavor == OutputParams::XML) { ms << MTag("alt role=\"tex\" "); // Workaround for db2latex: db2latex always includes equations with @@ -1474,7 +1477,7 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os, // so we strip LyX' math environment WriteStream wi(ls, false, false); InsetMathGrid::write(wi); - ms << subst(subst(ls.str(), "&", "&"), "<", "<"); + ms << subst(subst(lyx::to_utf8(ls.str()), "&", "&"), "<", "<"); ms << ETag("alt"); ms << MTag("math"); InsetMathGrid::mathmlize(ms); @@ -1482,7 +1485,7 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os, } else { ms << MTag("alt role=\"tex\""); res = latex(buf, ls, runparams); - ms << subst(subst(ls.str(), "&", "&"), "<", "<"); + ms << subst(subst(lyx::to_utf8(ls.str()), "&", "&"), "<", "<"); ms << ETag("alt"); } @@ -1498,11 +1501,12 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os, ms << "\">"; ms << ETag(name.c_str()); + os << lyx::to_utf8(oss.str()); return ms.line() + res; } -int InsetMathHull::textString(Buffer const & buf, lyx::odocstream & os, +int InsetMathHull::textString(Buffer const & buf, odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/mathed/InsetMathMBox.C b/src/mathed/InsetMathMBox.C index 37ed78429d..7f32029a26 100644 --- a/src/mathed/InsetMathMBox.C +++ b/src/mathed/InsetMathMBox.C @@ -79,7 +79,7 @@ void InsetMathMBox::write(WriteStream & ws) const } -int InsetMathMBox::latex(Buffer const & buf, std::ostream & os, +int InsetMathMBox::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { os << "\\mbox{\n"; diff --git a/src/mathed/InsetMathMBox.h b/src/mathed/InsetMathMBox.h index 305d88fd18..339ee668d9 100644 --- a/src/mathed/InsetMathMBox.h +++ b/src/mathed/InsetMathMBox.h @@ -36,7 +36,7 @@ public: /// void write(WriteStream & os) const; /// - int latex(Buffer const &, std::ostream & os, + int latex(Buffer const &, lyx::odocstream & os, OutputParams const & runparams) const; /// LyXText * getText(int) const; diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index ccda9eb549..6951c248a4 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -62,6 +62,7 @@ using lyx::CoordCache; using lyx::docstring; +using lyx::odocstream; using lyx::Point; using lyx::cap::copySelection; @@ -208,13 +209,15 @@ bool InsetMathNest::idxLast(LCursor & cur) const void InsetMathNest::dump() const { - WriteStream os(lyxerr); + lyx::odocstringstream oss; + WriteStream os(oss); os << "---------------------------------------------\n"; write(os); os << "\n"; for (idx_type i = 0, n = nargs(); i != n; ++i) os << cell(i) << "\n"; os << "---------------------------------------------\n"; + lyxerr << lyx::to_utf8(oss.str()); } @@ -348,7 +351,7 @@ void InsetMathNest::normalize(NormalStream & os) const } -int InsetMathNest::latex(Buffer const &, std::ostream & os, +int InsetMathNest::latex(Buffer const &, odocstream & os, OutputParams const & runparams) const { WriteStream wi(os, runparams.moving_arg, true); diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index f00db97813..4810bf16ce 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -93,7 +93,7 @@ public: /// writes [, name(), and args in [] void normalize(NormalStream & os) const; /// - int latex(Buffer const &, std::ostream & os, + int latex(Buffer const &, lyx::odocstream & os, OutputParams const & runparams) const; protected: diff --git a/src/mathed/MathData.C b/src/mathed/MathData.C index 6b94f12ec0..1b995587b1 100644 --- a/src/mathed/MathData.C +++ b/src/mathed/MathData.C @@ -29,6 +29,8 @@ #include +using lyx::odocstream; + using std::abs; using std::endl; using std::min; @@ -106,17 +108,21 @@ void MathArray::erase(size_type pos1, size_type pos2) void MathArray::dump2() const { - NormalStream ns(lyxerr); + lyx::odocstringstream os; + NormalStream ns(os); for (const_iterator it = begin(); it != end(); ++it) ns << *it << ' '; + lyxerr << lyx::to_utf8(os.str()); } void MathArray::dump() const { - NormalStream ns(lyxerr); + lyx::odocstringstream os; + NormalStream ns(os); for (const_iterator it = begin(); it != end(); ++it) ns << '<' << *it << '>'; + lyxerr << lyx::to_utf8(os.str()); } @@ -444,3 +450,20 @@ int MathArray::yo(BufferView & bv) const { return bv.coordCache().getArrays().y(this); } + + +std::ostream & operator<<(std::ostream & os, MathArray const & ar) +{ + lyx::odocstringstream oss; + NormalStream ns(oss); + ns << ar; + return os << lyx::to_utf8(oss.str()); +} + + +odocstream & operator<<(odocstream & os, MathArray const & ar) +{ + NormalStream ns(os); + ns << ar; + return os; +} diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index eb0441106a..9b679ad211 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -14,12 +14,13 @@ #ifndef MATH_DATA_H #define MATH_DATA_H -#include #include #include "MathAtom.h" #include "dimension.h" +#include "support/docstream.h" + class BufferView; class LaTeXFeatures; class ReplaceData; @@ -157,6 +158,8 @@ private: /// std::ostream & operator<<(std::ostream & os, MathArray const & ar); +/// +lyx::odocstream & operator<<(lyx::odocstream & os, MathArray const & ar); #endif diff --git a/src/mathed/MathExtern.C b/src/mathed/MathExtern.C index 41fba8c55b..0a35bd9799 100644 --- a/src/mathed/MathExtern.C +++ b/src/mathed/MathExtern.C @@ -40,6 +40,9 @@ #include #include +using lyx::docstring; +using lyx::odocstream; +using lyx::odocstringstream; using lyx::support::cmd_ret; using lyx::support::getVectorFromString; using lyx::support::libFileSearch; @@ -54,19 +57,10 @@ using std::find_if; using std::auto_ptr; using std::istringstream; using std::ostream; -using std::ostringstream; using std::swap; using std::vector; -ostream & operator<<(ostream & os, MathArray const & ar) -{ - NormalStream ns(os); - ns << ar; - return os; -} - - // define a function for tests typedef bool TestItemFunc(MathAtom const &); @@ -1053,12 +1047,13 @@ namespace { return string::npos; } - MathArray pipeThroughMaxima(string const &, MathArray const & ar) + MathArray pipeThroughMaxima(docstring const &, MathArray const & ar) { - ostringstream os; + lyx::odocstringstream os; MaximaStream ms(os); ms << ar; - string expr = os.str(); + // FIXME UNICODE Is utf8 encoding correct? + string expr = lyx::to_utf8(os.str()); string const header = "simpsum:true;"; string out; @@ -1147,7 +1142,7 @@ namespace { } - MathArray pipeThroughMaple(string const & extra, MathArray const & ar) + MathArray pipeThroughMaple(docstring const & extra, MathArray const & ar) { string header = "readlib(latex):\n"; @@ -1178,12 +1173,13 @@ namespace { // " := subs((\\'_\\' = \\'`\\_`\\',eval(`latex/latex/symbol`)): "; string trailer = "quit;"; - ostringstream os; + lyx::odocstringstream os; MapleStream ms(os); ms << ar; - string expr = os.str(); + // FIXME UNICODE Is utf8 encoding correct? + string expr = lyx::to_utf8(os.str()); lyxerr << "ar: '" << ar << "'\n" - << "ms: '" << os.str() << "'" << endl; + << "ms: '" << expr << "'" << endl; for (int i = 0; i < 100; ++i) { // at most 100 attempts // try to fix missing '*' the hard way by using mint @@ -1212,7 +1208,8 @@ namespace { expr.insert(pos, 1, '*'); } - string full = "latex(" + extra + '(' + expr + "));"; + // FIXME UNICODE Is utf8 encoding correct? + string full = "latex(" + lyx::to_utf8(extra) + '(' + expr + "));"; string out = captureOutput("maple -q", header + full + trailer); // change \_ into _ @@ -1224,12 +1221,13 @@ namespace { } - MathArray pipeThroughOctave(string const &, MathArray const & ar) + MathArray pipeThroughOctave(docstring const &, MathArray const & ar) { - ostringstream os; + lyx::odocstringstream os; OctaveStream vs(os); vs << ar; - string expr = os.str(); + // FIXME UNICODE Is utf8 encoding correct? + string expr = lyx::to_utf8(os.str()); string out; lyxerr << "pipe: ar: '" << ar << "'\n" @@ -1341,12 +1339,13 @@ namespace { } - MathArray pipeThroughMathematica(string const &, MathArray const & ar) + MathArray pipeThroughMathematica(docstring const &, MathArray const & ar) { - ostringstream os; + lyx::odocstringstream os; MathematicaStream ms(os); ms << ar; - string const expr = os.str(); + // FIXME UNICODE Is utf8 encoding correct? + string const expr = lyx::to_utf8(os.str()); string out; lyxerr << "expr: '" << expr << "'" << endl; @@ -1378,7 +1377,7 @@ namespace { } -MathArray pipeThroughExtern(string const & lang, string const & extra, +MathArray pipeThroughExtern(string const & lang, docstring const & extra, MathArray const & ar) { if (lang == "octave") @@ -1394,12 +1393,13 @@ MathArray pipeThroughExtern(string const & lang, string const & extra, return pipeThroughMathematica(extra, ar); // create normalized expression - ostringstream os; + lyx::odocstringstream os; NormalStream ns(os); os << '[' << extra << ' '; ns << ar; os << ']'; - string data = os.str(); + // FIXME UNICODE Is utf8 encoding correct? + string data = lyx::to_utf8(os.str()); // search external script string file = libFileSearch("mathed", "extern_" + lang); diff --git a/src/mathed/MathExtern.h b/src/mathed/MathExtern.h index 33c710a170..1c623a8f6f 100644 --- a/src/mathed/MathExtern.h +++ b/src/mathed/MathExtern.h @@ -12,7 +12,7 @@ #ifndef MATH_EXTERN_H #define MATH_EXTERN_H -#include +#include "support/docstring.h" class NormalStream; @@ -35,7 +35,7 @@ void octave(MathArray const &, OctaveStream &); bool extractNumber(MathArray const & ar, int & i); bool extractNumber(MathArray const & ar, double & i); -MathArray pipeThroughExtern(std::string const & lang, std::string const & extra, +MathArray pipeThroughExtern(std::string const & lang, lyx::docstring const & extra, MathArray const & ar); #endif diff --git a/src/mathed/MathMLStream.C b/src/mathed/MathMLStream.C index c519b4c39c..d320e81d9f 100644 --- a/src/mathed/MathMLStream.C +++ b/src/mathed/MathMLStream.C @@ -18,7 +18,7 @@ using std::strlen; -using std::ostream; +using lyx::odocstream; namespace { @@ -31,13 +31,13 @@ namespace { } -WriteStream::WriteStream(ostream & os, bool fragile, bool latex) +WriteStream::WriteStream(odocstream & os, bool fragile, bool latex) : os_(os), fragile_(fragile), firstitem_(false), latex_(latex), pendingspace_(false), line_(0) {} -WriteStream::WriteStream(ostream & os) +WriteStream::WriteStream(odocstream & os) : os_(os), fragile_(false), firstitem_(false), latex_(false), pendingspace_(false), line_(0) {} @@ -120,7 +120,7 @@ WriteStream & operator<<(WriteStream & ws, unsigned int i) ////////////////////////////////////////////////////////////////////// -MathMLStream::MathMLStream(ostream & os) +MathMLStream::MathMLStream(odocstream & os) : os_(os), tab_(0), line_(0), lastchar_(0) {} diff --git a/src/mathed/MathMLStream.h b/src/mathed/MathMLStream.h index ab4bef8f5b..0b967d9706 100644 --- a/src/mathed/MathMLStream.h +++ b/src/mathed/MathMLStream.h @@ -19,7 +19,7 @@ #include "metricsinfo.h" -#include +#include "support/docstream.h" class MathArray; class InsetMath; @@ -32,9 +32,9 @@ class MathAtom; class WriteStream { public: /// - WriteStream(std::ostream & os, bool fragile, bool latex); + WriteStream(lyx::odocstream & os, bool fragile, bool latex); /// - explicit WriteStream(std::ostream & os); + explicit WriteStream(lyx::odocstream & os); /// ~WriteStream(); /// @@ -44,7 +44,7 @@ public: /// bool latex() const { return latex_; } /// - std::ostream & os() { return os_; } + lyx::odocstream & os() { return os_; } /// bool & firstitem() { return firstitem_; } /// @@ -55,7 +55,7 @@ public: bool pendingSpace() const { return pendingspace_; } private: /// - std::ostream & os_; + lyx::odocstream & os_; /// do we have to write \\protect sometimes bool fragile_; /// are we at the beginning of an MathArray? @@ -106,11 +106,11 @@ public: class MathMLStream { public: /// - explicit MathMLStream(std::ostream & os); + explicit MathMLStream(lyx::odocstream & os); /// void cr(); /// - std::ostream & os() { return os_; } + lyx::odocstream & os() { return os_; } /// int line() const { return line_; } /// @@ -119,7 +119,7 @@ public: friend MathMLStream & operator<<(MathMLStream &, char const *); private: /// - std::ostream & os_; + lyx::odocstream & os_; /// int tab_; /// @@ -150,12 +150,12 @@ MathMLStream & operator<<(MathMLStream &, ETag const &); class NormalStream { public: /// - explicit NormalStream(std::ostream & os) : os_(os) {} + explicit NormalStream(lyx::odocstream & os) : os_(os) {} /// - std::ostream & os() { return os_; } + lyx::odocstream & os() { return os_; } private: /// - std::ostream & os_; + lyx::odocstream & os_; }; /// @@ -178,12 +178,12 @@ NormalStream & operator<<(NormalStream &, int); class MapleStream { public: /// - explicit MapleStream(std::ostream & os) : os_(os) {} + explicit MapleStream(lyx::odocstream & os) : os_(os) {} /// - std::ostream & os() { return os_; } + lyx::odocstream & os() { return os_; } private: /// - std::ostream & os_; + lyx::odocstream & os_; }; @@ -207,12 +207,12 @@ MapleStream & operator<<(MapleStream &, int); class MaximaStream { public: /// - explicit MaximaStream(std::ostream & os) : os_(os) {} + explicit MaximaStream(lyx::odocstream & os) : os_(os) {} /// - std::ostream & os() { return os_; } + lyx::odocstream & os() { return os_; } private: /// - std::ostream & os_; + lyx::odocstream & os_; }; @@ -236,12 +236,12 @@ MaximaStream & operator<<(MaximaStream &, int); class MathematicaStream { public: /// - explicit MathematicaStream(std::ostream & os) : os_(os) {} + explicit MathematicaStream(lyx::odocstream & os) : os_(os) {} /// - std::ostream & os() { return os_; } + lyx::odocstream & os() { return os_; } private: /// - std::ostream & os_; + lyx::odocstream & os_; }; @@ -265,12 +265,12 @@ MathematicaStream & operator<<(MathematicaStream &, int); class OctaveStream { public: /// - explicit OctaveStream(std::ostream & os) : os_(os) {} + explicit OctaveStream(lyx::odocstream & os) : os_(os) {} /// - std::ostream & os() { return os_; } + lyx::odocstream & os() { return os_; } private: /// - std::ostream & os_; + lyx::odocstream & os_; }; /// diff --git a/src/mathed/MathMacroTemplate.C b/src/mathed/MathMacroTemplate.C index b546e76720..b133375411 100644 --- a/src/mathed/MathMacroTemplate.C +++ b/src/mathed/MathMacroTemplate.C @@ -183,9 +183,11 @@ void MathMacroTemplate::read(Buffer const &, LyXLex & lex) void MathMacroTemplate::write(Buffer const &, std::ostream & os) const { - WriteStream wi(os, false, false); - os << "FormulaMacro\n"; + lyx::odocstringstream oss; + WriteStream wi(oss, false, false); + oss << "FormulaMacro\n"; write(wi); + os << lyx::to_utf8(oss.str()); } diff --git a/src/mathed/MathStream.C b/src/mathed/MathStream.C index 21af399570..ef7c4dc584 100644 --- a/src/mathed/MathStream.C +++ b/src/mathed/MathStream.C @@ -12,7 +12,6 @@ #include "MathStream.h" #include "MathMLStream.h" -#include "support/std_ostream.h" using std::string; @@ -26,41 +25,47 @@ WriteStream & operator<<(WriteStream & ws, string const & s) NormalStream & operator<<(NormalStream & ns, string const & s) { - ns.os() << s; + // FIXME UNICODE + ns.os() << lyx::from_utf8(s); return ns; } MapleStream & operator<<(MapleStream & ms, string const & s) { - ms.os() << s; + // FIXME UNICODE + ms.os() << lyx::from_utf8(s); return ms; } MaximaStream & operator<<(MaximaStream & ms, string const & s) { - ms.os() << s; + // FIXME UNICODE + ms.os() << lyx::from_utf8(s); return ms; } MathematicaStream & operator<<(MathematicaStream & ms, string const & s) { - ms.os() << s; + // FIXME UNICODE + ms.os() << lyx::from_utf8(s); return ms; } MathMLStream & operator<<(MathMLStream & ms, string const & s) { - ms.os() << s; + // FIXME UNICODE + ms.os() << lyx::from_utf8(s); return ms; } OctaveStream & operator<<(OctaveStream & os, string const & s) { - os.os() << s; + // FIXME UNICODE + os.os() << lyx::from_utf8(s); return os; } diff --git a/src/mathed/MathSupport.C b/src/mathed/MathSupport.C index 983c3c7637..23ad7351b8 100644 --- a/src/mathed/MathSupport.C +++ b/src/mathed/MathSupport.C @@ -671,10 +671,11 @@ void augmentFont(LyXFont & font, string const & name) string asString(MathArray const & ar) { - std::ostringstream os; + lyx::odocstringstream os; WriteStream ws(os); ws << ar; - return os.str(); + // FIXME UNICODE + return lyx::to_utf8(os.str()); } @@ -686,17 +687,19 @@ void asArray(docstring const & str, MathArray & ar) string asString(InsetMath const & inset) { - std::ostringstream os; + lyx::odocstringstream os; WriteStream ws(os); inset.write(ws); - return os.str(); + // FIXME UNICODE + return lyx::to_utf8(os.str()); } string asString(MathAtom const & at) { - std::ostringstream os; + lyx::odocstringstream os; WriteStream ws(os); at->write(ws); - return os.str(); + // FIXME UNICODE + return lyx::to_utf8(os.str()); } diff --git a/src/mathed/TextPainter.C b/src/mathed/TextPainter.C index 79180784e8..089a41f5c3 100644 --- a/src/mathed/TextPainter.C +++ b/src/mathed/TextPainter.C @@ -14,24 +14,27 @@ #include "support/std_ostream.h" +using lyx::char_type; + + TextPainter::TextPainter(int xmax, int ymax) : xmax_(xmax), ymax_(ymax), data_(xmax_ * (ymax_ + 1), ' ') {} -char & TextPainter::at(int x, int y) +char_type & TextPainter::at(int x, int y) { return data_[y * xmax_ + x]; } -char TextPainter::at(int x, int y) const +char_type TextPainter::at(int x, int y) const { return data_[y * xmax_ + x]; } -void TextPainter::draw(int x, int y, char const * str) +void TextPainter::draw(int x, int y, char_type const * str) { //cerr << "drawing string '" << str << "' at " << x << ',' << y << endl; for (int i = 0; *str && x + i < xmax_; ++i, ++str) @@ -40,21 +43,21 @@ void TextPainter::draw(int x, int y, char const * str) } -void TextPainter::horizontalLine(int x, int y, int n, char c) +void TextPainter::horizontalLine(int x, int y, int n, char_type c) { for (int i = 0; i < n && i + x < xmax_; ++i) at(x + i, y) = c; } -void TextPainter::verticalLine(int x, int y, int n, char c) +void TextPainter::verticalLine(int x, int y, int n, char_type c) { for (int i = 0; i < n && i + y < ymax_; ++i) at(x, y + i) = c; } -void TextPainter::draw(int x, int y, char c) +void TextPainter::draw(int x, int y, char_type c) { //cerr << "drawing char '" << c << "' at " << x << ',' << y << endl; at(x, y) = c; diff --git a/src/mathed/TextPainter.h b/src/mathed/TextPainter.h index 261500d550..3f25496b1a 100644 --- a/src/mathed/TextPainter.h +++ b/src/mathed/TextPainter.h @@ -32,25 +32,25 @@ class TextPainter { /// TextPainter(int xmax, int ymax); /// - void draw(int x, int y, char const * str); + void draw(int x, int y, lyx::char_type const * str); /// - void draw(int x, int y, char c); + void draw(int x, int y, lyx::char_type c); /// void show(lyx::odocstream & os, int offset = 0) const; /// int textheight() const { return ymax_; } /// - void horizontalLine(int x, int y, int len, char c = '-'); + void horizontalLine(int x, int y, int len, lyx::char_type c = '-'); /// - void verticalLine(int x, int y, int len, char c = '|'); + void verticalLine(int x, int y, int len, lyx::char_type c = '|'); private: /// - typedef std::vector data_type; + typedef std::vector data_type; /// - char at(int x, int y) const; + lyx::char_type at(int x, int y) const; /// - char & at(int x, int y); + lyx::char_type & at(int x, int y); /// xsize of the painter area int xmax_; diff --git a/src/output_latex.C b/src/output_latex.C index 24662e52f2..0cde7bef10 100644 --- a/src/output_latex.C +++ b/src/output_latex.C @@ -33,7 +33,7 @@ using lyx::support::subst; using std::endl; -using std::ostream; +using lyx::odocstream; using std::string; @@ -43,14 +43,14 @@ ParagraphList::const_iterator TeXEnvironment(Buffer const & buf, ParagraphList const & paragraphs, ParagraphList::const_iterator pit, - ostream & os, TexRow & texrow, + odocstream & os, TexRow & texrow, OutputParams const & runparams); ParagraphList::const_iterator TeXOnePar(Buffer const & buf, ParagraphList const & paragraphs, ParagraphList::const_iterator pit, - ostream & os, TexRow & texrow, + odocstream & os, TexRow & texrow, OutputParams const & runparams, string const & everypar = string()); @@ -59,7 +59,7 @@ ParagraphList::const_iterator TeXDeeper(Buffer const & buf, ParagraphList const & paragraphs, ParagraphList::const_iterator pit, - ostream & os, TexRow & texrow, + odocstream & os, TexRow & texrow, OutputParams const & runparams) { lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl; @@ -82,14 +82,14 @@ TeXDeeper(Buffer const & buf, int latexOptArgInsets(Buffer const & buf, Paragraph const & par, - ostream & os, OutputParams const & runparams, int number); + odocstream & os, OutputParams const & runparams, int number); ParagraphList::const_iterator TeXEnvironment(Buffer const & buf, ParagraphList const & paragraphs, ParagraphList::const_iterator pit, - ostream & os, TexRow & texrow, + odocstream & os, TexRow & texrow, OutputParams const & runparams) { lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl; @@ -108,16 +108,20 @@ TeXEnvironment(Buffer const & buf, if (!lyxrc.language_command_end.empty() && previous_language->babel() != doc_language->babel()) { - os << subst(lyxrc.language_command_end, "$$lang", - previous_language->babel()) + os << lyx::from_ascii(subst( + lyxrc.language_command_end, + "$$lang", + previous_language->babel())) << endl; texrow.newline(); } if (lyxrc.language_command_end.empty() || language->babel() != doc_language->babel()) { - os << subst(lyxrc.language_command_begin, "$$lang", - language->babel()) + os << lyx::from_ascii(subst( + lyxrc.language_command_begin, + "$$lang", + language->babel())) << endl; texrow.newline(); } @@ -125,14 +129,15 @@ TeXEnvironment(Buffer const & buf, bool leftindent_open = false; if (!pit->params().leftIndent().zero()) { - os << "\\begin{LyXParagraphLeftIndent}{" << - pit->params().leftIndent().asLatexString() << "}\n"; + os << "\\begin{LyXParagraphLeftIndent}{" + << lyx::from_ascii(pit->params().leftIndent().asLatexString()) + << "}\n"; texrow.newline(); leftindent_open = true; } if (style->isEnvironment()) { - os << "\\begin{" << style->latexname() << '}'; + os << "\\begin{" << lyx::from_ascii(style->latexname()) << '}'; if (style->optionalargs > 0) { int ret = latexOptArgInsets(buf, *pit, os, runparams, style->optionalargs); @@ -142,13 +147,15 @@ TeXEnvironment(Buffer const & buf, } } if (style->latextype == LATEX_LIST_ENVIRONMENT) { - os << "{" << pit->params().labelWidthString() << "}\n"; + // FIXME UNICODE + os << '{' + << lyx::from_utf8(pit->params().labelWidthString()) + << "}\n"; } else if (style->labeltype == LABEL_BIBLIO) { // ale970405 - // FIXME UNICODE - os << '{' << lyx::to_utf8(bibitemWidest(buf)) << "}\n"; + os << '{' << bibitemWidest(buf) << "}\n"; } else - os << style->latexparam() << '\n'; + os << lyx::from_ascii(style->latexparam()) << '\n'; texrow.newline(); } ParagraphList::const_iterator par = pit; @@ -190,7 +197,7 @@ TeXEnvironment(Buffer const & buf, && par->params().leftIndent() == pit->params().leftIndent()); if (style->isEnvironment()) { - os << "\\end{" << style->latexname() << "}\n"; + os << "\\end{" << lyx::from_ascii(style->latexname()) << "}\n"; texrow.newline(); } @@ -206,7 +213,7 @@ TeXEnvironment(Buffer const & buf, int latexOptArgInsets(Buffer const & buf, Paragraph const & par, - ostream & os, OutputParams const & runparams, int number) + odocstream & os, OutputParams const & runparams, int number) { int lines = 0; @@ -228,7 +235,7 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf, ParagraphList const & paragraphs, ParagraphList::const_iterator pit, - ostream & os, TexRow & texrow, + odocstream & os, TexRow & texrow, OutputParams const & runparams_in, string const & everypar) { @@ -266,8 +273,9 @@ TeXOnePar(Buffer const & buf, if (!lyxrc.language_command_end.empty() && previous_language->babel() != doc_language->babel()) { - os << subst(lyxrc.language_command_end, "$$lang", - previous_language->babel()) + os << lyx::from_ascii(subst(lyxrc.language_command_end, + "$$lang", + previous_language->babel())) << endl; texrow.newline(); } @@ -275,8 +283,10 @@ TeXOnePar(Buffer const & buf, if (lyxrc.language_command_end.empty() || language->babel() != doc_language->babel()) { - os << subst(lyxrc.language_command_begin, "$$lang", - language->babel()) + os << lyx::from_ascii(subst( + lyxrc.language_command_begin, + "$$lang", + language->babel())) << endl; texrow.newline(); } @@ -285,7 +295,7 @@ TeXOnePar(Buffer const & buf, if (bparams.inputenc == "auto" && language->encoding() != previous_language->encoding()) { os << "\\inputencoding{" - << language->encoding()->latexName() + << lyx::from_ascii(language->encoding()->latexName()) << "}\n"; texrow.newline(); } @@ -302,7 +312,8 @@ TeXOnePar(Buffer const & buf, && (pit == paragraphs.begin() || !boost::prior(pit)->hasSameLayout(*pit))) { - os << pit->params().spacing().writeEnvirBegin() << '\n'; + os << lyx::from_ascii(pit->params().spacing().writeEnvirBegin()) + << '\n'; texrow.newline(); } @@ -319,7 +330,7 @@ TeXOnePar(Buffer const & buf, switch (style->latextype) { case LATEX_COMMAND: - os << '\\' << style->latexname(); + os << '\\' << lyx::from_ascii(style->latexname()); // Separate handling of optional argument inset. if (style->optionalargs > 0) { @@ -331,7 +342,7 @@ TeXOnePar(Buffer const & buf, } } else - os << style->latexparam(); + os << lyx::from_ascii(style->latexparam()); break; case LATEX_ITEM_ENVIRONMENT: case LATEX_LIST_ENVIRONMENT: @@ -344,7 +355,8 @@ TeXOnePar(Buffer const & buf, break; } - os << everypar; + // FIXME UNICODE + os << lyx::from_utf8(everypar); bool need_par = pit->simpleTeXOnePar(buf, bparams, outerFont(std::distance(paragraphs.begin(), pit), paragraphs), os, texrow, runparams); @@ -374,7 +386,7 @@ TeXOnePar(Buffer const & buf, && !is_command) { if (!need_par) os << '{'; - os << "\\" << font.latexSize() << " \\par}"; + os << "\\" << lyx::from_ascii(font.latexSize()) << " \\par}"; } else if (need_par) { os << "\\par}"; } else if (is_command) @@ -421,7 +433,8 @@ TeXOnePar(Buffer const & buf, && (boost::next(pit) == paragraphs.end() || !boost::next(pit)->hasSameLayout(*pit))) { - os << pit->params().spacing().writeEnvirEnd() << '\n'; + os << lyx::from_ascii(pit->params().spacing().writeEnvirEnd()) + << '\n'; texrow.newline(); } } @@ -433,14 +446,16 @@ TeXOnePar(Buffer const & buf, // float. if (lyxrc.language_command_end.empty()) - os << subst(lyxrc.language_command_begin, - "$$lang", - doc_language->babel()) + os << lyx::from_ascii(subst( + lyxrc.language_command_begin, + "$$lang", + doc_language->babel())) << endl; else - os << subst(lyxrc.language_command_end, - "$$lang", - language->babel()) + os << lyx::from_ascii(subst( + lyxrc.language_command_end, + "$$lang", + language->babel())) << endl; texrow.newline(); } @@ -465,7 +480,7 @@ TeXOnePar(Buffer const & buf, // LaTeX all paragraphs void latexParagraphs(Buffer const & buf, ParagraphList const & paragraphs, - ostream & os, + odocstream & os, TexRow & texrow, OutputParams const & runparams, string const & everypar) @@ -506,18 +521,18 @@ void latexParagraphs(Buffer const & buf, was_title = true; if (tclass.titletype() == TITLE_ENVIRONMENT) { os << "\\begin{" - << tclass.titlename() + << lyx::from_ascii(tclass.titlename()) << "}\n"; texrow.newline(); } } } else if (was_title && !already_title) { if (tclass.titletype() == TITLE_ENVIRONMENT) { - os << "\\end{" << tclass.titlename() + os << "\\end{" << lyx::from_ascii(tclass.titlename()) << "}\n"; } else { - os << "\\" << tclass.titlename() + os << "\\" << lyx::from_ascii(tclass.titlename()) << "\n"; } texrow.newline(); @@ -547,11 +562,11 @@ void latexParagraphs(Buffer const & buf, // It might be that we only have a title in this document if (was_title && !already_title) { if (tclass.titletype() == TITLE_ENVIRONMENT) { - os << "\\end{" << tclass.titlename() + os << "\\end{" << lyx::from_ascii(tclass.titlename()) << "}\n"; } else { - os << "\\" << tclass.titlename() + os << "\\" << lyx::from_ascii(tclass.titlename()) << "\n"; } texrow.newline(); diff --git a/src/output_latex.h b/src/output_latex.h index f2a47b0de3..05e2572d07 100644 --- a/src/output_latex.h +++ b/src/output_latex.h @@ -14,7 +14,7 @@ #include "ParagraphList_fwd.h" -#include +#include "support/docstream.h" class Buffer; class OutputParams; @@ -24,7 +24,7 @@ class TexRow; void latexParagraphs(Buffer const & buf, ParagraphList const & paragraphs, - std::ostream & ofs, + lyx::odocstream & ofs, TexRow & texrow, OutputParams const &, std::string const & everypar = std::string()); diff --git a/src/paragraph.C b/src/paragraph.C index e95e838932..038ea5d539 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -55,6 +55,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::pos_type; using lyx::char_type; @@ -743,7 +744,7 @@ string const corrected_env(string const & suffix, string const & env, // This could go to ParagraphParameters if we want to int Paragraph::startTeXParParams(BufferParams const & bparams, - ostream & os, bool moving_arg) const + odocstream & os, bool moving_arg) const { int column = 0; @@ -780,7 +781,7 @@ int Paragraph::startTeXParParams(BufferParams const & bparams, output = corrected_env("\\begin", "flushleft", ownerCode()); else output = corrected_env("\\begin", "flushright", ownerCode()); - os << output; + os << lyx::from_ascii(output); column += output.size(); break; } case LYX_ALIGN_RIGHT: { @@ -789,13 +790,13 @@ int Paragraph::startTeXParParams(BufferParams const & bparams, output = corrected_env("\\begin", "flushright", ownerCode()); else output = corrected_env("\\begin", "flushleft", ownerCode()); - os << output; + os << lyx::from_ascii(output); column += output.size(); break; } case LYX_ALIGN_CENTER: { string output; output = corrected_env("\\begin", "center", ownerCode()); - os << output; + os << lyx::from_ascii(output); column += output.size(); break; } @@ -807,7 +808,7 @@ int Paragraph::startTeXParParams(BufferParams const & bparams, // This could go to ParagraphParameters if we want to int Paragraph::endTeXParParams(BufferParams const & bparams, - ostream & os, bool moving_arg) const + odocstream & os, bool moving_arg) const { int column = 0; @@ -839,7 +840,7 @@ int Paragraph::endTeXParParams(BufferParams const & bparams, output = corrected_env("\\par\\end", "flushleft", ownerCode()); else output = corrected_env("\\par\\end", "flushright", ownerCode()); - os << output; + os << lyx::from_ascii(output); column += output.size(); break; } case LYX_ALIGN_RIGHT: { @@ -848,13 +849,13 @@ int Paragraph::endTeXParParams(BufferParams const & bparams, output = corrected_env("\\par\\end", "flushright", ownerCode()); else output = corrected_env("\\par\\end", "flushleft", ownerCode()); - os << output; + os << lyx::from_ascii(output); column += output.size(); break; } case LYX_ALIGN_CENTER: { string output; output = corrected_env("\\par\\end", "center", ownerCode()); - os << output; + os << lyx::from_ascii(output); column += output.size(); break; } @@ -868,7 +869,7 @@ int Paragraph::endTeXParParams(BufferParams const & bparams, bool Paragraph::simpleTeXOnePar(Buffer const & buf, BufferParams const & bparams, LyXFont const & outerfont, - ostream & os, TexRow & texrow, + odocstream & os, TexRow & texrow, OutputParams const & runparams) const { lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl; @@ -1178,6 +1179,8 @@ pos_type Paragraph::getFirstWord(Buffer const & buf, ostream & os, OutputParams break; bool ws; string str; + // FIXME UNICODE + // sgml::escapeChar takes a char, not lyx::char_type boost::tie(ws, str) = sgml::escapeChar(c); os << str; @@ -1241,6 +1244,8 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf, value_type c = getChar(i); bool ws; string str; + // FIXME UNICODE + // sgml::escapeChar takes a char, not lyx::char_type boost::tie(ws, str) = sgml::escapeChar(c); if (style->pass_thru) diff --git a/src/paragraph.h b/src/paragraph.h index aad01e8d04..92aa012dd7 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -24,9 +24,6 @@ #include "insets/insetbase.h" // only for InsetBase::Code -#include "support/types.h" - -#include class Buffer; class BufferParams; @@ -126,15 +123,15 @@ public: void validate(LaTeXFeatures &) const; /// - int startTeXParParams(BufferParams const &, std::ostream &, bool) const; + int startTeXParParams(BufferParams const &, lyx::odocstream &, bool) const; /// - int endTeXParParams(BufferParams const &, std::ostream &, bool) const; + int endTeXParParams(BufferParams const &, lyx::odocstream &, bool) const; /// bool simpleTeXOnePar(Buffer const &, BufferParams const &, - LyXFont const & outerfont, std::ostream &, + LyXFont const & outerfont, lyx::odocstream &, TexRow & texrow, OutputParams const &) const; /// Can we drop the standard paragraph wrapper? diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 8796129d43..51bbd4ffa4 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -29,13 +29,14 @@ #include +using lyx::docstring; +using lyx::odocstream; using lyx::pos_type; using std::endl; using std::upper_bound; using std::lower_bound; using std::string; -using std::ostream; // Initialization of the counter for the paragraph id's, @@ -45,15 +46,15 @@ namespace { struct special_phrase { string phrase; - string macro; + docstring macro; bool builtin; }; -special_phrase special_phrases[] = { - { "LyX", "\\LyX{}", false }, - { "TeX", "\\TeX{}", true }, - { "LaTeX2e", "\\LaTeXe{}", true }, - { "LaTeX", "\\LaTeX{}", true }, +special_phrase const special_phrases[] = { + { "LyX", lyx::from_ascii("\\LyX{}"), false }, + { "TeX", lyx::from_ascii("\\TeX{}"), true }, + { "LaTeX2e", lyx::from_ascii("\\LaTeXe{}"), true }, + { "LaTeX", lyx::from_ascii("\\LaTeX{}"), true }, }; size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase); @@ -346,7 +347,7 @@ int Paragraph::Pimpl::erase(pos_type start, pos_type end) } -void Paragraph::Pimpl::simpleTeXBlanks(ostream & os, TexRow & texrow, +void Paragraph::Pimpl::simpleTeXBlanks(odocstream & os, TexRow & texrow, pos_type const i, unsigned int & column, LyXFont const & font, @@ -410,7 +411,7 @@ bool Paragraph::Pimpl::isTextAt(string const & str, pos_type pos) const void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, BufferParams const & bparams, - ostream & os, + odocstream & os, TexRow & texrow, OutputParams const & runparams, LyXFont & font, @@ -427,13 +428,9 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, if (style.pass_thru) { if (c != Paragraph::META_INSET) { if (c != '\0') - os << c; - } else { - lyx::odocstringstream oss; - owner_->getInset(i)->plaintext(buf, oss, runparams); - // FIXME UNICODE - os << lyx::to_utf8(oss.str()); - } + os.put(c); + } else + owner_->getInset(i)->plaintext(buf, os, runparams); return; } @@ -491,7 +488,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, } bool close = false; - ostream::pos_type const len = os.tellp(); + odocstream::pos_type const len = os.tellp(); if ((inset->lyxCode() == InsetBase::GRAPHICS_CODE || inset->lyxCode() == InsetBase::MATH_CODE diff --git a/src/paragraph_pimpl.h b/src/paragraph_pimpl.h index 0187490187..a1d223e5d8 100644 --- a/src/paragraph_pimpl.h +++ b/src/paragraph_pimpl.h @@ -126,14 +126,14 @@ public: FontList fontlist; /// - void simpleTeXBlanks(std::ostream &, TexRow & texrow, + void simpleTeXBlanks(lyx::odocstream &, TexRow & texrow, lyx::pos_type const i, unsigned int & column, LyXFont const & font, LyXLayout const & style); /// void simpleTeXSpecialChars(Buffer const &, BufferParams const &, - std::ostream &, TexRow & texrow, + lyx::odocstream &, TexRow & texrow, OutputParams const &, LyXFont & font, LyXFont & running_font, LyXFont & basefont, diff --git a/src/rowpainter.C b/src/rowpainter.C index 204d5fd404..16a055426f 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -210,6 +210,10 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font) if (isPrintableNonspace(c)) { int const width2 = text_.singleWidth(par_, i, c, text_.getFont(par_, i)); + // FIXME UNICODE + // This does not work anymore, and non-ascii + // characters in source files are forbidden + // anyway. // dalet / resh dx = (c == 'ø' || c == 'ã') ? width2 - width diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 578eb85f39..0036da8753 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -622,13 +622,15 @@ string const rsplit(string const & a, string & piece, char delim) // This function escapes 8-bit characters and other problematic // characters that cause problems in latex labels. -string const escape(string const & lab) +docstring const escape(docstring const & lab) { - char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7', + lyx::char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - string enc; - for (string::size_type i = 0; i < lab.length(); ++i) { - unsigned char c= lab[i]; + docstring enc; + for (docstring::size_type i = 0; i < lab.length(); ++i) { + lyx::char_type c= lab[i]; + // FIXME We must change the following algorithm for UCS4 + // chars, but that will be a file format change. if (c >= 128 || c == '=' || c == '%') { enc += '='; enc += hexdigit[c>>4]; diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 2f61aaa8f4..00016c3932 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -201,7 +201,7 @@ std::string const split(std::string const & a, char delim); std::string const rsplit(std::string const & a, std::string & piece, char delim); /// Escapes non ASCII chars -std::string const escape(std::string const & lab); +lyx::docstring const escape(lyx::docstring const & lab); /// gives a vector of stringparts which have the delimiter delim std::vector const getVectorFromString(std::string const & str, diff --git a/src/support/unicode.C b/src/support/unicode.C index 8779aeee8d..374e5d25be 100644 --- a/src/support/unicode.C +++ b/src/support/unicode.C @@ -64,7 +64,7 @@ iconv_convert(iconv_t * cd, char ICONV_CONST * inbuf = const_cast(reinterpret_cast(buf)); size_t inbytesleft = buflen * sizeof(InType); - size_t const outsize = 1000; + size_t const outsize = 10000; static char out[outsize]; char * outbuf = out; size_t outbytesleft = outsize; diff --git a/src/tabular.C b/src/tabular.C index bb28318de3..9a25921ee9 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -38,6 +38,7 @@ #include using lyx::docstring; +using lyx::odocstream; using lyx::support::ltrim; using lyx::support::prefixIs; using lyx::support::rtrim; @@ -1827,7 +1828,7 @@ bool LyXTabular::isPartOfMultiColumn(row_type row, col_type column) const } -int LyXTabular::TeXTopHLine(ostream & os, row_type row) const +int LyXTabular::TeXTopHLine(odocstream & os, row_type row) const { // FIXME: assert or return 0 as in TeXBottomHLine()? BOOST_ASSERT(row != npos); @@ -1863,7 +1864,7 @@ int LyXTabular::TeXTopHLine(ostream & os, row_type row) const } -int LyXTabular::TeXBottomHLine(ostream & os, row_type row) const +int LyXTabular::TeXBottomHLine(odocstream & os, row_type row) const { // FIXME: return 0 or assert as in TeXTopHLine()? if (row == npos || row >= rows_) @@ -1899,7 +1900,7 @@ int LyXTabular::TeXBottomHLine(ostream & os, row_type row) const } -int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const +int LyXTabular::TeXCellPreamble(odocstream & os, idx_type cell) const { int ret = 0; @@ -1910,7 +1911,8 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const if (isMultiColumn(cell)) { os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{"; if (!cellinfo_of_cell(cell).align_special.empty()) { - os << cellinfo_of_cell(cell).align_special << "}{"; + os << lyx::from_ascii(cellinfo_of_cell(cell).align_special) + << "}{"; } else { if (leftLine(cell) && (isFirstCellInRow(cell) || @@ -1932,7 +1934,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const break; } os << '{' - << getPWidth(cell).asLatexString() + << lyx::from_ascii(getPWidth(cell).asLatexString()) << '}'; } else { switch (getAlignment(cell)) { @@ -1968,7 +1970,8 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const os << 'b'; break; } - os << "]{" << getPWidth(cell).asLatexString() << "}{"; + os << "]{" << lyx::from_ascii(getPWidth(cell).asLatexString()) + << "}{"; } else if (getUsebox(cell) == BOX_MINIPAGE) { os << "\\begin{minipage}["; switch (getVAlignment(cell)) { @@ -1982,14 +1985,15 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const os << 'b'; break; } - os << "]{" << getPWidth(cell).asLatexString() << "}\n"; + os << "]{" << lyx::from_ascii(getPWidth(cell).asLatexString()) + << "}\n"; ++ret; } return ret; } -int LyXTabular::TeXCellPostamble(ostream & os, idx_type cell) const +int LyXTabular::TeXCellPostamble(odocstream & os, idx_type cell) const { int ret = 0; @@ -2011,7 +2015,7 @@ int LyXTabular::TeXCellPostamble(ostream & os, idx_type cell) const } -int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const & buf, +int LyXTabular::TeXLongtableHeaderFooter(odocstream & os, Buffer const & buf, OutputParams const & runparams) const { if (!is_long_tabular) @@ -2111,7 +2115,7 @@ bool LyXTabular::isValidRow(row_type row) const } -int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf, +int LyXTabular::TeXRow(odocstream & os, row_type i, Buffer const & buf, OutputParams const & runparams) const { idx_type cell = getCellNumber(i, 0); @@ -2124,10 +2128,12 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf, } else if(!row_info[i].top_space.zero()) { if (use_booktabs) os << "\\addlinespace[" - << row_info[i].top_space.asLatexString() << "]\n"; + << lyx::from_ascii(row_info[i].top_space.asLatexString()) + << "]\n"; else { os << "\\noalign{\\vskip" - << row_info[i].top_space.asLatexString() << "}\n"; + << lyx::from_ascii(row_info[i].top_space.asLatexString()) + << "}\n"; } ++ret; } @@ -2165,7 +2171,9 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf, } else if (!row_info[i].bottom_space.zero()) { if (use_booktabs) os << "\\addlinespace"; - os << '[' << row_info[i].bottom_space.asLatexString() << ']'; + os << '[' + << lyx::from_ascii(row_info[i].bottom_space.asLatexString()) + << ']'; } os << '\n'; ++ret; @@ -2178,11 +2186,11 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf, } else if (!row_info[i].interline_space.zero()) { if (use_booktabs) os << "\\addlinespace[" - << row_info[i].interline_space.asLatexString() + << lyx::from_ascii(row_info[i].interline_space.asLatexString()) << "]\n"; else os << "\\noalign{\\vskip" - << row_info[i].interline_space.asLatexString() + << lyx::from_ascii(row_info[i].interline_space.asLatexString()) << "}\n"; ++ret; } @@ -2190,7 +2198,7 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf, } -int LyXTabular::latex(Buffer const & buf, ostream & os, +int LyXTabular::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { int ret = 0; @@ -2209,7 +2217,7 @@ int LyXTabular::latex(Buffer const & buf, ostream & os, os << "\\begin{tabular}{"; for (col_type i = 0; i < columns_; ++i) { if (!column_info[i].align_special.empty()) { - os << column_info[i].align_special; + os << lyx::from_ascii(column_info[i].align_special); } else { if (!use_booktabs && column_info[i].left_line) os << '|'; @@ -2243,7 +2251,7 @@ int LyXTabular::latex(Buffer const & buf, ostream & os, break; } os << '{' - << column_info[i].p_width.asLatexString() + << lyx::from_ascii(column_info[i].p_width.asLatexString()) << '}'; } else { switch (column_info[i].alignment) { diff --git a/src/tabular.h b/src/tabular.h index b650db8717..b1be68f7ff 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -310,7 +310,7 @@ public: /// void read(Buffer const &, LyXLex &); /// - int latex(Buffer const &, std::ostream &, + int latex(Buffer const &, lyx::odocstream &, OutputParams const &) const; // int docbook(Buffer const & buf, std::ostream & os, @@ -587,20 +587,20 @@ public: /// // helper function for Latex returns number of newlines /// - int TeXTopHLine(std::ostream &, row_type row) const; + int TeXTopHLine(lyx::odocstream &, row_type row) const; /// - int TeXBottomHLine(std::ostream &, row_type row) const; + int TeXBottomHLine(lyx::odocstream &, row_type row) const; /// - int TeXCellPreamble(std::ostream &, idx_type cell) const; + int TeXCellPreamble(lyx::odocstream &, idx_type cell) const; /// - int TeXCellPostamble(std::ostream &, idx_type cell) const; + int TeXCellPostamble(lyx::odocstream &, idx_type cell) const; /// - int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf, + int TeXLongtableHeaderFooter(lyx::odocstream &, Buffer const & buf, OutputParams const &) const; /// bool isValidRow(row_type const row) const; /// - int TeXRow(std::ostream &, row_type const row, Buffer const & buf, + int TeXRow(lyx::odocstream &, row_type const row, Buffer const & buf, OutputParams const &) const; /// // helper function for ASCII returns number of newlines -- 2.39.2