]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_support.C
Andreas' patch to prevent crash on click on previewd inset
[lyx.git] / src / mathed / math_support.C
index e55c9286f4ea59f58d7527ce0a6b736e6b405a5a..f857d8e753c09c41c888ff3a1fb9bdad593b0e50 100644 (file)
 #include <config.h>
 
 #include "math_support.h"
-
 #include "math_data.h"
+#include "math_inset.h"
 #include "math_mathmlstream.h"
 #include "math_parser.h"
 
 #include "debug.h"
+#include "LColor.h"
 
 #include "frontends/Painter.h"
 #include "frontends/font_metrics.h"
 #include "frontends/lyx_gui.h"
 
-#include "support/std_sstream.h"
-
 #include <map>
+#include <sstream>
+
 
+using std::string;
 using std::max;
 using std::endl;
 
@@ -333,7 +335,8 @@ named_deco_struct deco_table[] = {
 std::map<string, deco_struct> deco_list;
 
 // sort the table on startup
-struct init_deco_table {
+class init_deco_table {
+public:
        init_deco_table() {
                unsigned const n = sizeof(deco_table) / sizeof(deco_table[0]);
                for (named_deco_struct * p = deco_table; p != deco_table + n; ++p) {
@@ -455,7 +458,7 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
                                int(x + xx + 0.5), int(y + yy + 0.5),
                                int(x + x2 + 0.5), int(y + y2 + 0.5),
                                LColor::math);
-               }       else {
+               } else {
                        int xp[32];
                        int yp[32];
                        int const n = int(d[i++]);
@@ -477,14 +480,6 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
 }
 
 
-// In the future maybe we use a better fonts renderer
-void drawStr(PainterInfo & pi, LyXFont const & font,
-       int x, int y, string const & str)
-{
-       pi.pain.text(x, y, str, font);
-}
-
-
 void drawStrRed(PainterInfo & pi, int x, int y, string const & str)
 {
        LyXFont f = pi.base.font;
@@ -501,12 +496,6 @@ void drawStrBlack(PainterInfo & pi, int x, int y, string const & str)
 }
 
 
-void drawChar(PainterInfo & pi, LyXFont const & font, int x, int y, char c)
-{
-       pi.pain.text(x, y, c, font);
-}
-
-
 void math_font_max_dim(LyXFont const & font, int & asc, int & des)
 {
        asc = font_metrics::maxAscent(font);
@@ -532,8 +521,8 @@ LyXFont::FONT_SHAPE  const inh_shape  = LyXFont::INHERIT_SHAPE;
 // does not work
 fontinfo fontinfos[] = {
        // math fonts
-       {"mathnormal",    inh_family, LyXFont::MEDIUM_SERIES,
-                         LyXFont::UP_SHAPE, LColor::math},
+       {"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,
@@ -541,27 +530,29 @@ fontinfo fontinfos[] = {
        {"mathfrak",      LyXFont::EUFRAK_FAMILY, inh_series,
                          inh_shape, LColor::math},
        {"mathrm",        LyXFont::ROMAN_FAMILY, inh_series,
-                         inh_shape, LColor::math},
+                         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},
+       {"mathit",        inh_family, inh_series,
+                         LyXFont::ITALIC_SHAPE, LColor::math},
        {"cmex",          LyXFont::CMEX_FAMILY, inh_series,
-                         inh_shape, LColor::none},
+                         inh_shape, LColor::math},
        {"cmm",           LyXFont::CMM_FAMILY, inh_series,
-                         inh_shape, LColor::none},
+                         inh_shape, LColor::math},
        {"cmr",           LyXFont::CMR_FAMILY, inh_series,
-                         inh_shape, LColor::none},
+                         inh_shape, LColor::math},
        {"cmsy",          LyXFont::CMSY_FAMILY, inh_series,
-                         inh_shape, LColor::none},
+                         inh_shape, LColor::math},
        {"eufrak",        LyXFont::EUFRAK_FAMILY, inh_series,
-                         inh_shape, LColor::none},
+                         inh_shape, LColor::math},
        {"msa",           LyXFont::MSA_FAMILY, inh_series,
-                         inh_shape, LColor::none},
+                         inh_shape, LColor::math},
        {"msb",           LyXFont::MSB_FAMILY, inh_series,
-                         inh_shape, LColor::none},
+                         inh_shape, LColor::math},
        {"wasy",          LyXFont::WASY_FAMILY, inh_series,
                          inh_shape, LColor::none},
 
@@ -577,7 +568,7 @@ fontinfo fontinfos[] = {
        {"textnormal",    inh_family, inh_series,
                          LyXFont::UP_SHAPE, LColor::foreground},
        {"textrm",        LyXFont::ROMAN_FAMILY,
-                         inh_series,LyXFont::UP_SHAPE,LColor::foreground},
+                         inh_series, LyXFont::UP_SHAPE,LColor::foreground},
        {"textsc",        inh_family, inh_series,
                          LyXFont::SMALLCAPS_SHAPE, LColor::foreground},
        {"textsf",        LyXFont::SANS_FAMILY, inh_series,
@@ -595,19 +586,15 @@ fontinfo fontinfos[] = {
 
        // LyX internal usage
        {"lyxtex",        inh_family, inh_series,
-                         inh_shape, LColor::latex},
-       {"lyxert",        LyXFont::TYPEWRITER_FAMILY, inh_series,
-                         inh_shape, LColor::latex},
+                         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},
-       {"lyxitsymbol",   LyXFont::SYMBOL_FAMILY, inh_series,
-                    LyXFont::ITALIC_SHAPE, LColor::math},
        {"lyxblacktext",  LyXFont::ROMAN_FAMILY, LyXFont::MEDIUM_SERIES,
-                    LyXFont::UP_SHAPE, LColor::foreground},
+                         LyXFont::UP_SHAPE, LColor::foreground},
        {"lyxnochange",   inh_family, inh_series,
-                    inh_shape, LColor::foreground},
+                         inh_shape, LColor::foreground},
        {"lyxfakebb",     LyXFont::TYPEWRITER_FAMILY, LyXFont::BOLD_SERIES,
                          LyXFont::UP_SHAPE, LColor::math},
        {"lyxfakecal",    LyXFont::SANS_FAMILY, LyXFont::MEDIUM_SERIES,
@@ -697,7 +684,7 @@ string asString(MathArray const & ar)
        std::ostringstream os;
        WriteStream ws(os);
        ws << ar;
-       return STRCONV(os.str());
+       return os.str();
 }
 
 
@@ -705,3 +692,21 @@ void asArray(string const & str, MathArray & ar)
 {
        mathed_parse_cell(ar, str);
 }
+
+
+string asString(MathInset const & inset)
+{
+       std::ostringstream os;
+       WriteStream ws(os);
+       inset.write(ws);
+       return os.str();
+}
+
+
+string asString(MathAtom const & at)
+{
+       std::ostringstream os;
+       WriteStream ws(os);
+       at->write(ws);
+       return os.str();
+}