diff --git a/lib/languages b/lib/languages index e4c0dd5c94..d54d9f7367 100644 --- a/lib/languages +++ b/lib/languages @@ -10,6 +10,7 @@ # PolyglossiaName # PolyglossiaOpts "" # Encoding +# FontEncoding # QuoteStyle # InternalEncoding # RTL @@ -45,6 +46,8 @@ # Default" # * InternalEncoding is used to tell LyX that babel internally sets a font # encoding (such as hebrew to LHE). See bug #5091. +# * "FontEncoding none" tells LyX that fontenc should not be loaded with this +# language. # * AsBabelOptions advices LyX to pass the languages locally to babel, not # globally to the class. Some languages (basically those not directly # supported by babel) need this. @@ -143,6 +146,7 @@ Language arabic_arabi PolyglossiaName arabic QuoteStyle french Encoding cp1256 + FontEncoding "LFE,LAE" RTL true AsBabelOptions true LangCode ar_SA @@ -410,6 +414,7 @@ Language farsi BabelName farsi PolyglossiaName farsi Encoding utf8 + FontEncoding "LFE,LAE" RTL true LangCode fa_IR PostBabelPreamble @@ -511,6 +516,7 @@ Language greek QuoteStyle french Encoding iso8859-7 InternalEncoding true + FontEncoding "LGR" LangCode el_GR End @@ -522,6 +528,7 @@ Language polutonikogreek QuoteStyle french Encoding iso8859-7 InternalEncoding true + FontEncoding "LGR" LangCode el_GR End @@ -532,6 +539,7 @@ Language hebrew Encoding cp1255 QuoteStyle english InternalEncoding true + FontEncoding "LHE" RTL true LangCode he_IL End @@ -605,6 +613,7 @@ Language japanese AsBabelOptions true Requires japanese InternalEncoding true + FontEncoding None End # uses CJK package diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index f28d26d469..7a527a7592 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -1491,32 +1491,26 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, << from_ascii(fonts_default_family) << "}\n"; // set font encoding - // for arabic_arabi and farsi we also need to load the LAE and - // LFE encoding - // XeTeX and LuaTeX (with OS fonts) work without fontenc - if (font_encoding() != "default" && language->lang() != "japanese" - && !useNonTeXFonts && !features.isProvided("fontenc")) { - docstring extra_encoding; - if (features.mustProvide("textgreek")) - extra_encoding += from_ascii("LGR"); - if (features.mustProvide("textcyr")) { - if (!extra_encoding.empty()) - extra_encoding.push_back(','); - extra_encoding += from_ascii("T2A"); + // XeTeX and LuaTeX (with OS fonts) do not need fontenc + if (!useNonTeXFonts && !features.isProvided("fontenc") + && font_encoding() != "default") { + vector fontencs; + // primary language font encoding and default encoding + if (ascii_lowercase(language->fontenc()) != "none") { + vector fencs = getVectorFromString(font_encoding()); + fontencs.insert(fontencs.end(), fencs.begin(), fencs.end()); + fencs = getVectorFromString(language->fontenc()); + vector::const_iterator fit = fencs.begin(); + for (; fit != fencs.end(); ++fit) { + if (find(fontencs.begin(), fontencs.end(), *fit) == fontencs.end()) + fontencs.push_back(*fit); + } } - if (!extra_encoding.empty() && !font_encoding().empty()) - extra_encoding.push_back(','); - size_t fars = language_options.str().find("farsi"); - size_t arab = language_options.str().find("arabic"); - if (language->lang() == "arabic_arabi" - || language->lang() == "farsi" || fars != string::npos - || arab != string::npos) { - os << "\\usepackage[" << extra_encoding - << from_ascii(font_encoding()) - << ",LFE,LAE]{fontenc}\n"; - } else { - os << "\\usepackage[" << extra_encoding - << from_ascii(font_encoding()) + // get font encodings of secondary languages + features.getFontEncodings(fontencs); + if (!fontencs.empty()) { + os << "\\usepackage[" + << from_ascii(getStringFromVector(fontencs)) << "]{fontenc}\n"; } } diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 48c416dc0e..aa52ec4ffb 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -666,6 +666,30 @@ set LaTeXFeatures::getEncodingSet(string const & doc_encoding) const return encodings; } + +void LaTeXFeatures::getFontEncodings(vector & encodings) const +{ + // these must be loaded if glyphs of this script + // are used (notwithstanding the language) + if (mustProvide("textgreek")) + encodings.insert(encodings.begin(), "LGR"); + if (mustProvide("textcyr")) + encodings.insert(encodings.begin(), "T2A"); + + LanguageList::const_iterator it = UsedLanguages_.begin(); + LanguageList::const_iterator end = UsedLanguages_.end(); + for (; it != end; ++it) + if (!(*it)->fontenc().empty() + && ascii_lowercase((*it)->fontenc()) != "none") { + vector extraencs = getVectorFromString((*it)->fontenc()); + vector::const_iterator fit = extraencs.begin(); + for (; fit != extraencs.end(); ++fit) { + if (find(encodings.begin(), encodings.end(), *fit) == encodings.end()) + encodings.insert(encodings.begin(), *fit); + } + } +} + namespace { char const * simplefeatures[] = { diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 097fe4cf8c..0d417bd9d2 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -128,6 +128,8 @@ public: /// std::set getEncodingSet(std::string const & doc_encoding) const; /// + void getFontEncodings(std::vector & encodings) const; + /// void useLayout(docstring const & lyt); /// void useInsetLayout(InsetLayout const & lay); diff --git a/src/Language.cpp b/src/Language.cpp index 34ab1f0caf..28ce4e23e3 100644 --- a/src/Language.cpp +++ b/src/Language.cpp @@ -72,6 +72,7 @@ bool Language::readLanguage(Lexer & lex) LA_BABELNAME, LA_ENCODING, LA_END, + LA_FONTENC, LA_GUINAME, LA_INTERNAL_ENC, LA_LANG_CODE, @@ -91,6 +92,7 @@ bool Language::readLanguage(Lexer & lex) { "babelname", LA_BABELNAME }, { "encoding", LA_ENCODING }, { "end", LA_END }, + { "fontencoding", LA_FONTENC }, { "guiname", LA_GUINAME }, { "internalencoding", LA_INTERNAL_ENC }, { "langcode", LA_LANG_CODE }, @@ -145,6 +147,9 @@ bool Language::readLanguage(Lexer & lex) case LA_ENCODING: lex >> encodingStr_; break; + case LA_FONTENC: + lex >> fontenc_; + break; case LA_GUINAME: lex >> display_; break; diff --git a/src/Language.h b/src/Language.h index 6d54e2a201..177e55d8f6 100644 --- a/src/Language.h +++ b/src/Language.h @@ -76,6 +76,8 @@ public: std::string const babel_presettings() const { return babel_presettings_; } /// This language internally sets a font encoding bool internalFontEncoding() const { return internal_enc_; } + /// fontenc encoding(s) + std::string const fontenc() const { return fontenc_; } /// This language needs to be passed to babel itself (not the class) bool asBabelOptions() const { return as_babel_options_; } /// @@ -118,6 +120,8 @@ private: /// trivstring babel_presettings_; /// + trivstring fontenc_; + /// bool internal_enc_; /// bool as_babel_options_;