]> git.lyx.org Git - features.git/commitdiff
Introduce "inherit" encoding for latex_language
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 24 Dec 2017 16:10:42 +0000 (17:10 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 24 Dec 2017 16:10:42 +0000 (17:10 +0100)
This gets rid of the hardcoded latin1 encoding for verbatim. Instead,
verbatim now inherits the encoding from the context, which is what is
actually wanted here.

Fixes: #9012, #9258
lib/encodings
lib/languages
src/DocIterator.cpp
src/Text.cpp
src/frontends/qt4/GuiDocument.cpp
src/output_latex.cpp

index 924c996b967117cbaa2979c142237888fc3a1770..c43f63802863a0a600b1489870f30d91f0aa0775 100644 (file)
@@ -246,3 +246,9 @@ End
 # Pure 7bit ASCII encoding (partially hardcoded in LyX)
 Encoding ascii ascii "ASCII" ascii fixed none
 End
+
+# Semantic encodings
+
+# Inherit encoding of the context (used by verbatim)
+Encoding inherit inherit "" "" fixed none
+End
index 282d902c78adcb4953794ec6e5595d9f1e6fe289..4c3b49b2ac3b40534c8fd5d779b7daed84262381 100644 (file)
@@ -65,6 +65,8 @@
 # * Encoding is the default encoding used with TeX fonts.
 #   It is only used if Document > Settings > Language > Encoding
 #   is set to "Language Default" and "use non-TeX fonts" is FALSE.
+#   Encoding "inherit" means: keep encoding of the context (used by
+#   latex_language).
 # * InternalEncoding is used to tell LyX that babel internally sets a
 #   non-standard font encoding (such as hebrew to LHE or greek to LGR).
 #   If True, LyX cares for characters/macros that do not exist in
@@ -100,13 +102,13 @@ Language ignore
        GuiName          "Ignore"
        BabelName        ignore
        PolyglossiaName  ignore
-       Encoding         iso8859-1
+       Encoding         inherit
        LangCode         ignore
 End
 
 Language latex
        GuiName          "LaTeX"
-       Encoding         iso8859-1
+       Encoding         inherit
        LangCode         latex
 End
 
index 58b91dff3620f43a258b2a84daa056413c1da3d9..8f4021404cf4ecb455b5f708c6e6e3d8de96def4 100644 (file)
@@ -721,6 +721,17 @@ Encoding const * DocIterator::getEncoding() const
        Text const & text = *sl.text();
        Font font = text.getPar(sl.pit()).getFont(bp, sl.pos(),
                                                  text.outerFont(sl.pit()));
+       Encoding const * enc = font.language()->encoding();
+       if (enc->name() == "inherit") {
+               size_t const n = depth();
+               for (size_t i = 0; i < n; ++i) {
+                       Text const & otext = *slices_[i].text();
+                       Font ofont = otext.getPar(slices_[i].pit()).getFont(bp, slices_[i].pos(),
+                                                                 otext.outerFont(slices_[i].pit()));
+                       if (ofont.language()->encoding()->name() != "inherit")
+                               return ofont.language()->encoding();
+               }
+       }
        return font.language()->encoding();
 }
 
index 84f7857678f63144e564407bdbae52ec713a688a..001aca5ded7a8843e99cea04b0c7a5855d9605e9 100644 (file)
@@ -933,15 +933,12 @@ bool canInsertChar(Cursor const & cur, char_type c)
                }
        }
 
-       // Prevent to insert uncodable characters in verbatim and ERT
-       // (workaround for bug 9012)
-       // Don't do it for listings inset, since InsetListings::latex() tries
-       // to switch to a usable encoding which works in many cases (bug 9102).
-       if (par.isPassThru() && cur.inset().lyxCode() != LISTINGS_CODE &&
-           cur.current_font.language()) {
-               Encoding const * e = cur.current_font.language()->encoding();
+       // Prevent to insert uncodable characters in verbatim and ERT.
+       // The encoding is inherited from the context here.
+       if (par.isPassThru() && cur.getEncoding()) {
+               Encoding const * e = cur.getEncoding();
                if (!e->encodable(c)) {
-                       cur.message(_("Character is uncodable in verbatim paragraphs."));
+                       cur.message(_("Character is uncodable in this verbatim context."));
                        return false;
                }
        }
index e6217f5cb385549cb0b0660ccb8b5a02547c52c2..36f9fa4c06457b4510e8d2edddc314384bde458b 100644 (file)
@@ -1079,7 +1079,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        Encodings::const_iterator it = encodings.begin();
        Encodings::const_iterator const end = encodings.end();
        for (auto const & encvar : encodings) {
-               if (!encvar.unsafe())
+               if (!encvar.unsafe() && !encvar.guiName().empty())
                        encodinglist.append(qt_(encvar.guiName()));
        }
        encodinglist.sort();
index 5bb21cc2ac8bc3466904f3d1eaa34f81854d63b0..5cac0ad89f96c9d0a5e5381dc96506a7314f7035 100644 (file)
@@ -1530,7 +1530,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
        // * with useNonTeXFonts: "utf8plain",
        // * with XeTeX and TeX fonts: "ascii" (inputenc fails),
        // * with LuaTeX and TeX fonts: only one encoding accepted by luainputenc.
-       if (runparams.isFullUnicode())
+       if (runparams.isFullUnicode() || newEnc.name() == "inherit")
                return make_pair(false, 0);
 
        Encoding const & oldEnc = *runparams.encoding;