commit 565a89b2f4618249bd49349581b7eb8d85acd44a Author: Thibaut Cuvelier <tcuvel...@lyx.org> Date: Wed Oct 30 20:12:54 2024 +0100
Parse the new list of Unicode characters. I shamelessly copied the existing code for `symbols`, as it serves roughly the same purpose. The new code might be hosted somewhere else if deemed appropriate. --- src/mathed/MathFactory.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++ src/mathed/MathFactory.h | 3 ++ src/mathed/MathParser.h | 34 ++++++++++++++++++ 3 files changed, 124 insertions(+) diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index 2a25d8464a..ee2f3a2a3f 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -88,6 +88,7 @@ bool has_math_fonts; namespace { MathWordList theMathWordList; +MathVariantList theMathVariantList; bool isMathFontAvailable(string & name) @@ -346,6 +347,85 @@ void initSymbols() } +void initVariantSymbols() +{ + FileName const filename = libFileSearch(string(), "unicode_alphanum_variants"); + LYXERR(Debug::MATHED, "read variant symbols from " << filename); + if (filename.empty()) { + lyxerr << "Could not find variant symbols file" << endl; + return; + } + + ifstream fs(filename.toFilesystemEncoding().c_str()); + // limit the size of strings we read to avoid memory problems + fs >> setw(65636); + string line; + while (getline(fs, line)) { + if (line.empty() || line[0] == '#') + continue; + + // Split the line along spaces. + std::string character, bold, italic, bold_italic, script, bold_script, + fraktur, bold_fraktur, double_struck, sans, bold_sans, italic_sans, + bold_italic_sans, monospace; + line = split(line, character, ' '); + line = split(line, bold, ' '); + line = split(line, italic, ' '); + line = split(line, bold_italic, ' '); + line = split(line, script, ' '); + line = split(line, bold_script, ' '); + line = split(line, fraktur, ' '); + line = split(line, bold_fraktur, ' '); + line = split(line, double_struck, ' '); + line = split(line, sans, ' '); + line = split(line, bold_sans, ' '); + line = split(line, italic_sans, ' '); + line = split(line, bold_italic_sans, ' '); + line = split(line, monospace, ' '); + + // Deal with the special case of "": it means that there is no mapping. + if (character == "\"\"") continue; + if (bold == "\"\"") bold = ""; + if (italic == "\"\"") italic = ""; + if (bold_italic == "\"\"") bold_italic = ""; + if (script == "\"\"") script = ""; + if (bold_script == "\"\"") bold_script = ""; + if (fraktur == "\"\"") fraktur = ""; + if (bold_fraktur == "\"\"") bold_fraktur = ""; + if (double_struck == "\"\"") double_struck = ""; + if (sans == "\"\"") sans = ""; + if (bold_sans == "\"\"") bold_sans = ""; + if (italic_sans == "\"\"") italic_sans = ""; + if (bold_italic_sans == "\"\"") bold_italic_sans = ""; + if (monospace == "\"\"") monospace = ""; + + // Build the object, converting from ASCII std::string to actual docstring. + UnicodeVariants tmp; + tmp.character = from_ascii(character); + tmp.bold = from_ascii(bold); + tmp.italic = from_ascii(italic); + tmp.bold_italic = from_ascii(bold_italic); + tmp.script = from_ascii(script); + tmp.bold_script = from_ascii(bold_script); + tmp.fraktur = from_ascii(fraktur); + tmp.bold_fraktur = from_ascii(bold_fraktur); + tmp.double_struck = from_ascii(double_struck); + tmp.sans = from_ascii(sans); + tmp.bold_sans = from_ascii(bold_sans); + tmp.italic_sans = from_ascii(italic_sans); + tmp.bold_italic_sans = from_ascii(bold_italic_sans); + tmp.monospace = from_ascii(monospace); + + // Insert the new mappings if the character hasn't had previous mappings. + if (theMathVariantList.find(tmp.character) != theMathVariantList.end()) + LYXERR(Debug::MATHED, "readVariantSymbols: symbol " << to_utf8(tmp.character) + << " already exists."); + else + theMathVariantList[tmp.character] = tmp; + } +} + + bool isSpecialChar(docstring const & name) { if (name.size() != 1) @@ -366,6 +446,12 @@ MathWordList const & mathedWordList() } +MathVariantList const & mathedVariantList() +{ + return theMathVariantList; +} + + void initMath() { static bool initialized = false; @@ -373,6 +459,7 @@ void initMath() initialized = true; initParser(); initSymbols(); + initVariantSymbols(); } } diff --git a/src/mathed/MathFactory.h b/src/mathed/MathFactory.h index d653c54fb3..ce62536518 100644 --- a/src/mathed/MathFactory.h +++ b/src/mathed/MathFactory.h @@ -34,6 +34,9 @@ bool createInsetMath_fromDialogStr(docstring const &, MathData &); typedef std::map<docstring, latexkeys> MathWordList; MathWordList const & mathedWordList(); +typedef std::map<docstring, UnicodeVariants> MathVariantList; +MathVariantList const & mathedVariantList(); + } // namespace lyx #endif diff --git a/src/mathed/MathParser.h b/src/mathed/MathParser.h index ef9472bf90..67d616faba 100644 --- a/src/mathed/MathParser.h +++ b/src/mathed/MathParser.h @@ -67,6 +67,40 @@ public: }; +/// +class UnicodeVariants { +public: + /// Unicode base character (Latin/Greek letter, number). + docstring character; + /// The same Unicode character, in bold. + docstring bold; + /// The same Unicode character, in italic. + docstring italic; + /// The same Unicode character, in bold italic. + docstring bold_italic; + /// The same Unicode character, in script. + docstring script; + /// The same Unicode character, in bold script. + docstring bold_script; + /// The same Unicode character, in fraktur. + docstring fraktur; + /// The same Unicode character, in bold fraktur. + docstring bold_fraktur; + /// The same Unicode character, double-struck. + docstring double_struck; + /// The same Unicode character, in sans-serif. + docstring sans; + /// The same Unicode character, in bold sans-serif. + docstring bold_sans; + /// The same Unicode character, in italic sans-serif. + docstring italic_sans; + /// The same Unicode character, in bold italic sans-serif. + docstring bold_italic_sans; + /// The same Unicode character, in monospace. + docstring monospace; +}; + + /// check whether this is a well-known (La)TeX macro or primitive latexkeys const * in_word_set(docstring const & str); -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs