MCPcopy Create free account
hub / github.com/NanoMichael/MicroTeX / convertCharacter

Method convertCharacter

src/core/parser.cpp:935–1064  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

933}
934
935sptr<Atom> TeXParser::convertCharacter(wchar_t c, bool oneChar) throw(ex_parse) {
936 if (_ignoreWhiteSpace) {
937 // the unicode Greek Letters in math mode are not drawn with the Greek font
938 if (c >= 945 && c <= 969) {
939 // Greek small letter
940 return SymbolAtom::get(TeXFormula::_symbolMappings[c]);
941 } else if (c >= 913 && c <= 937) {
942 // Greek capital letter
943 wstring ltx;
944 utf82wide(TeXFormula::_symbolFormulaMappings[c].c_str(), ltx);
945 return TeXFormula(ltx)._root;
946 }
947 }
948
949 c = tex::convertToRomanNumber(c);
950
951 /*
952 * None alphanumeric character
953 */
954 if ((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z')) {
955 /*
956 * Find from registered UNICODE-table
957 */
958 const UnicodeBlock& block = UnicodeBlock::of(c);
959#ifdef HAVE_LOG
960 int idx = indexOf(DefaultTeXFont::_loadedAlphabets, block);
961 __log << "block of char: " << c << " is " << idx << endl;
962#endif // HAVE_LOG
963 bool exist = (indexOf(DefaultTeXFont::_loadedAlphabets, block) != -1);
964 if (!_isLoading && !exist) {
965 auto it = DefaultTeXFont::_registeredAlphabets.find(block);
966 if (it != DefaultTeXFont::_registeredAlphabets.end())
967 DefaultTeXFont::addAlphabet(DefaultTeXFont::_registeredAlphabets[block]);
968 }
969
970 auto sit = TeXFormula::_symbolMappings.find(c);
971 auto fit = TeXFormula::_symbolFormulaMappings.find(c);
972
973 /*
974 * Character not in the symbol-mapping and not in the formula-mapping, find from
975 * external font-mapping
976 */
977 if (sit == TeXFormula::_symbolMappings.end() &&
978 fit == TeXFormula::_symbolFormulaMappings.end()) {
979 FontInfos* fontInfos = nullptr;
980 bool isLatin = UnicodeBlock::BASIC_LATIN == block;
981 if ((isLatin && TeXFormula::isRegisteredBlock(UnicodeBlock::BASIC_LATIN)) || !isLatin) {
982 fontInfos = TeXFormula::getExternalFont(block);
983 }
984 if (fontInfos != nullptr) {
985 if (oneChar) return sptr<Atom>(new TextRenderingAtom(towstring(c), fontInfos));
986 int start = _pos++;
987 int en = _len - 1;
988 while (_pos < _len) {
989 c = _parseString[_pos];
990 if (!block.contains(c)) {
991 en = --_pos;
992 break;

Callers 1

macroFunction · 0.80

Calls 7

utf82wideFunction · 0.85
indexOfFunction · 0.85
towstringFunction · 0.85
ex_parseClass · 0.85
tostringFunction · 0.85
containsMethod · 0.80
TeXFormulaClass · 0.70

Tested by

no test coverage detected