From bd6885433adf952f4ceadb038e3b37a479cfc31f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 11 Jul 2002 09:34:58 +0000 Subject: [PATCH] remove hard-wired association LaTeX macro <-> mathed inset git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4599 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_amsarrayinset.h | 4 + src/mathed/math_factory.C | 197 +++++++------------------------- src/mathed/math_hullinset.C | 1 + src/mathed/math_mathmlstream.C | 7 ++ src/mathed/math_mathmlstream.h | 2 + src/mathed/math_parser.C | 4 +- src/mathed/math_support.C | 19 ++- src/mathed/math_support.h | 1 + 8 files changed, 76 insertions(+), 159 deletions(-) diff --git a/src/mathed/math_amsarrayinset.h b/src/mathed/math_amsarrayinset.h index 4c45fe2d49..55900da11b 100644 --- a/src/mathed/math_amsarrayinset.h +++ b/src/mathed/math_amsarrayinset.h @@ -8,6 +8,10 @@ #pragma interface #endif +// +// used for [pbvV]matrix, psmatrix etc +// + class MathAMSArrayInset : public MathGridInset { public: diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index 6fa68eaf20..24921d8df8 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -53,112 +53,6 @@ typedef std::map WordList; WordList theWordList; -struct key_type { - /// - string name; - /// - string inset; - /// - string extra; -}; - - -key_type wordlist_array[] = -{ - {"!", "space", ""}, - {",", "space", ""}, - {":", "space", ""}, - {";", "space", ""}, - {"Vmatrix", "matrix", ""}, - {"acute", "decoration", ""}, - {"bar", "decoration", ""}, - {"begin", "begin", ""}, - {"bf", "oldfont", ""}, - {"bmatrix", "matrix", ""}, - {"acute", "decoration", ""}, - {"breve", "decoration", ""}, - {"cal", "oldfont", ""}, - {"cdots", "dots", ""}, - {"check", "decoration", ""}, - {"ddot", "decoration", ""}, - {"dddot", "decoration", ""}, - {"ddots", "dots", ""}, - {"displaystyle", "style", ""}, - {"dot", "decoration", ""}, - {"dotsb", "dots", ""}, - {"dotsc", "dots", ""}, - {"dotsi", "dots", ""}, - {"dotsm", "dots", ""}, - {"dotso", "dots", ""}, - {"end", "end", ""}, - {"fbox", "fbox", ""}, - {"frak", "font", ""}, - {"grave", "decoration", ""}, - {"hat", "decoration", ""}, - {"it", "oldfont", ""}, - {"label", "label", ""}, - {"ldots", "dots", ""}, - {"left", "left", ""}, - {"lyxnegspace", "space", ""}, - {"lyxposspace", "space", ""}, - {"mathbb", "font", ""}, - {"mathbf", "font", ""}, - {"mathcal", "font", ""}, - {"mathfrak", "font", ""}, - {"mathit", "font", ""}, - {"mathnormal", "font", ""}, - {"mathring", "decoration", ""}, - {"mathrm", "font", ""}, - {"mathsf", "font", ""}, - {"mathtt", "font", ""}, - {"matrix", "matrix", ""}, - {"mbox", "mbox", ""}, - {"newcommand", "newcommand", ""}, - {"overbrace", "decoration", ""}, - {"overleftarrow", "decoration", ""}, - {"overline", "decoration", ""}, - {"overrightarrow", "decoration", ""}, - {"overleftrightarrow", "decoration", ""}, - {"pageref", "ref", ""}, - {"parbox", "parbox", ""}, - {"pmatrix", "matrix", ""}, - {"prettyref", "ref", ""}, - {"protect", "protect", ""}, - {"qquad", "space", ""}, - {"quad", "space", ""}, - {"ref", "ref", ""}, - {"right", "right", ""}, - {"rm", "oldfont", ""}, - {"scriptscriptstyle", "style", ""}, - {"scriptstyle", "style", ""}, - {"text", "font", "mathtext"}, - {"textbf", "font", "mathtext"}, - {"textipa", "font", "mathtext"}, - {"textit", "font", "mathtext"}, - {"textmd", "font", "mathtext"}, - {"textrm", "font", "mathtext"}, - {"textsl", "font", "mathtext"}, - {"textup", "font", "mathtext"}, - {"textstyle", "style", ""}, - {"tilde", "decoration", ""}, - {"tt", "oldfont", ""}, - {"underbar", "decoration", ""}, - {"underbrace", "decoration", ""}, - {"underleftarrow", "decoration", ""}, - {"underline", "decoration", ""}, - {"underrightarrow", "decoration", ""}, - {"underleftrightarrow", "decoration", ""}, - {"underset", "underset", ""}, - {"vdots", "dots", ""}, - {"vec", "decoration", ""}, - {"vmatrix", "matrix", ""}, - {"vpageref", "ref", ""}, - {"vref", "ref", ""}, - {"widehat", "decoration", ""}, - {"widetilde", "decoration", ""} -}; - - bool math_font_available(string & name) { LyXFont f; @@ -179,9 +73,15 @@ bool math_font_available(string & name) } -void readSymbols(string const & filename) +void initSymbols() { + string const filename = LibFileSearch(string(), "symbols"); lyxerr[Debug::MATHED] << "read symbols from " << filename << "\n"; + if (filename.empty()) { + lyxerr << "Could not find symbols file\n"; + return; + } + std::ifstream fs(filename.c_str()); while (fs) { int charid = 0; @@ -189,40 +89,51 @@ void readSymbols(string const & filename) latexkeys tmp; string line; getline(fs, line); + if (line.size() > 1 && line[0] == '#') + continue; istringstream is(line); - is >> tmp.name - >> tmp.inset - >> charid - >> fallbackid - >> tmp.extra - >> tmp.xmlname; - if (!is) + is >> tmp.name >> tmp.inset; + if (isFontName(tmp.inset)) + is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname; + else + is >> tmp.extra; + if (!is) { + lyxerr[Debug::MATHED] << "skipping line '" << line << "'\n"; + lyxerr[Debug::MATHED] + << tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << "\n"; continue; + } - // tmp.inset _is_ the fontname here. - // create fallbacks if necessary - if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra=="special") { - lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n"; - tmp.draw = tmp.name; - } else if (math_font_available(tmp.inset)) { - lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n"; - tmp.draw += char(charid); - } else if (fallbackid) { - if (tmp.inset == "cmex") - tmp.inset = "lyxsymbol"; - else - tmp.inset = "lyxboldsymbol"; - lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n"; - tmp.draw += char(fallbackid); + if (isFontName(tmp.inset)) { + // tmp.inset _is_ the fontname here. + // create fallbacks if necessary + if (tmp.extra=="func" || tmp.extra=="funclim" || tmp.extra=="special") { + lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n"; + tmp.draw = tmp.name; + } else if (math_font_available(tmp.inset)) { + lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n"; + tmp.draw += char(charid); + } else if (fallbackid) { + if (tmp.inset == "cmex") + tmp.inset = "lyxsymbol"; + else + tmp.inset = "lyxboldsymbol"; + lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n"; + tmp.draw += char(fallbackid); + } else { + lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n"; + tmp.draw = tmp.name; + tmp.inset = "lyxtex"; + } } else { - lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n"; - tmp.draw = tmp.name; - tmp.inset = "lyxtex"; + // it's a proper inset + lyxerr[Debug::MATHED] << "inset " << tmp.inset << " used for " + << tmp.name << "\n"; } if (theWordList.find(tmp.name) != theWordList.end()) lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name - << " already exists.\n"; + << " already exists.\n"; else theWordList[tmp.name] = tmp; lyxerr[Debug::MATHED] << "read symbol '" << tmp.name @@ -234,26 +145,6 @@ void readSymbols(string const & filename) } -void initSymbols() -{ - unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]); - for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) { - latexkeys tmp; - tmp.name = p->name; - tmp.inset = p->inset; - tmp.draw = p->name; - theWordList[p->name] = tmp; - } - - lyxerr[Debug::MATHED] << "reading symbols file\n"; - string const file = LibFileSearch(string(), "symbols"); - if (file.empty()) - lyxerr << "Could not find symbols file\n"; - else - readSymbols(file); -} - - } // namespace anon diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 739a945f5c..11833f0ed6 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -259,6 +259,7 @@ string MathHullInset::label(row_type row) const void MathHullInset::label(row_type row, string const & label) { + lyxerr << "setting label '" << label << "' for row " << row << endl; label_[row] = label; } diff --git a/src/mathed/math_mathmlstream.C b/src/mathed/math_mathmlstream.C index 7d5f9a9e3a..42ab2c1125 100644 --- a/src/mathed/math_mathmlstream.C +++ b/src/mathed/math_mathmlstream.C @@ -233,6 +233,13 @@ NormalStream & operator<<(NormalStream & ns, char c) } +NormalStream & operator<<(NormalStream & ns, int i) +{ + ns.os() << i; + return ns; +} + + ////////////////////////////////////////////////////////////////////// diff --git a/src/mathed/math_mathmlstream.h b/src/mathed/math_mathmlstream.h index 715e08c88f..6425e27d3b 100644 --- a/src/mathed/math_mathmlstream.h +++ b/src/mathed/math_mathmlstream.h @@ -93,6 +93,8 @@ NormalStream & operator<<(NormalStream &, MathArray const &); NormalStream & operator<<(NormalStream &, char const *); /// NormalStream & operator<<(NormalStream &, char); +/// +NormalStream & operator<<(NormalStream &, int); diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 0b93d3e99e..e4cf20698e 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -249,8 +249,6 @@ private: void error(string const & msg); /// dump contents to screen void dump() const; - -private: /// void tokenize(istream & is); /// @@ -656,7 +654,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags, if (flags & FLAG_OPTION) { if (t.cat() == catOther && t.character() == '[') { - // skip the bracket and collect everything to the clsing bracket + // skip the bracket and collect everything to the closing bracket flags |= FLAG_BRACK_LAST; continue; } diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index a02fa2ccfd..b67f6bf45f 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -589,21 +589,34 @@ fontinfo fontinfos[] = { }; -fontinfo * searchFont(string const & name) +fontinfo * lookupFont(string const & name) { - int const n = sizeof(fontinfos) / sizeof(fontinfo); //lyxerr << "searching font '" << name << "'\n"; + int const n = sizeof(fontinfos) / sizeof(fontinfo); for (int i = 0; i < n; ++i) if (fontinfos[i].cmd_ == name) { //lyxerr << "found '" << i << "'\n"; return fontinfos + i; } + return 0; +} + + +fontinfo * searchFont(string const & name) +{ + fontinfo * f = lookupFont(name); + return f ? f : fontinfos; // this should be mathnormal - return fontinfos; //return searchFont("mathnormal"); } +bool isFontName(string const & name) +{ + return lookupFont(name); +} + + LyXFont getFont(string const & name) { LyXFont font; diff --git a/src/mathed/math_support.h b/src/mathed/math_support.h index 2cd35476cf..5092aa48c2 100644 --- a/src/mathed/math_support.h +++ b/src/mathed/math_support.h @@ -41,5 +41,6 @@ void math_font_max_dim(LyXFont const &, int & asc, int & desc); void augmentFont(LyXFont & f, string const & cmd); +bool isFontName(string const & name); #endif -- 2.39.2