X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FEncoding.cpp;h=47e27eb97d9c94e6909e8367618f5c6f41c197e8;hb=02d2e4aa3279b872c9786718dab4f95fd44e900a;hp=5c0681903593b475b4cb8e7f38b1ffec1e6e044a;hpb=7dfc6c7f8b1a0f71a5b6f2b4f153c73513739eae;p=lyx.git diff --git a/src/Encoding.cpp b/src/Encoding.cpp index 5c06819035..47e27eb97d 100644 --- a/src/Encoding.cpp +++ b/src/Encoding.cpp @@ -23,10 +23,9 @@ #include "support/textutils.h" #include "support/unicode.h" -#include - -#include #include +#include +#include #include using namespace std; @@ -189,9 +188,16 @@ bool Encoding::encodable(char_type c) const { // assure the used encoding is properly initialized init(); - if (iconvName_ == "UTF-8" && package_ == none) return true; + // platex does not load inputenc: force conversion of supported characters + if (package_ == Encoding::japanese + && ((0xb7 <= c && c <= 0x05ff) // Latin-1 Supplement ... Hebrew + || (0x1d00 <= c && c <= 0x218f) // Phonetic Extensions ... Number Forms + || (0x2193 <= c && c <= 0x2aff) // Arrows ... Supplemental Mathematical Operators + || (0xfb00 <= c && c <= 0xfb4f) // Alphabetic Presentation Forms + || (0x1d400 <= c && c <= 0x1d7ff))) // Mathematical Alphanumeric Symbols + return false; if (c < start_encodable_ && !isForced(c)) return true; if (encodable_.find(c) != encodable_.end()) @@ -223,8 +229,8 @@ pair Encoding::latexString(docstring const & input, bool d docstring uncodable; bool terminate = false; for (size_t n = 0; n < input.size(); ++n) { + char_type const c = input[n]; try { - char_type const c = input[n]; pair latex_char = latexChar(c); docstring const latex = latex_char.first; if (terminate && !prefixIs(latex, '\\') @@ -241,7 +247,8 @@ pair Encoding::latexString(docstring const & input, bool d result += latex; terminate = latex_char.second; } catch (EncodingException & /* e */) { - LYXERR0("Uncodable character in latexString!"); + LYXERR0("Uncodable character <" << docstring(1, c) + << "> in latexString!"); if (dryrun) { result += "<" + _("LyX Warning: ") + _("uncodable character") + " '"; @@ -267,7 +274,7 @@ vector Encoding::symbolsList() const // 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 const & elem : unicodesymbols) { + for (auto const & elem : unicodesymbols) { if (find(symbols.begin(), symbols.end(), elem.first) == symbols.end()) symbols.push_back(elem.first); } @@ -306,10 +313,11 @@ bool Encodings::latexMathChar(char_type c, bool mathmode, if (!encoding || command.empty()) { command = it->second.textcommand(); needsTermination = !it->second.textnotermination(); - addTextCmd(c); } if (mathmode) addMathSym(c); + else + addTextCmd(c); } return use_math; } @@ -580,36 +588,29 @@ string const Encodings::TIPAShortcut(char_type c) return string(); } -// Return true, if `c` is a supported Greek or Cyrillic letter. -bool Encodings::isKnownScriptChar(char_type const c, string & preamble) + +string const Encodings::isKnownScriptChar(char_type const c) { CharInfoMap::const_iterator const it = unicodesymbols.find(c); if (it == unicodesymbols.end()) - return false; - - if (it->second.textpreamble() != "textgreek" - && it->second.textpreamble() != "textcyrillic") - return false; - - if (preamble.empty()) { - preamble = it->second.textpreamble(); - return true; - } - return it->second.textpreamble() == preamble; + return string(); + // FIXME: parse complex textpreamble (may be list or alternatives, + // e.g., "subscript,textgreek" or "textcomp|textgreek") + if (it->second.textpreamble() == "textgreek" + || it->second.textpreamble() == "textcyrillic") + return it->second.textpreamble(); + return string(); } -bool Encodings::needsScriptWrapper(string const & script, string const & fontenc) +bool Encodings::fontencSupportsScript(string const & fontenc, string const & script) { - // Note: the wrapper is not required with Unicode font encoding "TU". - // However, this function is not called with non-TeX (Unicode) fonts. if (script == "textgreek") - return (fontenc != "LGR"); - if (script == "textcyrillic") { - return (fontenc != "T2A" && fontenc != "T2B" - && fontenc != "T2C" && fontenc != "X2"); - } + return (fontenc == "LGR" || fontenc == "TU"); + if (script == "textcyrillic") + return (fontenc == "T2A" || fontenc == "T2B" || fontenc == "T2C" + || fontenc == "X2" || fontenc == "TU"); return false; } @@ -635,9 +636,9 @@ Encodings::fromLyXName(string const & name, bool allowUnsafe) const { EncodingList::const_iterator const it = encodinglist.find(name); if (it == encodinglist.end()) - return 0; + return nullptr; if (!allowUnsafe && it->second.unsafe()) - return 0; + return nullptr; return &it->second; } @@ -661,7 +662,7 @@ Encodings::fromLaTeXName(string const & n, int const & p, bool allowUnsafe) cons if ((it->second.latexName() == name) && (it->second.package() & p) && (!it->second.unsafe() || allowUnsafe)) return &it->second; - return 0; + return nullptr; } @@ -673,7 +674,7 @@ Encodings::fromIconvName(string const & n, int const & p, bool allowUnsafe) cons if ((it->second.iconvName() == n) && (it->second.package() & p) && (!it->second.unsafe() || allowUnsafe)) return &it->second; - return 0; + return nullptr; } @@ -701,7 +702,7 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile) istringstream is(symbolslex.getString()); // reading symbol directly does not work if // char_type == wchar_t. - boost::uint32_t tmp; + uint32_t tmp; if(!(is >> hex >> tmp)) break; symbol = tmp;