X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMathSupport.cpp;h=6a815ed8985e6b81605b4f201c6ecfffb865fab0;hb=d243e53f54e861c90ce7135f3d1a8d68d6202555;hp=a01b9294ae8eba9e832b5be036dc4e867b790f5f;hpb=5ddc612b735317d5b22553a63aad7879503e3950;p=lyx.git diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp index a01b9294ae..6a815ed898 100644 --- a/src/mathed/MathSupport.cpp +++ b/src/mathed/MathSupport.cpp @@ -4,37 +4,36 @@ * Licence details can be found in the file COPYING. * * \author Alejandro Aguilar Sierra - * \author André Pönitz + * \author André Pönitz * * Full author contact details are available in file CREDITS. */ #include -#include "InsetMath.h" +#include "MathSupport.h" + +#include "InsetMathFont.h" +#include "InsetMathSymbol.h" #include "MathData.h" #include "MathParser.h" #include "MathStream.h" -#include "MathSupport.h" - -#include "debug.h" #include "frontends/FontLoader.h" #include "frontends/FontMetrics.h" #include "frontends/Painter.h" +#include "support/debug.h" +#include "support/docstream.h" + #include -#include +using namespace std; namespace lyx { using frontend::Painter; -using std::max; -using std::endl; -using std::vector; - /// class Matrix { @@ -162,6 +161,15 @@ double const brack[] = { }; +double const dbrack[] = { + 2, 4, + 0.95, 0.05, 0.05, 0.05, 0.05, 0.95, 0.95, 0.95, + 2, 2, + 0.50, 0.05, 0.50, 0.95, + 0 +}; + + double const corner[] = { 2, 3, 0.95, 0.05, 0.05, 0.05, 0.05, 0.95, @@ -189,16 +197,25 @@ double const hline[] = { double const ddot[] = { - 1, 0.2, 0.5, 0.3, 0.5, - 1, 0.7, 0.5, 0.8, 0.5, + 1, 0.2, 0.5, 0.3, 0.5, + 1, 0.7, 0.5, 0.8, 0.5, 0 }; double const dddot[] = { - 1, 0.1, 0.5, 0.2, 0.5, + 1, 0.1, 0.5, 0.2, 0.5, + 1, 0.45, 0.5, 0.55, 0.5, + 1, 0.8, 0.5, 0.9, 0.5, + 0 +}; + + +double const ddddot[] = { + 1, 0.1, 0.5, 0.2, 0.5, 1, 0.45, 0.5, 0.55, 0.5, - 1, 0.8, 0.5, 0.9, 0.5, + 1, 0.8, 0.5, 0.9, 0.5, + 1, 1.15, 0.5, 1.25, 0.5, 0 }; @@ -280,6 +297,8 @@ named_deco_struct deco_table[] = { {"underleftarrow", arrow, 1 }, {"underrightarrow", arrow, 3 }, {"underleftrightarrow", udarrow, 1 }, + {"undertilde", tilde, 0 }, + {"utilde", tilde, 0 }, // Delimiters {"(", parenth, 0 }, @@ -290,12 +309,16 @@ named_deco_struct deco_table[] = { {"rbrace", brace, 2 }, {"[", brack, 0 }, {"]", brack, 2 }, + {"llbracket", dbrack, 0 }, + {"rrbracket", dbrack, 2 }, {"|", vert, 0 }, {"/", slash, 0 }, {"slash", slash, 0 }, {"vert", vert, 0 }, {"Vert", Vert, 0 }, {"'", slash, 1 }, + {"<", angle, 0 }, + {">", angle, 2 }, {"\\", slash, 1 }, {"backslash", slash, 1 }, {"langle", angle, 0 }, @@ -314,6 +337,7 @@ named_deco_struct deco_table[] = { // Accents {"ddot", ddot, 0 }, {"dddot", dddot, 0 }, + {"ddddot", ddddot, 0 }, {"hat", angle, 3 }, {"grave", slash, 1 }, {"acute", slash, 0 }, @@ -331,6 +355,8 @@ named_deco_struct deco_table[] = { {"cdots", hline3, 0 }, {"vdots", hline3, 1 }, {"ddots", dline3, 0 }, + {"adots", dline3, 1 }, + {"iddots", dline3, 1 }, {"dotsb", hline3, 0 }, {"dotsc", hline3, 0 }, {"dotsi", hline3, 0 }, @@ -339,7 +365,7 @@ named_deco_struct deco_table[] = { }; -std::map deco_list; +map deco_list; // sort the table on startup class init_deco_table { @@ -360,7 +386,7 @@ static init_deco_table dummy; deco_struct const * search_deco(docstring const & name) { - std::map::const_iterator p = deco_list.find(name); + map::const_iterator p = deco_list.find(name); return p == deco_list.end() ? 0 : &(p->second); } @@ -451,7 +477,7 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h, pi.pain.line( int(x + xx + 0.5), int(y + yy + 0.5), int(x + x2 + 0.5), int(y + y2 + 0.5), - Color_math); + pi.base.font.color()); } else { int xp[32]; int yp[32]; @@ -468,15 +494,24 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h, yp[j] = int(y + yy + 0.5); // lyxerr << "P[" << j ' ' << xx << ' ' << yy << ' ' << x << ' ' << y << ']'; } - pi.pain.lines(xp, yp, n, Color_math); + pi.pain.lines(xp, yp, n, pi.base.font.color()); } } } +void metricsStrRedBlack(MetricsInfo & mi, Dimension & dim, docstring const & str) +{ + FontInfo font = mi.base.font; + augmentFont(font, from_ascii("mathnormal")); + mathed_string_dim(font, str, dim); +} + + void drawStrRed(PainterInfo & pi, int x, int y, docstring const & str) { FontInfo f = pi.base.font; + augmentFont(f, from_ascii("mathnormal")); f.setColor(Color_latex); pi.pain.text(x, y, str, f); } @@ -485,6 +520,7 @@ void drawStrRed(PainterInfo & pi, int x, int y, docstring const & str) void drawStrBlack(PainterInfo & pi, int x, int y, docstring const & str) { FontInfo f = pi.base.font; + augmentFont(f, from_ascii("mathnormal")); f.setColor(Color_foreground); pi.pain.text(x, y, str, f); } @@ -499,7 +535,7 @@ void math_font_max_dim(FontInfo const & font, int & asc, int & des) struct fontinfo { - std::string cmd_; + string cmd_; FontFamily family_; FontSeries series_; FontShape shape_; @@ -534,6 +570,8 @@ fontinfo fontinfos[] = { inh_shape, Color_math}, {"mathit", inh_family, inh_series, ITALIC_SHAPE, Color_math}, + {"mathscr", RSFS_FAMILY, inh_series, + inh_shape, Color_math}, {"cmex", CMEX_FAMILY, inh_series, inh_shape, Color_math}, {"cmm", CMM_FAMILY, inh_series, @@ -548,6 +586,8 @@ fontinfo fontinfos[] = { inh_shape, Color_math}, {"msb", MSB_FAMILY, inh_series, inh_shape, Color_math}, + {"stmry", STMARY_FAMILY, inh_series, + inh_shape, Color_math}, {"wasy", WASY_FAMILY, inh_series, inh_shape, Color_math}, {"esint", ESINT_FAMILY, inh_series, @@ -581,6 +621,12 @@ fontinfo fontinfos[] = { {"textipa", inh_family, inh_series, inh_shape, Color_foreground}, + // mhchem support + {"ce", inh_family, inh_series, + inh_shape, Color_foreground}, + {"cf", inh_family, inh_series, + inh_shape, Color_foreground}, + // LyX internal usage {"lyxtex", inh_family, inh_series, UP_SHAPE, Color_latex}, @@ -605,7 +651,7 @@ fontinfo * lookupFont(docstring const & name0) { //lyxerr << "searching font '" << name << "'" << endl; int const n = sizeof(fontinfos) / sizeof(fontinfo); - std::string name = to_utf8(name0); + string name = to_utf8(name0); for (int i = 0; i < n; ++i) if (fontinfos[i].cmd_ == name) { //lyxerr << "found '" << i << "'" << endl; @@ -630,6 +676,20 @@ bool isFontName(docstring const & name) } +bool isMathFont(docstring const & name) +{ + fontinfo * f = lookupFont(name); + return f && f->color_ == Color_math; +} + + +bool isTextFont(docstring const & name) +{ + fontinfo * f = lookupFont(name); + return f && f->color_ == Color_foreground; +} + + FontInfo getFont(docstring const & name) { FontInfo font; @@ -677,6 +737,27 @@ void augmentFont(FontInfo & font, docstring const & name) } +bool isAlphaSymbol(MathAtom const & at) +{ + if (at->asCharInset() || + (at->asSymbolInset() && + at->asSymbolInset()->isOrdAlpha())) + return true; + + if (at->asFontInset()) { + MathData const & ar = at->asFontInset()->cell(0); + for (size_t i = 0; i < ar.size(); ++i) { + if (!(ar[i]->asCharInset() || + (ar[i]->asSymbolInset() && + ar[i]->asSymbolInset()->isOrdAlpha()))) + return false; + } + return true; + } + return false; +} + + docstring asString(MathData const & ar) { odocstringstream os; @@ -686,9 +767,11 @@ docstring asString(MathData const & ar) } -void asArray(docstring const & str, MathData & ar) +void asArray(docstring const & str, MathData & ar, Parse::flags pf) { - mathed_parse_cell(ar, str); + bool quiet = pf & Parse::QUIET; + if ((str.size() == 1 && quiet) || (!mathed_parse_cell(ar, str, pf) && quiet)) + mathed_parse_cell(ar, str, pf | Parse::VERBATIM); }