Avoid \inputencoding altogether if the buffer encoding permits

(part of bug #7800).


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40612 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2012-01-14 01:21:00 +00:00
parent 4026c0dccd
commit 76c376c427
2 changed files with 26 additions and 5 deletions

View File

@ -1156,6 +1156,17 @@ docstring const getFloatI18nPreamble(docstring const & type,
Encoding const & enc, bool const polyglossia,
bool const unicode)
{
// Check whether name can be encoded in the buffer encoding
bool encodable = true;
if (!unicode) {
for (size_t i = 0; i < name.size(); ++i) {
if (enc.latexChar(name[i], true)[0] != name[i]) {
encodable = false;
break;
}
}
}
docstring const language = polyglossia ? from_ascii(lang->polyglossia())
: from_ascii(lang->babel());
docstring const langenc = from_ascii(lang->encoding()->iconvName());
@ -1163,7 +1174,7 @@ docstring const getFloatI18nPreamble(docstring const & type,
docstring const bufenc = from_ascii(enc.iconvName());
docstring const s1 = docstring(1, 0xF0000);
docstring const s2 = docstring(1, 0xF0001);
docstring const translated = (unicode || langenc == bufenc) ? name
docstring const translated = encodable ? name
: from_ascii("\\inputencoding{") + texenc + from_ascii("}")
+ s1 + langenc + s2 + name + s1 + bufenc + s2;

View File

@ -891,10 +891,20 @@ docstring const i18npreamble(Language const * lang, Encoding const & enc,
smatch sub;
while (regex_search(preamble, sub, reg)) {
string const key = sub.str(1);
string translated = to_utf8(lang->translateLayout(key));
if (!unicode && langenc != bufenc)
translated = "\\inputencoding{" + texenc + "}"
+ s1 + langenc + s2 + translated
docstring const name = lang->translateLayout(key);
// Check whether name can be encoded in the buffer encoding
bool encodable = true;
if (!unicode) {
for (size_t i = 0; i < name.size(); ++i) {
if (enc.latexChar(name[i], true)[0] != name[i]) {
encodable = false;
break;
}
}
}
string const translated = encodable ? to_utf8(name)
: "\\inputencoding{" + texenc + "}"
+ s1 + langenc + s2 + to_utf8(name)
+ s1 + bufenc + s2;
preamble = subst(preamble, sub.str(), translated);
}