]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathSupport.cpp
GuiPrintNomencl.cpp: fix bug #7853
[lyx.git] / src / mathed / MathSupport.cpp
index f828b06d587159fa64415bbc2f38ee415c499a38..1d7358abb086563096c30d33bf61e942a1898cae 100644 (file)
@@ -4,7 +4,7 @@
  * 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 <config.h>
 
 #include "MathSupport.h"
-#include "MathArray.h"
+
 #include "InsetMath.h"
-#include "MathStream.h"
+#include "MathData.h"
 #include "MathParser.h"
-
-#include "debug.h"
-#include "LColor.h"
+#include "MathStream.h"
 
 #include "frontends/FontLoader.h"
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
+#include "support/debug.h"
+#include "support/docstream.h"
+
 #include <map>
-#include <sstream>
 
+using namespace std;
 
 namespace lyx {
 
 using frontend::Painter;
 
-using std::max;
-using std::endl;
-using std::vector;
-
 
 ///
 class Matrix {
@@ -190,16 +187,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
 };
 
@@ -281,6 +287,8 @@ named_deco_struct deco_table[] = {
        {"underleftarrow",      arrow,    1 },
        {"underrightarrow",     arrow,    3 },
        {"underleftrightarrow", udarrow,  1 },
+       {"undertilde",          tilde,    0 },
+       {"utilde",              tilde,    0 },
 
        // Delimiters
        {"(",              parenth,    0 },
@@ -297,6 +305,8 @@ named_deco_struct deco_table[] = {
        {"vert",           vert,       0 },
        {"Vert",           Vert,       0 },
        {"'",              slash,      1 },
+       {"<",              angle,      0 },
+       {">",              angle,      2 },
        {"\\",             slash,      1 },
        {"backslash",      slash,      1 },
        {"langle",         angle,      0 },
@@ -315,6 +325,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 },
@@ -332,6 +343,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 },
@@ -340,7 +353,7 @@ named_deco_struct deco_table[] = {
 };
 
 
-std::map<docstring, deco_struct> deco_list;
+map<docstring, deco_struct> deco_list;
 
 // sort the table on startup
 class init_deco_table {
@@ -361,7 +374,7 @@ static init_deco_table dummy;
 
 deco_struct const * search_deco(docstring const & name)
 {
-       std::map<docstring, deco_struct>::const_iterator p = deco_list.find(name);
+       map<docstring, deco_struct>::const_iterator p = deco_list.find(name);
        return p == deco_list.end() ? 0 : &(p->second);
 }
 
@@ -369,20 +382,20 @@ deco_struct const * search_deco(docstring const & name)
 } // namespace anon
 
 
-int mathed_char_width(LyXFont const & font, char_type c)
+int mathed_char_width(FontInfo const & font, char_type c)
 {
        return theFontMetrics(font).width(c);
 }
 
 
-int mathed_char_kerning(LyXFont const & font, char_type c)
+int mathed_char_kerning(FontInfo const & font, char_type c)
 {
        frontend::FontMetrics const & fm = theFontMetrics(font);
        return fm.rbearing(c) - fm.width(c);
 }
 
 
-void mathed_string_dim(LyXFont const & font,
+void mathed_string_dim(FontInfo const & font,
                       docstring const & s,
                       Dimension & dim)
 {
@@ -399,7 +412,7 @@ void mathed_string_dim(LyXFont const & font,
 }
 
 
-int mathed_string_width(LyXFont const & font, docstring const & s)
+int mathed_string_width(FontInfo const & font, docstring const & s)
 {
        return theFontMetrics(font).width(s);
 }
@@ -410,7 +423,7 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
 {
        if (name == ".") {
                pi.pain.line(x + w/2, y, x + w/2, y + h,
-                         LColor::cursor, Painter::line_onoffdash);
+                         Color_cursor, Painter::line_onoffdash);
                return;
        }
 
@@ -452,7 +465,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),
-                               LColor::math);
+                               pi.base.font.color());
                } else {
                        int xp[32];
                        int yp[32];
@@ -469,7 +482,7 @@ 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, LColor::math);
+                       pi.pain.lines(xp, yp, n, pi.base.font.color());
                }
        }
 }
@@ -477,21 +490,21 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
 
 void drawStrRed(PainterInfo & pi, int x, int y, docstring const & str)
 {
-       LyXFont f = pi.base.font;
-       f.setColor(LColor::latex);
+       FontInfo f = pi.base.font;
+       f.setColor(Color_latex);
        pi.pain.text(x, y, str, f);
 }
 
 
 void drawStrBlack(PainterInfo & pi, int x, int y, docstring const & str)
 {
-       LyXFont f = pi.base.font;
-       f.setColor(LColor::foreground);
+       FontInfo f = pi.base.font;
+       f.setColor(Color_foreground);
        pi.pain.text(x, y, str, f);
 }
 
 
-void math_font_max_dim(LyXFont const & font, int & asc, int & des)
+void math_font_max_dim(FontInfo const & font, int & asc, int & des)
 {
        frontend::FontMetrics const & fm = theFontMetrics(font);
        asc = fm.maxAscent();
@@ -500,105 +513,113 @@ void math_font_max_dim(LyXFont const & font, int & asc, int & des)
 
 
 struct fontinfo {
-       std::string cmd_;
-       LyXFont::FONT_FAMILY family_;
-       LyXFont::FONT_SERIES series_;
-       LyXFont::FONT_SHAPE  shape_;
-       LColor::color        color_;
+       string cmd_;
+       FontFamily family_;
+       FontSeries series_;
+       FontShape  shape_;
+       ColorCode        color_;
 };
 
 
-LyXFont::FONT_FAMILY const inh_family = LyXFont::INHERIT_FAMILY;
-LyXFont::FONT_SERIES const inh_series = LyXFont::INHERIT_SERIES;
-LyXFont::FONT_SHAPE  const inh_shape  = LyXFont::INHERIT_SHAPE;
+FontFamily const inh_family = INHERIT_FAMILY;
+FontSeries const inh_series = INHERIT_SERIES;
+FontShape  const inh_shape  = INHERIT_SHAPE;
 
 
 // mathnormal should be the first, otherwise the fallback further down
 // does not work
 fontinfo fontinfos[] = {
        // math fonts
-       {"mathnormal",    LyXFont::ROMAN_FAMILY, LyXFont::MEDIUM_SERIES,
-                         LyXFont::ITALIC_SHAPE, LColor::math},
-       {"mathbf",        inh_family, LyXFont::BOLD_SERIES,
-                         inh_shape, LColor::math},
-       {"mathcal",       LyXFont::CMSY_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"mathfrak",      LyXFont::EUFRAK_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"mathrm",        LyXFont::ROMAN_FAMILY, inh_series,
-                         LyXFont::UP_SHAPE, LColor::math},
-       {"mathsf",        LyXFont::SANS_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"mathbb",        LyXFont::MSB_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"mathtt",        LyXFont::TYPEWRITER_FAMILY, inh_series,
-                         inh_shape, LColor::math},
+       {"mathnormal",    ROMAN_FAMILY, MEDIUM_SERIES,
+                         ITALIC_SHAPE, Color_math},
+       {"mathbf",        inh_family, BOLD_SERIES,
+                         inh_shape, Color_math},
+       {"mathcal",       CMSY_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"mathfrak",      EUFRAK_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"mathrm",        ROMAN_FAMILY, inh_series,
+                         UP_SHAPE, Color_math},
+       {"mathsf",        SANS_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"mathbb",        MSB_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"mathtt",        TYPEWRITER_FAMILY, inh_series,
+                         inh_shape, Color_math},
        {"mathit",        inh_family, inh_series,
-                         LyXFont::ITALIC_SHAPE, LColor::math},
-       {"cmex",          LyXFont::CMEX_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"cmm",           LyXFont::CMM_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"cmr",           LyXFont::CMR_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"cmsy",          LyXFont::CMSY_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"eufrak",        LyXFont::EUFRAK_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"msa",           LyXFont::MSA_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"msb",           LyXFont::MSB_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"wasy",          LyXFont::WASY_FAMILY, inh_series,
-                         inh_shape, LColor::none},
-       {"esint",         LyXFont::ESINT_FAMILY, inh_series,
-                         inh_shape, LColor::none},
+                         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,
+                         inh_shape, Color_math},
+       {"cmr",           CMR_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"cmsy",          CMSY_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"eufrak",        EUFRAK_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"msa",           MSA_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"msb",           MSB_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"wasy",          WASY_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"esint",         ESINT_FAMILY, inh_series,
+                         inh_shape, Color_math},
 
        // Text fonts
        {"text",          inh_family, inh_series,
-                         inh_shape, LColor::foreground},
-       {"textbf",        inh_family, LyXFont::BOLD_SERIES,
-                         inh_shape, LColor::foreground},
+                         inh_shape, Color_foreground},
+       {"textbf",        inh_family, BOLD_SERIES,
+                         inh_shape, Color_foreground},
        {"textit",        inh_family, inh_series,
-                         LyXFont::ITALIC_SHAPE, LColor::foreground},
-       {"textmd",        inh_family, LyXFont::MEDIUM_SERIES,
-                         inh_shape, LColor::foreground},
+                         ITALIC_SHAPE, Color_foreground},
+       {"textmd",        inh_family, MEDIUM_SERIES,
+                         inh_shape, Color_foreground},
        {"textnormal",    inh_family, inh_series,
-                         LyXFont::UP_SHAPE, LColor::foreground},
-       {"textrm",        LyXFont::ROMAN_FAMILY,
-                         inh_series, LyXFont::UP_SHAPE,LColor::foreground},
+                         UP_SHAPE, Color_foreground},
+       {"textrm",        ROMAN_FAMILY,
+                         inh_series, UP_SHAPE,Color_foreground},
        {"textsc",        inh_family, inh_series,
-                         LyXFont::SMALLCAPS_SHAPE, LColor::foreground},
-       {"textsf",        LyXFont::SANS_FAMILY, inh_series,
-                         inh_shape, LColor::foreground},
+                         SMALLCAPS_SHAPE, Color_foreground},
+       {"textsf",        SANS_FAMILY, inh_series,
+                         inh_shape, Color_foreground},
        {"textsl",        inh_family, inh_series,
-                         LyXFont::SLANTED_SHAPE, LColor::foreground},
-       {"texttt",        LyXFont::TYPEWRITER_FAMILY, inh_series,
-                         inh_shape, LColor::foreground},
+                         SLANTED_SHAPE, Color_foreground},
+       {"texttt",        TYPEWRITER_FAMILY, inh_series,
+                         inh_shape, Color_foreground},
        {"textup",        inh_family, inh_series,
-                         LyXFont::UP_SHAPE, LColor::foreground},
+                         UP_SHAPE, Color_foreground},
 
        // TIPA support
        {"textipa",       inh_family, inh_series,
-                         inh_shape, LColor::foreground},
+                         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,
-                         LyXFont::UP_SHAPE, LColor::latex},
-       {"lyxsymbol",     LyXFont::SYMBOL_FAMILY, inh_series,
-                         inh_shape, LColor::math},
-       {"lyxboldsymbol", LyXFont::SYMBOL_FAMILY, LyXFont::BOLD_SERIES,
-                         inh_shape, LColor::math},
-       {"lyxblacktext",  LyXFont::ROMAN_FAMILY, LyXFont::MEDIUM_SERIES,
-                         LyXFont::UP_SHAPE, LColor::foreground},
+                         UP_SHAPE, Color_latex},
+       {"lyxsymbol",     SYMBOL_FAMILY, inh_series,
+                         inh_shape, Color_math},
+       {"lyxboldsymbol", SYMBOL_FAMILY, BOLD_SERIES,
+                         inh_shape, Color_math},
+       {"lyxblacktext",  ROMAN_FAMILY, MEDIUM_SERIES,
+                         UP_SHAPE, Color_foreground},
        {"lyxnochange",   inh_family, inh_series,
-                         inh_shape, LColor::foreground},
-       {"lyxfakebb",     LyXFont::TYPEWRITER_FAMILY, LyXFont::BOLD_SERIES,
-                         LyXFont::UP_SHAPE, LColor::math},
-       {"lyxfakecal",    LyXFont::SANS_FAMILY, LyXFont::MEDIUM_SERIES,
-                         LyXFont::ITALIC_SHAPE, LColor::math},
-       {"lyxfakefrak",   LyXFont::ROMAN_FAMILY, LyXFont::BOLD_SERIES,
-                         LyXFont::ITALIC_SHAPE, LColor::math}
+                         inh_shape, Color_foreground},
+       {"lyxfakebb",     TYPEWRITER_FAMILY, BOLD_SERIES,
+                         UP_SHAPE, Color_math},
+       {"lyxfakecal",    SANS_FAMILY, MEDIUM_SERIES,
+                         ITALIC_SHAPE, Color_math},
+       {"lyxfakefrak",   ROMAN_FAMILY, BOLD_SERIES,
+                         ITALIC_SHAPE, Color_math}
 };
 
 
@@ -606,7 +627,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;
@@ -631,9 +652,23 @@ bool isFontName(docstring const & name)
 }
 
 
-LyXFont getFont(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)
 {
-       LyXFont font;
+       FontInfo font;
        augmentFont(font, name);
        return font;
 }
@@ -655,7 +690,7 @@ void fakeFont(docstring const & orig, docstring const & fake)
 }
 
 
-void augmentFont(LyXFont & font, docstring const & name)
+void augmentFont(FontInfo & font, docstring const & name)
 {
        static bool initialized = false;
        if (!initialized) {
@@ -673,12 +708,12 @@ void augmentFont(LyXFont & font, docstring const & name)
                font.setSeries(info->series_);
        if (info->shape_ != inh_shape)
                font.setShape(info->shape_);
-       if (info->color_ != LColor::none)
+       if (info->color_ != Color_none)
                font.setColor(info->color_);
 }
 
 
-docstring asString(MathArray const & ar)
+docstring asString(MathData const & ar)
 {
        odocstringstream os;
        WriteStream ws(os);
@@ -687,9 +722,11 @@ docstring asString(MathArray const & ar)
 }
 
 
-void asArray(docstring const & str, MathArray & 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);
 }