Fix encoding inheritance with CJKUtf8 as custom document encoding

Fixes #11579

(cherry picked from commit b2604aa840)
This commit is contained in:
Juergen Spitzmueller 2020-02-07 16:18:47 +01:00 committed by Richard Kimberly Heck
parent ae1544fd51
commit e30adc702c

View File

@ -20,6 +20,7 @@
#include "Font.h" #include "Font.h"
#include "InsetList.h" #include "InsetList.h"
#include "Language.h" #include "Language.h"
#include "LaTeXFeatures.h"
#include "Paragraph.h" #include "Paragraph.h"
#include "LyXRC.h" #include "LyXRC.h"
#include "Text.h" #include "Text.h"
@ -706,12 +707,16 @@ Encoding const * DocIterator::getEncoding() const
Language const * lang = Language const * lang =
text.getPar(sl.pit()).getFont(bp, sl.pos(), text.getPar(sl.pit()).getFont(bp, sl.pos(),
text.outerFont(sl.pit())).language(); text.outerFont(sl.pit())).language();
// If we have a custom encoding for the buffer, we only switch // If we have a custom encoding for the buffer, we do not switch encoding ...
// encoding for CJK (see output_latex::switchEncoding())
bool const customenc = bool const customenc =
bp.inputenc != "auto" && bp.inputenc != "default"; 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 = Encoding const * enc =
(customenc && lang->encoding()->package() != Encoding::CJK) (customenc
&& (lang->encoding()->package() != Encoding::CJK || !cjk_non_utf8))
? &bp.encoding() : lang->encoding(); ? &bp.encoding() : lang->encoding();
// Some insets force specific encodings sometimes (e.g., listings in // Some insets force specific encodings sometimes (e.g., listings in
@ -744,7 +749,8 @@ Encoding const * DocIterator::getEncoding() const
// Again, if we have a custom encoding, this is used // Again, if we have a custom encoding, this is used
// instead of the language's. // instead of the language's.
Encoding const * oenc = Encoding const * oenc =
(customenc && olang->encoding()->package() != Encoding::CJK) (customenc
&& (olang->encoding()->package() != Encoding::CJK || !cjk_non_utf8))
? &bp.encoding() : olang->encoding(); ? &bp.encoding() : olang->encoding();
if (olang->encoding()->name() != "inherit") if (olang->encoding()->name() != "inherit")
return oenc; return oenc;