]> git.lyx.org Git - lyx.git/blobdiff - src/Encoding.cpp
Revert "Use swap in InsetText::updateBuffer for notes ad friends"
[lyx.git] / src / Encoding.cpp
index 73edc843ff361bfe977441284f67f10d498239e6..026ad3c43e190d8bbe48889d069a4cb948b5b45b 100644 (file)
@@ -25,8 +25,9 @@
 
 #include <boost/cstdint.hpp>
 
-#include <sstream>
+#include <iterator>
 #include <algorithm>
+#include <sstream>
 
 using namespace std;
 using namespace lyx::support;
@@ -58,7 +59,7 @@ MathAlphaSet mathalpha;
 /// The highest code point in UCS4 encoding (1<<20 + 1<<16)
 char_type const max_ucs4 = 0x110000;
 
-} // namespace anon
+} // namespace
 
 
 EncodingException::EncodingException(char_type c)
@@ -259,16 +260,19 @@ vector<char_type> Encoding::symbolsList() const
        // assure the used encoding is properly initialized
        init();
 
-       // first all encodable characters
-       vector<char_type> symbols(encodable_.begin(), encodable_.end());
-       // add those below start_encodable_
+       // first all those below start_encodable_
+       vector<char_type> symbols;
        for (char_type c = 0; c < start_encodable_; ++c)
                symbols.push_back(c);
-       // now the ones from the unicodesymbols file
-       CharInfoMap::const_iterator const end = unicodesymbols.end();
-       CharInfoMap::const_iterator it = unicodesymbols.begin();
-       for (; it != end; ++it)
-               symbols.push_back(it->first);
+       // add all encodable characters
+       copy(encodable_.begin(), encodable_.end(), back_inserter(symbols));
+       // now the ones from the unicodesymbols file that are not already there
+       for (pair<char_type, CharInfo> const & elem : unicodesymbols) {
+               if (find(symbols.begin(), symbols.end(), elem.first) == symbols.end())
+                       symbols.push_back(elem.first);
+       }
+       // finally, sort the vector
+       sort(symbols.begin(), symbols.end());
        return symbols;
 }
 
@@ -584,7 +588,8 @@ bool Encodings::isKnownScriptChar(char_type const c, string & preamble)
        if (it == unicodesymbols.end())
                return false;
 
-       if (it->second.textpreamble() != "textgreek" && it->second.textpreamble() != "textcyr")
+       if (it->second.textpreamble() != "textgreek"
+           && it->second.textpreamble() != "textcyrillic")
                return false;
 
        if (preamble.empty()) {
@@ -595,12 +600,34 @@ bool Encodings::isKnownScriptChar(char_type const c, string & preamble)
 }
 
 
+bool Encodings::needsScriptWrapper(string const & script, string const & fontenc)
+{
+       if (script == "textgreek")
+               return (fontenc != "LGR");
+       if (script == "textcyrillic") {
+               return (fontenc != "T2A" && fontenc != "T2B"
+                       && fontenc != "T2C" && fontenc != "X2");
+       }
+       return false;
+}
+
+
 bool Encodings::isMathAlpha(char_type c)
 {
        return mathalpha.count(c);
 }
 
 
+bool Encodings::isUnicodeTextOnly(char_type c)
+{
+       if (isASCII(c) || isMathAlpha(c))
+               return false;
+
+       CharInfoMap::const_iterator const it = unicodesymbols.find(c);
+       return it == unicodesymbols.end() || it->second.mathcommand().empty();
+}
+
+
 Encoding const *
 Encodings::fromLyXName(string const & name, bool allowUnsafe) const
 {
@@ -701,16 +728,16 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                                flags |= CharInfoForce;
                                forced.insert(symbol);
                        } else if (prefixIs(flag, "force=")) {
-                               vector<string> encodings =
+                               vector<string> encs =
                                        getVectorFromString(flag.substr(6), ";");
-                               for (size_t i = 0; i < encodings.size(); ++i)
-                                       forcedselected[encodings[i]].insert(symbol);
+                               for (size_t i = 0; i < encs.size(); ++i)
+                                       forcedselected[encs[i]].insert(symbol);
                                flags |= CharInfoForceSelected;
                        } else if (prefixIs(flag, "force!=")) {
-                               vector<string> encodings =
+                               vector<string> encs =
                                        getVectorFromString(flag.substr(7), ";");
-                               for (size_t i = 0; i < encodings.size(); ++i)
-                                       forcednotselected[encodings[i]].insert(symbol);
+                               for (size_t i = 0; i < encs.size(); ++i)
+                                       forcednotselected[encs[i]].insert(symbol);
                                flags |= CharInfoForceSelected;
                        } else if (flag == "mathalpha") {
                                mathalpha.insert(symbol);