X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLayout.cpp;h=a57a28e813a317f2aa0ca9a5d178124379ac7ab5;hb=ec3aed75ad965160a96547b7e36c924c5df7a91b;hp=6861b5b2b24a1f8c17ac9fad8f429f3a6928a1dc;hpb=8edfef001d791c3dd43a24dc9bbcf04c3430722a;p=lyx.git diff --git a/src/Layout.cpp b/src/Layout.cpp index 6861b5b2b2..a57a28e813 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -874,13 +874,14 @@ docstring const i18npreamble(Language const * lang, Encoding const & enc, #ifdef TEX2LYX // tex2lyx does not have getMessages() LASSERT(false, /**/); + (void)enc; #else string const langenc = lang->encoding()->iconvName(); string const texenc = lang->encoding()->latexName(); string const bufenc = enc.iconvName(); // First and second character of plane 15 (Private Use Area) - char const s1[5] = {0xf3, 0xb0, 0x80, 0x80, 0x00}; // U+F0000 - char const s2[5] = {0xf3, 0xb0, 0x80, 0x81, 0x00}; // U+F0001 + string const s1 = "\xf3\xb0\x80\x80"; // U+F0000 + string const s2 = "\xf3\xb0\x80\x81"; // U+F0001 // FIXME UNICODE // lyx::regex is not unicode-safe. // Should use QRegExp or (boost::u32regex, but that requires ICU) @@ -888,11 +889,19 @@ 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 (langenc != bufenc) - translated = "\\inputencoding{" + texenc + "}" - + string(s1) + langenc + string(s2) + translated - + string(s1) + bufenc + string(s2); + docstring const name = lang->translateLayout(key); + // Check whether name can be encoded in the buffer encoding + bool encodable = true; + 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); } #endif