From: Georg Baum Date: Sun, 18 Mar 2007 10:59:16 +0000 (+0000) Subject: Fix bug 3235 X-Git-Tag: 1.6.10~10574 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4f1d5e72ef98c7719d1cd054dabbffeaae716504;p=features.git Fix bug 3235 * src/insets/insetcaption.C (InsetCaption::latex): Copy back encoding to runparams_in * src/insets/insetfoot.C (InsetFoot::latex): ditto * src/insets/insetnote.C (InsetNote::latex): ditto * src/exporter.C (Exporter::Export): Create runparams with document encoding * src/converter.C (bool Converters::convert): ditto * src/buffer.C (Buffer::writeLaTeXSource): Copy back encoding to runparams_in (Buffer::runChktex): Create runparams with document encoding (Buffer::changeRefsIfUnique): ditto * src/outputparams.[Ch] (encoding): New member * src/lyxfont.C (LyXFont::latexWriteStartChanges): Don't switch the encoding anymore. This is now done in Paragraph::simpleTeXOnePar. (LyXFont::latexWriteEndChanges): Ditto * src/output_latex.C (TeXOnePar): Ditto * src/paragraph.C (Paragraph::simpleTeXOnePar): Switch the encoding between font changes if needed. * All other files: Adjust to the changes above git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17470 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/buffer.C b/src/buffer.C index 365408aa5e..c70bd7444d 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1022,6 +1022,7 @@ void Buffer::writeLaTeXSource(odocstream & os, lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made." << endl; } + runparams_in.encoding = runparams.encoding; // Just to be sure. (Asger) texrow().newline(); @@ -1157,7 +1158,7 @@ int Buffer::runChktex() message(_("Running chktex...")); // Generate the LaTeX file if neccessary - OutputParams runparams; + OutputParams runparams(¶ms().encoding()); runparams.flavor = OutputParams::LATEX; runparams.nice = false; makeLaTeXFile(FileName(name), org_path, runparams); @@ -1676,7 +1677,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, void Buffer::getSourceCode(odocstream & os, pit_type par_begin, pit_type par_end, bool full_source) { - OutputParams runparams; + OutputParams runparams(¶ms().encoding()); runparams.nice = true; runparams.flavor = OutputParams::LATEX; runparams.linelen = lyxrc.plaintext_linelen; diff --git a/src/converter.C b/src/converter.C index 18dddd33dc..0188df95e4 100644 --- a/src/converter.C +++ b/src/converter.C @@ -337,7 +337,7 @@ bool Converters::convert(Buffer const * buffer, from_ascii(from_format), from_ascii(to_format))); return false; } - OutputParams runparams; + OutputParams runparams(&buffer->params().encoding()); runparams.flavor = getFlavor(edgepath); // Some converters (e.g. lilypond) can only output files to the @@ -561,7 +561,7 @@ bool Converters::formatIsUsed(string const & format) bool Converters::scanLog(Buffer const & buffer, string const & /*command*/, FileName const & filename, ErrorList & errorList) { - OutputParams runparams; + OutputParams runparams(0); runparams.flavor = OutputParams::LATEX; LaTeX latex("", runparams, filename); TeXErrors terr; diff --git a/src/exporter.C b/src/exporter.C index d3ff74a95e..ee96cee0d1 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -149,7 +149,7 @@ bool Exporter::Export(Buffer * buffer, string const & format, bool put_in_tempdir, string & result_file) { string backend_format; - OutputParams runparams; + OutputParams runparams(&buffer->params().encoding()); runparams.flavor = OutputParams::LATEX; runparams.linelen = lyxrc.plaintext_linelen; vector backends = Backends(*buffer); diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index e31f1bafd6..bc8a60f288 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -679,7 +679,9 @@ void PreviewLoader::Impl::dumpPreamble(odocstream & os) const // Why on earth is Buffer::makeLaTeXFile a non-const method? Buffer & tmp = const_cast(buffer_); // Dump the preamble only. - OutputParams runparams; + // We don't need an encoding for runparams since it is not used by + // the preamble. + OutputParams runparams(0); runparams.flavor = OutputParams::LATEX; runparams.nice = true; runparams.moving_arg = true; diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index 2da9e8b4a0..8fcbcc4987 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -241,6 +241,7 @@ int InsetCaption::latex(Buffer const & buf, odocstream & os, os << '{'; l += InsetText::latex(buf, os, runparams); os << "}\n"; + runparams_in.encoding = runparams.encoding; return l + 1; } diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 564101b16a..3c6961dff8 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -803,7 +803,7 @@ bool preview_wanted(InsetExternalParams const & params) docstring const latex_string(InsetExternal const & inset, Buffer const & buffer) { odocstringstream os; - OutputParams runparams; + OutputParams runparams(0); runparams.flavor = OutputParams::LATEX; inset.latex(buffer, os, runparams); return os.str(); diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 103f90c1dc..9b698b2ff8 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -75,6 +75,7 @@ int InsetFoot::latex(Buffer const & buf, odocstream & os, int const i = InsetText::latex(buf, os, runparams); os << "%\n}"; + runparams_in.encoding = runparams.encoding; return i + 2; } diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 067df5ac4e..c2d08f788b 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -739,7 +739,7 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer) docstring const latex_string(InsetInclude const & inset, Buffer const & buffer) { odocstringstream os; - OutputParams runparams; + OutputParams runparams(0); runparams.flavor = OutputParams::LATEX; inset.latex(buffer, os, runparams); diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 2e3bfd0460..38250c38af 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -290,6 +290,7 @@ int InsetNote::latex(Buffer const & buf, odocstream & os, docstring const str = ss.str(); os << str; + runparams_in.encoding = runparams.encoding; // Return how many newlines we issued. return int(lyx::count(str.begin(), str.end(), '\n')); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 218f92394c..eaa5a72488 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1828,7 +1828,7 @@ bool InsetTabular::copySelection(LCursor & cur) true, true); odocstringstream os; - OutputParams const runparams; + OutputParams const runparams(0); paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t'); // Needed for the "Edit->Paste recent" menu and the system clipboard. cap::copySelection(cur, os.str()); diff --git a/src/lyxfont.C b/src/lyxfont.C index 3b5e883d23..05949567d5 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -23,7 +23,6 @@ #include "LColor.h" #include "lyxlex.h" #include "lyxrc.h" -#include "output_latex.h" #include "support/lstrings.h" @@ -738,13 +737,11 @@ 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(odocstream & os, LyXFont const & base, - LyXFont const & prev, - BufferParams const & bparams) const + LyXFont const & prev) const { bool env = false; - int count = switchEncoding(os, bparams, *(prev.language()->encoding()), - *(language()->encoding())); + int count = 0; if (language()->babel() != base.language()->babel() && language() != prev.language()) { if (isRightToLeft() != prev.isRightToLeft()) { @@ -836,8 +833,7 @@ int LyXFont::latexWriteStartChanges(odocstream & os, LyXFont const & base, // Returns number of chars written // This one corresponds to latexWriteStartChanges(). (Asger) int LyXFont::latexWriteEndChanges(odocstream & os, LyXFont const & base, - LyXFont const & next, - BufferParams const & bparams) const + LyXFont const & next) const { int count = 0; bool env = false; @@ -901,8 +897,6 @@ int LyXFont::latexWriteEndChanges(odocstream & os, LyXFont const & base, os << '}'; ++count; } - count += switchEncoding(os, bparams, *(language()->encoding()), - *(next.language()->encoding())); return count; } diff --git a/src/lyxfont.h b/src/lyxfont.h index 0cfaaf24c5..3d61113748 100644 --- a/src/lyxfont.h +++ b/src/lyxfont.h @@ -300,16 +300,14 @@ public: font state active now. */ int latexWriteStartChanges(odocstream &, LyXFont const & base, - LyXFont const & prev, - BufferParams const &) const; + 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(odocstream &, LyXFont const & base, - LyXFont const & next, - BufferParams const &) const; + LyXFont const & next) const; /// Build GUI description of font state diff --git a/src/mathed/InsetMathHull.C b/src/mathed/InsetMathHull.C index 17887b681c..2b42deda64 100644 --- a/src/mathed/InsetMathHull.C +++ b/src/mathed/InsetMathHull.C @@ -1513,7 +1513,7 @@ int InsetMathHull::docbook(Buffer const & buf, odocstream & os, void InsetMathHull::textString(Buffer const & buf, odocstream & os) const { - plaintext(buf, os, OutputParams()); + plaintext(buf, os, OutputParams(0)); } diff --git a/src/output_latex.C b/src/output_latex.C index 58b21f3ea9..a109c934b4 100644 --- a/src/output_latex.C +++ b/src/output_latex.C @@ -292,24 +292,6 @@ TeXOnePar(Buffer const & buf, } } - LyXFont const outerfont = - outerFont(std::distance(paragraphs.begin(), pit), - paragraphs); - // This must be identical to basefont in Paragraph::simpleTeXOnePar - LyXFont basefont = (pit->beginOfBody() > 0) ? - pit->getLabelFont(bparams, outerfont) : - pit->getLayoutFont(bparams, outerfont); - Encoding const & outer_encoding(*(outerfont.language()->encoding())); - // FIXME we switch from the outer encoding to the encoding of - // this paragraph, since I could not figure out the correct - // logic to take the encoding of the previous paragraph into - // account. This may result in some unneeded encoding changes. - if (switchEncoding(os, bparams, outer_encoding, - *(basefont.language()->encoding()))) { - os << '\n'; - texrow.newline(); - } - // In an inset with unlimited length (all in one row), // don't allow any special options in the paragraph if (!pit->forceDefaultParagraphs()) { @@ -360,9 +342,14 @@ TeXOnePar(Buffer const & buf, break; } + LyXFont const outerfont = + outerFont(std::distance(paragraphs.begin(), pit), + paragraphs); + // FIXME UNICODE os << from_utf8(everypar); bool need_par = pit->simpleTeXOnePar(buf, bparams, outerfont, + // *encoding, os, texrow, runparams); // Make sure that \\par is done with the font of the last @@ -456,17 +443,11 @@ TeXOnePar(Buffer const & buf, pending_newline = true; } - // FIXME we switch from the encoding of this paragraph to the - // outer encoding, since I could not figure out the correct logic - // to take the encoding of the next paragraph into account. - // This may result in some unneeded encoding changes. - basefont = pit->getLayoutFont(bparams, outerfont); - switchEncoding(os, bparams, *(basefont.language()->encoding()), - outer_encoding); if (pending_newline) { os << '\n'; texrow.newline(); } + runparams_in.encoding = runparams.encoding; // we don't need it for the last paragraph!!! // Note from JMarc: we will re-add a \n explicitely in diff --git a/src/outputparams.C b/src/outputparams.C index 7783a4860a..9604f38f6d 100644 --- a/src/outputparams.C +++ b/src/outputparams.C @@ -17,9 +17,9 @@ namespace lyx { -OutputParams::OutputParams() +OutputParams::OutputParams(Encoding const * enc) : flavor(LATEX), nice(false), moving_arg(false), - local_font(0), free_spacing(false), use_babel(false), + local_font(0), encoding(enc), free_spacing(false), use_babel(false), linelen(0), depth(0), exportdata(new ExportData), inComment(false), diff --git a/src/outputparams.h b/src/outputparams.h index 4a521f393d..fa9b98cdf0 100644 --- a/src/outputparams.h +++ b/src/outputparams.h @@ -21,6 +21,7 @@ namespace lyx { +class Encoding; class ExportData; class LyXFont; @@ -33,7 +34,7 @@ public: XML }; - OutputParams(); + OutputParams(Encoding const *); ~OutputParams(); /** The latex that we export depends occasionally on what is to @@ -68,6 +69,25 @@ public: */ mutable std::string document_language; + /** Current stream encoding. Only used for LaTeX. + This must be set to the document encoding (via the constructor) + before output starts. Afterwards it must be kept up to date for + each single character (\see Paragraph::simpleTeXOnePar). + This does also mean that you need to set it back if you use a + copy (e.g. in insets): \code + int InsetFoo::latex(..., OutputParams const & runparams_in) const + { + OutputParams runparams(runparams_in); + runparams.inComment = true; + ... + InsetBla::latex(..., runparams); + ... + runparams_in.encoding = runparams.encoding; + } + \endcode + */ + mutable Encoding const * encoding; + /** free_spacing == true means that the inset is in a free-spacing paragraph. */ diff --git a/src/paragraph.C b/src/paragraph.C index 2d5ad8671d..f95d48d1a2 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -33,6 +33,7 @@ #include "lyxrow.h" #include "messages.h" #include "outputparams.h" +#include "output_latex.h" #include "paragraph_funcs.h" #include "rowpainter.h" @@ -963,7 +964,6 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, // As long as we are in the label, this font is the base font of the // label. Before the first body character it is set to the base font // of the body. - // This must be identical to basefont in TeXOnePar(). LyXFont basefont; // output change tracking marks only if desired, @@ -1009,13 +1009,14 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, // Computed only once per paragraph since bparams.encoding() is expensive Encoding const & doc_encoding = bparams.encoding(); + for (pos_type i = 0; i < size(); ++i) { // First char in paragraph or after label? if (i == body_pos) { if (body_pos > 0) { if (open_font) { column += running_font.latexWriteEndChanges( - os, basefont, basefont, bparams); + os, basefont, basefont); open_font = false; } basefont = getLayoutFont(bparams, outerfont); @@ -1054,10 +1055,10 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, changeType, output); runningChangeType = changeType; - value_type c = getChar(i); + value_type const c = getChar(i); // Fully instantiated font - LyXFont font = getFont(bparams, i, outerfont); + LyXFont const font = getFont(bparams, i, outerfont); LyXFont const last_font = running_font; @@ -1068,19 +1069,27 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, { column += running_font.latexWriteEndChanges( os, basefont, - (i == body_pos-1) ? basefont : font, - bparams); + (i == body_pos-1) ? basefont : font); running_font = basefont; open_font = false; } + // Switch file encoding if necessary + int const count = switchEncoding(os, bparams, + *(runparams.encoding), + *(font.language()->encoding())); + if (count > 0) { + column += count; + runparams.encoding = font.language()->encoding(); + } + // Do we need to change font? if ((font != running_font || font.language() != running_font.language()) && i != body_pos - 1) { - column += font.latexWriteStartChanges( - os, basefont, last_font, bparams); + column += font.latexWriteStartChanges(os, basefont, + last_font); running_font = font; open_font = true; } @@ -1120,11 +1129,10 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, if (next_) { running_font .latexWriteEndChanges(os, basefont, - next_->getFont(bparams, 0, outerfont), - bparams); + next_->getFont(bparams, 0, outerfont)); } else { running_font.latexWriteEndChanges(os, basefont, - basefont, bparams); + basefont); } #else #ifdef WITH_WARNINGS @@ -1132,8 +1140,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, //#warning there as we start another \selectlanguage with the next paragraph if //#warning we are in need of this. This should be fixed sometime (Jug) #endif - running_font.latexWriteEndChanges(os, basefont, basefont, - bparams); + running_font.latexWriteEndChanges(os, basefont, basefont); #endif } diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 1d3fd5a57a..6ce12872b6 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -523,7 +523,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, } else { if (open_font) { column += running_font.latexWriteEndChanges( - os, basefont, basefont, bparams); + os, basefont, basefont); open_font = false; } @@ -578,7 +578,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, // some insets cannot be inside a font change command if (open_font && inset->noFontChange()) { column += running_font.latexWriteEndChanges( - os, basefont, basefont, bparams); + os, basefont, basefont); open_font = false; basefont = owner_->getLayoutFont(bparams, outerfont); running_font = basefont;