Refine fix for bug #7800. Also allow setting the document encoding to

an encoding different from the automatically chosen one.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39823 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2011-10-09 14:45:51 +00:00
parent 6c85f8338f
commit 8edfef001d
3 changed files with 34 additions and 30 deletions

View File

@ -1164,18 +1164,18 @@ docstring const LaTeXFeatures::getTClassHTMLStyles() const {
namespace {
docstring const getFloatI18nPreamble(docstring const & type,
docstring const & name, Language const * lang,
Language const * buflang, bool const polyglossia)
Encoding const & enc, bool const polyglossia)
{
docstring const language = polyglossia ? from_ascii(lang->polyglossia())
: from_ascii(lang->babel());
docstring const enc = from_ascii(lang->encoding()->iconvName());
docstring const langenc = from_ascii(lang->encoding()->iconvName());
docstring const texenc = from_ascii(lang->encoding()->latexName());
docstring const bufenc = from_ascii(buflang->encoding()->iconvName());
docstring const translated = (enc == bufenc) ? name
docstring const bufenc = from_ascii(enc.iconvName());
docstring const s1 = docstring(1, 0xF0000);
docstring const s2 = docstring(1, 0xF0001);
docstring const translated = (langenc == bufenc) ? name
: from_ascii("\\inputencoding{") + texenc + from_ascii("}")
+ docstring(1, 0xF0000) + enc + docstring(1, 0xF0001)
+ translated
+ docstring(1, 0xF0000) + bufenc + docstring(1, 0xF0001);
+ s1 + langenc + s2 + translated + s1 + bufenc + s2;
odocstringstream os;
os << "\\addto\\captions" << language
@ -1199,17 +1199,18 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
for (; cit != end; ++cit) {
// language dependent commands (once per document)
snippets.insert(tclass[*cit].langpreamble(buffer().language(),
buffer().params().encoding(),
use_polyglossia));
// commands for language changing (for multilanguage documents)
if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
snippets.insert(tclass[*cit].babelpreamble(
buffer().language(),
buffer().language(),
buffer().params().encoding(),
use_polyglossia));
for (lang_it lit = lbeg; lit != lend; ++lit)
snippets.insert(tclass[*cit].babelpreamble(
*lit,
buffer().language(),
buffer().params().encoding(),
use_polyglossia));
}
}
@ -1230,7 +1231,8 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
if (flname != name)
snippets.insert(getFloatI18nPreamble(
type, name, buffer().language(),
buffer().language(), use_polyglossia));
buffer().params().encoding(),
use_polyglossia));
for (lang_it lit = lbeg; lit != lend; ++lit) {
string const code = (*lit)->code();
name = (*lit)->translateLayout(fl.name());
@ -1244,7 +1246,7 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
if (have_translation)
snippets.insert(getFloatI18nPreamble(
type, name, *lit,
buffer().language(),
buffer().params().encoding(),
use_polyglossia));
}
}

View File

@ -861,7 +861,7 @@ void Layout::readSpacing(Lexer & lex)
namespace {
docstring const i18npreamble(Language const * lang, Language const * buflang,
docstring const i18npreamble(Language const * lang, Encoding const & enc,
docstring const & templ, bool const polyglossia)
{
if (templ.empty())
@ -875,9 +875,9 @@ docstring const i18npreamble(Language const * lang, Language const * buflang,
// tex2lyx does not have getMessages()
LASSERT(false, /**/);
#else
string const enc = lang->encoding()->iconvName();
string const langenc = lang->encoding()->iconvName();
string const texenc = lang->encoding()->latexName();
string const bufenc = buflang->encoding()->iconvName();
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
@ -889,9 +889,9 @@ docstring const i18npreamble(Language const * lang, Language const * buflang,
while (regex_search(preamble, sub, reg)) {
string const key = sub.str(1);
string translated = to_utf8(lang->translateLayout(key));
if (enc != bufenc)
if (langenc != bufenc)
translated = "\\inputencoding{" + texenc + "}"
+ string(s1) + enc + string(s2) + translated
+ string(s1) + langenc + string(s2) + translated
+ string(s1) + bufenc + string(s2);
preamble = subst(preamble, sub.str(), translated);
}
@ -902,16 +902,17 @@ docstring const i18npreamble(Language const * lang, Language const * buflang,
}
docstring const Layout::langpreamble(Language const * lang, bool const polyglossia) const
docstring const Layout::langpreamble(Language const * lang,
Encoding const & enc, bool const polyglossia) const
{
return i18npreamble(lang, lang, langpreamble_, polyglossia);
return i18npreamble(lang, enc, langpreamble_, polyglossia);
}
docstring const Layout::babelpreamble(Language const * lang,
Language const * buflang, bool const polyglossia) const
Encoding const & enc, bool const polyglossia) const
{
return i18npreamble(lang, buflang, babelpreamble_, polyglossia);
return i18npreamble(lang, enc, babelpreamble_, polyglossia);
}

View File

@ -14,6 +14,7 @@
#ifndef LAYOUT_H
#define LAYOUT_H
#include "Encoding.h"
#include "FontInfo.h"
#include "LayoutEnums.h"
#include "Spacing.h"
@ -95,10 +96,10 @@ public:
docstring const & preamble() const { return preamble_; }
/// Get language dependent macro definitions needed for this layout
/// for language \p lang
docstring const langpreamble(Language const * lang, bool const polyglossia) const;
docstring const langpreamble(Language const * lang, Encoding const & enc, bool const polyglossia) const;
/// Get language and babel dependent macro definitions needed for
/// this layout for language \p lang
docstring const babelpreamble(Language const * lang, Language const * buflang, bool const polyglossia) const;
docstring const babelpreamble(Language const * lang, Encoding const & enc, bool const polyglossia) const;
///
std::set<std::string> const & requires() const { return requires_; }
///