Move font encoding information to languages.

This commit is contained in:
Juergen Spitzmueller 2015-01-24 14:02:16 +01:00
parent 9397e15aa7
commit 16c33b5f6e
6 changed files with 63 additions and 25 deletions

View File

@ -10,6 +10,7 @@
# PolyglossiaName <polyglossianame> # PolyglossiaName <polyglossianame>
# PolyglossiaOpts "<language-specific options>" # PolyglossiaOpts "<language-specific options>"
# Encoding <encoding> # Encoding <encoding>
# FontEncoding <font encoding>
# QuoteStyle <danish|english|french|german|polish|swedish> # QuoteStyle <danish|english|french|german|polish|swedish>
# InternalEncoding <true|false> # InternalEncoding <true|false>
# RTL <true|false> # RTL <true|false>
@ -45,6 +46,8 @@
# Default" # Default"
# * InternalEncoding is used to tell LyX that babel internally sets a font # * InternalEncoding is used to tell LyX that babel internally sets a font
# encoding (such as hebrew to LHE). See bug #5091. # 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 # * AsBabelOptions advices LyX to pass the languages locally to babel, not
# globally to the class. Some languages (basically those not directly # globally to the class. Some languages (basically those not directly
# supported by babel) need this. # supported by babel) need this.
@ -143,6 +146,7 @@ Language arabic_arabi
PolyglossiaName arabic PolyglossiaName arabic
QuoteStyle french QuoteStyle french
Encoding cp1256 Encoding cp1256
FontEncoding "LFE,LAE"
RTL true RTL true
AsBabelOptions true AsBabelOptions true
LangCode ar_SA LangCode ar_SA
@ -410,6 +414,7 @@ Language farsi
BabelName farsi BabelName farsi
PolyglossiaName farsi PolyglossiaName farsi
Encoding utf8 Encoding utf8
FontEncoding "LFE,LAE"
RTL true RTL true
LangCode fa_IR LangCode fa_IR
PostBabelPreamble PostBabelPreamble
@ -511,6 +516,7 @@ Language greek
QuoteStyle french QuoteStyle french
Encoding iso8859-7 Encoding iso8859-7
InternalEncoding true InternalEncoding true
FontEncoding "LGR"
LangCode el_GR LangCode el_GR
End End
@ -522,6 +528,7 @@ Language polutonikogreek
QuoteStyle french QuoteStyle french
Encoding iso8859-7 Encoding iso8859-7
InternalEncoding true InternalEncoding true
FontEncoding "LGR"
LangCode el_GR LangCode el_GR
End End
@ -532,6 +539,7 @@ Language hebrew
Encoding cp1255 Encoding cp1255
QuoteStyle english QuoteStyle english
InternalEncoding true InternalEncoding true
FontEncoding "LHE"
RTL true RTL true
LangCode he_IL LangCode he_IL
End End
@ -605,6 +613,7 @@ Language japanese
AsBabelOptions true AsBabelOptions true
Requires japanese Requires japanese
InternalEncoding true InternalEncoding true
FontEncoding None
End End
# uses CJK package # uses CJK package

View File

@ -1491,32 +1491,26 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
<< from_ascii(fonts_default_family) << "}\n"; << from_ascii(fonts_default_family) << "}\n";
// set font encoding // set font encoding
// for arabic_arabi and farsi we also need to load the LAE and // XeTeX and LuaTeX (with OS fonts) do not need fontenc
// LFE encoding if (!useNonTeXFonts && !features.isProvided("fontenc")
// XeTeX and LuaTeX (with OS fonts) work without fontenc && font_encoding() != "default") {
if (font_encoding() != "default" && language->lang() != "japanese" vector<string> fontencs;
&& !useNonTeXFonts && !features.isProvided("fontenc")) { // primary language font encoding and default encoding
docstring extra_encoding; if (ascii_lowercase(language->fontenc()) != "none") {
if (features.mustProvide("textgreek")) vector<string> fencs = getVectorFromString(font_encoding());
extra_encoding += from_ascii("LGR"); fontencs.insert(fontencs.end(), fencs.begin(), fencs.end());
if (features.mustProvide("textcyr")) { fencs = getVectorFromString(language->fontenc());
if (!extra_encoding.empty()) vector<string>::const_iterator fit = fencs.begin();
extra_encoding.push_back(','); for (; fit != fencs.end(); ++fit) {
extra_encoding += from_ascii("T2A"); if (find(fontencs.begin(), fontencs.end(), *fit) == fontencs.end())
fontencs.push_back(*fit);
}
} }
if (!extra_encoding.empty() && !font_encoding().empty()) // get font encodings of secondary languages
extra_encoding.push_back(','); features.getFontEncodings(fontencs);
size_t fars = language_options.str().find("farsi"); if (!fontencs.empty()) {
size_t arab = language_options.str().find("arabic"); os << "\\usepackage["
if (language->lang() == "arabic_arabi" << from_ascii(getStringFromVector(fontencs))
|| 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())
<< "]{fontenc}\n"; << "]{fontenc}\n";
} }
} }

View File

@ -666,6 +666,30 @@ set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
return encodings; return encodings;
} }
void LaTeXFeatures::getFontEncodings(vector<string> & 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<string> extraencs = getVectorFromString((*it)->fontenc());
vector<string>::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 { namespace {
char const * simplefeatures[] = { char const * simplefeatures[] = {

View File

@ -128,6 +128,8 @@ public:
/// ///
std::set<std::string> getEncodingSet(std::string const & doc_encoding) const; std::set<std::string> getEncodingSet(std::string const & doc_encoding) const;
/// ///
void getFontEncodings(std::vector<std::string> & encodings) const;
///
void useLayout(docstring const & lyt); void useLayout(docstring const & lyt);
/// ///
void useInsetLayout(InsetLayout const & lay); void useInsetLayout(InsetLayout const & lay);

View File

@ -72,6 +72,7 @@ bool Language::readLanguage(Lexer & lex)
LA_BABELNAME, LA_BABELNAME,
LA_ENCODING, LA_ENCODING,
LA_END, LA_END,
LA_FONTENC,
LA_GUINAME, LA_GUINAME,
LA_INTERNAL_ENC, LA_INTERNAL_ENC,
LA_LANG_CODE, LA_LANG_CODE,
@ -91,6 +92,7 @@ bool Language::readLanguage(Lexer & lex)
{ "babelname", LA_BABELNAME }, { "babelname", LA_BABELNAME },
{ "encoding", LA_ENCODING }, { "encoding", LA_ENCODING },
{ "end", LA_END }, { "end", LA_END },
{ "fontencoding", LA_FONTENC },
{ "guiname", LA_GUINAME }, { "guiname", LA_GUINAME },
{ "internalencoding", LA_INTERNAL_ENC }, { "internalencoding", LA_INTERNAL_ENC },
{ "langcode", LA_LANG_CODE }, { "langcode", LA_LANG_CODE },
@ -145,6 +147,9 @@ bool Language::readLanguage(Lexer & lex)
case LA_ENCODING: case LA_ENCODING:
lex >> encodingStr_; lex >> encodingStr_;
break; break;
case LA_FONTENC:
lex >> fontenc_;
break;
case LA_GUINAME: case LA_GUINAME:
lex >> display_; lex >> display_;
break; break;

View File

@ -76,6 +76,8 @@ public:
std::string const babel_presettings() const { return babel_presettings_; } std::string const babel_presettings() const { return babel_presettings_; }
/// This language internally sets a font encoding /// This language internally sets a font encoding
bool internalFontEncoding() const { return internal_enc_; } 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) /// This language needs to be passed to babel itself (not the class)
bool asBabelOptions() const { return as_babel_options_; } bool asBabelOptions() const { return as_babel_options_; }
/// ///
@ -118,6 +120,8 @@ private:
/// ///
trivstring babel_presettings_; trivstring babel_presettings_;
/// ///
trivstring fontenc_;
///
bool internal_enc_; bool internal_enc_;
/// ///
bool as_babel_options_; bool as_babel_options_;