typedef map<char_type, CharInfo> CharInfoMap;
CharInfoMap unicodesymbols;
+typedef std::set<char_type> CharSet;
+CharSet forced;
+
/// The highest code point in UCS4 encoding (1<<20 + 1<<16)
char_type const max_ucs4 = 0x110000;
}
-Encoding::Encoding(string const & n, string const & l, string const & i,
- bool f, Encoding::Package p)
- : name_(n), latexName_(l), iconvName_(i), fixedwidth_(f), package_(p)
+Encoding::Encoding(string const & n, string const & l, string const & g,
+ string const & i, bool f, Encoding::Package p)
+ : name_(n), latexName_(l), guiName_(g), iconvName_(i), fixedwidth_(f), package_(p)
{
if (n == "ascii") {
// ASCII can encode 128 code points and nothing else
}
-docstring Encoding::latexChar(char_type c) const
+docstring Encoding::latexChar(char_type c, bool for_mathed) const
{
// assure the used encoding is properly initialized
init();
- if (c < start_encodable_)
+ if (iconvName_ == "UTF-8" && package_ == none)
+ return docstring(1, c);
+ if (c < start_encodable_ && !encodings.isForced(c))
return docstring(1, c);
if (encodable_.find(c) != encodable_.end())
return docstring(1, c);
+ if (for_mathed)
+ return docstring();
// c cannot (or should not) be encoded in this encoding
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
}
-bool Encodings::latexMathChar(char_type c, docstring & command)
+bool Encodings::latexMathChar(char_type c, Encoding const * encoding,
+ docstring & command)
{
+ if (encoding) {
+ command = encoding->latexChar(c, true);
+ if (!command.empty())
+ return false;
+ }
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
if (it == unicodesymbols.end())
throw EncodingException(c);
CharInfoMap::const_iterator it = unicodesymbols.begin();
size_t unicmd_size = 0;
- char_type c;
+ char_type c = 0;
for (; it != uniend; ++it) {
docstring const math = it->second.mathcommand;
docstring const text = it->second.textcommand;
}
+bool Encodings::isForced(char_type c)
+{
+ return (!forced.empty() && forced.find(c) != forced.end());
+}
+
+
Encoding const * Encodings::fromLyXName(string const & name) const
{
EncodingList::const_iterator const it = encodinglist.find(name);
flags = split(flags, flag, ',');
if (flag == "combining")
info.combining = true;
- else if (flag == "force")
+ else if (flag == "force") {
info.force = true;
- else
+ forced.insert(symbol);
+ } else
lyxerr << "Ignoring unknown flag `" << flag
<< "' for symbol `0x"
<< hex << symbol << dec
lex.next();
string const latexname = lex.getString();
lex.next();
+ string const guiname = lex.getString();
+ lex.next();
string const iconvname = lex.getString();
lex.next();
string const width = lex.getString();
package = Encoding::inputenc;
else if (p == "CJK")
package = Encoding::CJK;
+ else if (p == "japanese")
+ package = Encoding::japanese;
else
lex.printError("Unknown package");
LYXERR(Debug::INFO, "Reading encoding " << name);
encodinglist[name] = Encoding(name, latexname,
- iconvname, fixedwidth, package);
+ guiname, iconvname, fixedwidth, package);
if (lex.lex() != et_end)
lex.printError("Missing end");