[LyX/2.3.x] Fix encoding inheritance with CJKUtf8 as custom document encoding

Juergen Spitzmueller spitz at lyx.org
Fri Feb 7 15:01:30 UTC 2020


commit b2604aa840a8ee1017fb8ac5f5bc740106976727
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Fri Feb 7 16:18:47 2020 +0100

    Fix encoding inheritance with CJKUtf8 as custom document encoding
    
    Fixes #11579
---
 src/DocIterator.cpp |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/DocIterator.cpp b/src/DocIterator.cpp
index e9b9580..04a2a1d 100644
--- a/src/DocIterator.cpp
+++ b/src/DocIterator.cpp
@@ -20,6 +20,7 @@
 #include "Font.h"
 #include "InsetList.h"
 #include "Language.h"
+#include "LaTeXFeatures.h"
 #include "Paragraph.h"
 #include "LyXRC.h"
 #include "Text.h"
@@ -705,13 +706,17 @@ Encoding const * DocIterator::getEncoding() const
 	Text const & text = *sl.text();
 	Language const * lang =
 		text.getPar(sl.pit()).getFont(bp, sl.pos(),
-										  text.outerFont(sl.pit())).language();
-	// If we have a custom encoding for the buffer, we only switch
-	// encoding for CJK (see output_latex::switchEncoding())
+					      text.outerFont(sl.pit())).language();
+	// If we have a custom encoding for the buffer, we do not switch encoding ...
 	bool const customenc =
 		bp.inputenc != "auto" && bp.inputenc != "default";
+	// ... except for non-CJKutf8 CJK (see output_latex::switchEncoding())
+	bool const cjk_non_utf8 =
+			bp.encoding().name() != "utf8-cjk"
+			|| !LaTeXFeatures::isAvailable("CJKutf8");
 	Encoding const * enc =
-		(customenc && lang->encoding()->package() != Encoding::CJK)
+		(customenc
+		 && (lang->encoding()->package() != Encoding::CJK || !cjk_non_utf8))
 		? &bp.encoding() : lang->encoding();
 
 	// Some insets force specific encodings sometimes (e.g., listings in
@@ -723,7 +728,7 @@ Encoding const * DocIterator::getEncoding() const
 			Text const & otext = *slices_[i].text();
 			Language const * olang =
 					otext.getPar(slices_[i].pit()).getFont(bp, slices_[i].pos(),
-														   otext.outerFont(slices_[i].pit())).language();
+									       otext.outerFont(slices_[i].pit())).language();
 			Encoding const * oenc = olang->encoding();
 			if (oenc->name() != "inherit")
 				return inset().forcedEncoding(enc, oenc);
@@ -740,11 +745,12 @@ Encoding const * DocIterator::getEncoding() const
 			Text const & otext = *slices_[i].text();
 			Language const * olang =
 					otext.getPar(slices_[i].pit()).getFont(bp, slices_[i].pos(),
-														   otext.outerFont(slices_[i].pit())).language();
+									       otext.outerFont(slices_[i].pit())).language();
 			// Again, if we have a custom encoding, this is used
 			// instead of the language's.
 			Encoding const * oenc =
-					(customenc && olang->encoding()->package() != Encoding::CJK)
+					(customenc
+					 && (olang->encoding()->package() != Encoding::CJK || !cjk_non_utf8))
 					? &bp.encoding() : olang->encoding();
 			if (olang->encoding()->name() != "inherit")
 				return oenc;


More information about the lyx-cvs mailing list