]> git.lyx.org Git - features.git/commitdiff
Fix bug 3235
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 18 Mar 2007 10:59:16 +0000 (10:59 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 18 Mar 2007 10:59:16 +0000 (10:59 +0000)
* 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

18 files changed:
src/buffer.C
src/converter.C
src/exporter.C
src/graphics/PreviewLoader.C
src/insets/insetcaption.C
src/insets/insetexternal.C
src/insets/insetfoot.C
src/insets/insetinclude.C
src/insets/insetnote.C
src/insets/insettabular.C
src/lyxfont.C
src/lyxfont.h
src/mathed/InsetMathHull.C
src/output_latex.C
src/outputparams.C
src/outputparams.h
src/paragraph.C
src/paragraph_pimpl.C

index 365408aa5e8ae52b4a2ad06782efb7d43c63a441..c70bd7444d4e803ad009eab286c2d39c96391e0a 100644 (file)
@@ -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(&params().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(&params().encoding());
        runparams.nice = true;
        runparams.flavor = OutputParams::LATEX;
        runparams.linelen = lyxrc.plaintext_linelen;
index 18dddd33dc3869effef6c00e4a194c8a0b7067af..0188df95e4efe1bff6b98a2865c6603a25f85a59 100644 (file)
@@ -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;
index d3ff74a95ef7e4e2df0315353e267d19c2e17312..ee96cee0d189e92a71e90f5379f811289355a413 100644 (file)
@@ -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<string> backends = Backends(*buffer);
index e31f1bafd6b23cbe56becda3c8f1cb34acdc5531..bc8a60f28868c4f6acb7f2bb41bd439474686f8d 100644 (file)
@@ -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 &>(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;
index 2da9e8b4a02ca0716b60aab6cffde10623ff2266..8fcbcc498719642386eeab326a63294f8cf00e61 100644 (file)
@@ -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;
 }
 
index 564101b16af1d463cca6da9d12763ee7d504a8e9..3c6961dff817110d1e16aa87c6196787e14d37bf 100644 (file)
@@ -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();
index 103f90c1dc4bd13481d4743f5643078c35f62f18..9b698b2ff8b66cac521ba5ab1b95f94b795d38cd 100644 (file)
@@ -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;
 }
index 067df5ac4eb6ffc108765e0f2571457d67f0612e..c2d08f788b243757d002bc02d48bf45085d7ee96 100644 (file)
@@ -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);
 
index 2e3bfd0460f8a7539af4914de399cb153b2cfc5d..38250c38af6004c44fd9ff7cc6bf8c0430587b8e 100644 (file)
@@ -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'));
 }
index 218f92394ca3d996a5ec2ff1bc4792549a4f3490..eaa5a72488f83268c9d9017e097547b0388473ea 100644 (file)
@@ -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());
index 3b5e883d23ebe492690d6efdac707c37bd1cda4b..05949567d55e9fd3a291d8cc17276cbcb71e234c 100644 (file)
@@ -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;
 }
index 0cfaaf24c5d94dbbcd5427f2a5b60f698dce5032..3d61113748842f910a450ba138a8f5b37518d74f 100644 (file)
@@ -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
index 17887b681c5390a42434c05ef9a97a546062b88e..2b42deda64cbe526efe8a4eef2de8b61cfcc6b0f 100644 (file)
@@ -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));
 }
 
 
index 58b21f3ea93bde2cd48aeec5bedea10859a89fda..a109c934b455da8c44deee79104097463dcc7bc6 100644 (file)
@@ -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
index 7783a4860a7835422d65fab4c6696cf686abfd40..9604f38f6dcd9f9b0cfed25beb70d4ca2e456891 100644 (file)
@@ -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),
index 4a521f393d52dc7b274cc2f0806bd3ebb0d510d9..fa9b98cdf04bd54461a6b6e5f722ffecf580fd88 100644 (file)
@@ -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.
        */
index 2d5ad8671d14329891229c317b4a858a3c617ba6..f95d48d1a22f4cba54b6ab67da3aac1822b2603d 100644 (file)
@@ -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
        }
 
index 1d3fd5a57a5e97a09d8b14e8120fc7a4bb47dfe5..6ce12872b6b47985d09b8e7a26f3a5367caad288 100644 (file)
@@ -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;