]> git.lyx.org Git - lyx.git/blobdiff - src/Encoding.cpp
* GuiToolbar.cpp:
[lyx.git] / src / Encoding.cpp
index e75fe3ede7427bed321aeb13bfeb66edeb5166b4..cfdc6ebd837fb1c23a21653fb52d9b58fe6e713b 100644 (file)
@@ -247,6 +247,9 @@ struct CharInfo {
 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;
@@ -266,9 +269,9 @@ const char * EncodingException::what() const throw()
 }
 
 
-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
@@ -330,15 +333,19 @@ void Encoding::init() const
 }
 
 
-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);
@@ -370,8 +377,14 @@ vector<char_type> Encoding::symbolsList() const
 }
 
 
-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);
@@ -432,7 +445,7 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, docstring & rem)
 
                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;
@@ -573,6 +586,12 @@ bool Encodings::isKnownScriptChar(char_type const c, string & preamble)
 }
 
 
+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);
@@ -644,9 +663,10 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                        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
@@ -719,6 +739,8 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                        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();
@@ -744,7 +766,7 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
 
                        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");