From c627507b3f132bb972ff536f20a35c67cdf40afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Milde?= Date: Wed, 12 Jun 2019 11:48:47 +0200 Subject: [PATCH] Revert 051de65db and implement alternative fix for remainder of #11115. --- lib/encodings | 10 +- src/frontends/qt4/GuiDocument.cpp | 161 +++++++++++++++++------------ src/frontends/qt4/GuiDocument.h | 4 +- src/frontends/qt4/ui/LanguageUi.ui | 107 ++++++++----------- 4 files changed, 143 insertions(+), 139 deletions(-) diff --git a/lib/encodings b/lib/encodings index 42f0c10a03..71aee7670c 100644 --- a/lib/encodings +++ b/lib/encodings @@ -47,12 +47,12 @@ # and pt254. # inputenc's standard utf8 support: -Encoding utf8 utf8 "utf8 (default)" UTF-8 variable inputenc +Encoding utf8 utf8 "Default" UTF-8 variable inputenc End # extended utf8 support from the "ucs" package: # Larger set of supported characters but conflicts with some packages. -Encoding utf8x utf8x "utf8 (extended) [ucs] (utf8x)" UTF-8 variable inputenc +Encoding utf8x utf8x "Extended [ucs] (utf8x)" UTF-8 variable inputenc End # from http://www.ctan.org/pkg/armtex @@ -212,7 +212,7 @@ Encoding euc-kr KS "Korean (EUC-KR)" EUC-KR variable CJK End # The CJK package has yet another name for utf8... -Encoding utf8-cjk UTF8 "utf8 [CJK] (Chinese/Japanese/Korean)" UTF-8 variable CJK +Encoding utf8-cjk UTF8 "Extended [CJK] (Chinese/Japanese/Korean)" UTF-8 variable CJK End # For traditional chinese @@ -233,13 +233,13 @@ Encoding jis-platex jis "Japanese (pLaTeX) (JIS)" ISO-2022-JP variable japanese End Encoding shift-jis-platex sjis "Japanese (pLaTeX) (SJIS)" CP932 variable japanese End -Encoding utf8-platex utf8 "utf8 [pLaTeX] (Japanese)" UTF-8 variable japanese +Encoding utf8-platex utf8 "Extended [pLaTeX] (Japanese)" UTF-8 variable japanese End # A plain utf8 encoding that does not use the inputenc package # nor the LyX-added conversions in lib/unicodesymbols. # Such an encoding is required for XeTeX and LuaTeX. -Encoding utf8-plain utf8-plain "utf8 (pass-through)" UTF-8 variable none +Encoding utf8-plain utf8-plain "Pass-Through" UTF-8 variable none End # Pure 7bit ASCII encoding (partially hardcoded in LyX) diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 268fd36b1a..0f143b2cc0 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -156,6 +156,11 @@ QMap sffonts_; QMap ttfonts_; QMap mathfonts_; +enum EncodingSets { + unicode = 0, + legacy = 1, + custom = 2 +}; } // anonymous namespace @@ -931,18 +936,16 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(languageChanged(int))); + connect(langModule->encodingCO, SIGNAL(activated(int)), + this, SLOT(change_adaptor())); + connect(langModule->encodingCO, SIGNAL(activated(int)), + this, SLOT(encodingSwitched(int))); connect(langModule->unicodeEncodingCO, SIGNAL(activated(int)), - this, SLOT(change_adaptor())); - connect(langModule->autoEncodingCO, SIGNAL(activated(int)), - this, SLOT(change_adaptor())); + this, SLOT(change_adaptor())); connect(langModule->customEncodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); - connect(langModule->autoEncodingRB, SIGNAL(toggled(bool)), - this, SLOT(change_encoding())); - connect(langModule->unicodeEncodingRB, SIGNAL(toggled(bool)), - this, SLOT(change_encoding())); - connect(langModule->customEncodingRB, SIGNAL(toggled(bool)), - this, SLOT(change_encoding())); + connect(langModule->noInputencCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(langModule->languagePackageCO, SIGNAL(activated(int)), @@ -963,6 +966,16 @@ GuiDocument::GuiDocument(GuiView & lv) langModule->languageCO->setModel(language_model); langModule->languageCO->setModelColumn(0); + langModule->encodingCO->addItem(qt_("Unicode (utf8)")); + langModule->encodingCO->addItem(qt_("Traditional (auto-selected)")); + langModule->encodingCO->addItem(qt_("Custom")); + langModule->encodingCO->setItemData(EncodingSets::unicode, + "Use Unicode (utf8) for the latex source.", Qt::ToolTipRole); + langModule->encodingCO->setItemData(EncodingSets::legacy, + "Use legacy default encodings depending on text language.", Qt::ToolTipRole); + langModule->encodingCO->setItemData(EncodingSets::custom, + "Select a custom, document-wide encoding.", Qt::ToolTipRole); + QMap encodingmap_utf8; for (auto const & encvar : encodings) { if (!encvar.unsafe() && !encvar.guiName().empty() @@ -975,9 +988,6 @@ GuiDocument::GuiDocument(GuiView & lv) ++it8; } - langModule->autoEncodingCO->addItem(qt_("legacy language default"), toqstr("auto-legacy")); - langModule->autoEncodingCO->addItem(qt_("legacy language default (no inputenc)"), toqstr("auto-legacy-plain")); - QMap encodingmap; for (auto const & encvar : encodings) { if (!encvar.unsafe() && !encvar.guiName().empty() @@ -989,6 +999,11 @@ GuiDocument::GuiDocument(GuiView & lv) langModule->customEncodingCO->addItem(it.key(), it.value()); ++it; } + // equalise the width of encoding selectors + langModule->unicodeEncodingCO->setMinimumSize( + langModule->customEncodingCO->minimumSizeHint()); + langModule->noInputencCB->setMinimumSize( + langModule->customEncodingCO->minimumSizeHint()); langModule->languagePackageCO->addItem( qt_("Default"), toqstr("default")); @@ -1734,12 +1749,6 @@ void GuiDocument::change_adaptor() changed(); } -void GuiDocument::change_encoding() -{ - encodingSwitched(); - nonModuleChanged_ = true; - changed(); -} void GuiDocument::shellescapeChanged() { @@ -2281,11 +2290,10 @@ void GuiDocument::osFontsChanged(bool nontexfonts) fontModule->font_math = font_math; fontModule->font_sf_scale = font_sf_scale; fontModule->font_tt_scale = font_tt_scale; - // enable/disable input encoding selection - langModule->unicodeEncodingRB->setEnabled(tex_fonts); - langModule->autoEncodingRB->setEnabled(tex_fonts); - langModule->customEncodingRB->setEnabled(tex_fonts); - encodingSwitched(); + + // non-tex fonts override the "\inputencoding" option with "utf8-plain" + langModule->encodingCO->setEnabled(tex_fonts); + inputencodingToDialog(); fontModule->fontsDefaultCO->setEnabled(tex_fonts); fontModule->fontsDefaultLA->setEnabled(tex_fonts); @@ -2303,15 +2311,42 @@ void GuiDocument::osFontsChanged(bool nontexfonts) } -void GuiDocument::encodingSwitched() +void GuiDocument::encodingSwitched(int i) { bool const tex_fonts = !fontModule->osFontsCB->isChecked(); - langModule->unicodeEncodingCO->setEnabled(tex_fonts - && langModule->unicodeEncodingRB->isChecked()); - langModule->autoEncodingCO->setEnabled(tex_fonts - && langModule->autoEncodingRB->isChecked()); - langModule->customEncodingCO->setEnabled(tex_fonts - && langModule->customEncodingRB->isChecked()); + langModule->unicodeEncodingCO->setEnabled(tex_fonts); + langModule->customEncodingCO->setEnabled(tex_fonts); + langModule->noInputencCB->setEnabled(tex_fonts); + langModule->unicodeEncodingCO->setVisible(i == EncodingSets::unicode); + langModule->noInputencCB->setVisible(i == EncodingSets::legacy); + langModule->customEncodingCO->setVisible(i == EncodingSets::custom); +} + +void GuiDocument::inputencodingToDialog() +{ + QString inputenc = toqstr(bp_.inputenc); + int p; + if (fontModule->osFontsCB->isChecked()) { // non-tex fonts require utf8-plain + langModule->encodingCO->setCurrentIndex(EncodingSets::unicode); + langModule->unicodeEncodingCO->setCurrentIndex( + langModule->unicodeEncodingCO->findData("utf8-plain")); + } else if (inputenc.startsWith("utf8")) { + langModule->encodingCO->setCurrentIndex(EncodingSets::unicode); + p = langModule->unicodeEncodingCO->findData(inputenc); + if (p != -1) + langModule->unicodeEncodingCO->setCurrentIndex(p); + } else if (inputenc.startsWith("auto")) { + langModule->encodingCO->setCurrentIndex(EncodingSets::legacy); + langModule->noInputencCB->setChecked(inputenc == "auto-legacy-plain"); + } else { + langModule->encodingCO->setCurrentIndex(EncodingSets::custom); + p = langModule->customEncodingCO->findData(inputenc); + if (p != -1) + langModule->customEncodingCO->setCurrentIndex(p); + else + langModule->encodingCO->setCurrentIndex(EncodingSets::unicode); + } + encodingSwitched(langModule->encodingCO->currentIndex()); } @@ -3257,18 +3292,27 @@ void GuiDocument::applyView() indicesModule->apply(bp_); // language & quotes - if (langModule->unicodeEncodingRB->isChecked()) - bp_.inputenc = fromqstr(langModule->unicodeEncodingCO->itemData( - langModule->unicodeEncodingCO->currentIndex()).toString()); - else if (langModule->autoEncodingRB->isChecked()) - bp_.inputenc = fromqstr(langModule->autoEncodingCO->itemData( - langModule->autoEncodingCO->currentIndex()).toString()); - else if (langModule->customEncodingRB->isChecked()) - bp_.inputenc = fromqstr(langModule->customEncodingCO->itemData( - langModule->customEncodingCO->currentIndex()).toString()); - else // this should never happen - bp_.inputenc = "utf8"; - + switch (langModule->encodingCO->currentIndex()) { + case EncodingSets::unicode: { + bp_.inputenc = fromqstr(langModule->unicodeEncodingCO->itemData( + langModule->unicodeEncodingCO->currentIndex()).toString()); + break; + } + case EncodingSets::legacy: { + bp_.inputenc = "auto-legacy"; + if (langModule->noInputencCB->isChecked()) + bp_.inputenc = "auto-legacy-plain"; + break; + } + case EncodingSets::custom: { + bp_.inputenc = fromqstr(langModule->customEncodingCO->itemData( + langModule->customEncodingCO->currentIndex()).toString()); + break; + } + default: + // this should never happen + bp_.inputenc = "utf8"; + } bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData( langModule->quoteStyleCO->currentIndex()).toInt(); bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked(); @@ -3760,31 +3804,10 @@ void GuiDocument::paramsToDialog() langModule->quoteStyleCO->setCurrentIndex( langModule->quoteStyleCO->findData(bp_.quotes_style)); langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes); - // LaTeX input encoding - QString inputenc = toqstr(bp_.inputenc); - int p; - if (inputenc.startsWith("utf8")) { - langModule->unicodeEncodingRB->setChecked(true); - p = langModule->unicodeEncodingCO->findData(inputenc); - if (p != -1) { - langModule->unicodeEncodingCO->setCurrentIndex(p); - } - } else if (inputenc.startsWith("auto")) { - langModule->autoEncodingRB->setChecked(true); - p = langModule->autoEncodingCO->findData(inputenc); - if (p != -1) { - langModule->autoEncodingCO->setCurrentIndex(p); - } - } else { - langModule->customEncodingRB->setChecked(true); - p = langModule->customEncodingCO->findData(inputenc); - if (p != -1) { - langModule->customEncodingCO->setCurrentIndex(p); - } - } - encodingSwitched(); - // language package - p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package)); + + // LaTeX input encoding: set after the fonts (see below) + + int p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package)); if (p == -1) { langModule->languagePackageCO->setCurrentIndex( langModule->languagePackageCO->findData("custom")); @@ -4141,6 +4164,10 @@ void GuiDocument::paramsToDialog() fontModule->fontencLE->setText(toqstr(bp_.fontenc)); } + // LaTeX input encoding + // Set after fonts because non-tex fonts override "\inputencoding". + inputencodingToDialog(); + // Formats // This must be set _after_ fonts since updateDefaultFormat() // checks osFontsCB settings. diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index c398375051..3e0c35384b 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -101,7 +101,6 @@ public Q_SLOTS: private Q_SLOTS: void updateNumbering(); void change_adaptor(); - void change_encoding(); void shellescapeChanged(); void includeonlyClicked(QTreeWidgetItem * item, int); void setListingsMessage(); @@ -153,7 +152,8 @@ private Q_SLOTS: void deleteBoxBackgroundColor(); void languageChanged(int); void osFontsChanged(bool); - void encodingSwitched(); + void encodingSwitched(int); + void inputencodingToDialog(); void mathFontChanged(int); void branchesRename(docstring const &, docstring const &); void allPackagesAuto(); diff --git a/src/frontends/qt4/ui/LanguageUi.ui b/src/frontends/qt4/ui/LanguageUi.ui index 686cb5eb48..9624ce0d9f 100644 --- a/src/frontends/qt4/ui/LanguageUi.ui +++ b/src/frontends/qt4/ui/LanguageUi.ui @@ -83,30 +83,60 @@ + + + + &Encoding: + + + encodingCO + + + + + + + true + + + false + + + Select encoding of the generated LaTeX source + (LaTeX input encoding). + + + - - false + + true Select Unicode (utf8) variant. - - - + + + false + + false + + + Do not load inputenc + - Specify whether to load the 'inputenc' package - and write input encoding switch commands to the source. + Do not to load the 'inputenc' package + nor write input encoding switch commands to the source. - + - + false @@ -114,13 +144,6 @@ - - - - Select which language package LyX should use - - - @@ -131,56 +154,10 @@ - - - - &Encoding: - + + - Encoding of the generated LaTeX source - (LaTeX input encoding). - - - unicodeEncodingRB - - - - - - - true - - - Unicode - - - Set input encoding to Unicode (utf8). - - - - - - - true - - - Automatic - - - Use language specific legacy encodings. - - - - - - - true - - - Custom - - - Use custom document-wide encoding. + Select which language package LyX should use