]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_support.C
rename commandtags.h to lfuns.h and renumber/cleanup. Rebuild the tree !
[lyx.git] / src / mathed / math_support.C
index 3cc23305b809115f17410d614d32a9741d61c077..ee036fe9ef48fe5b657039e92d7b5c38d3545d84 100644 (file)
@@ -1,21 +1,21 @@
-#include <config.h>
 
-#include <map>
+#include <config.h>
 
 #include "math_support.h"
 #include "lyxfont.h"
 #include "math_cursor.h"
-#include "math_defs.h"
 #include "math_inset.h"
 #include "math_parser.h"
+#include "math_metricsinfo.h"
 #include "frontends/Painter.h"
 #include "frontends/font_metrics.h"
-#include "frontends/font_loader.h"
+#include "frontends/lyx_gui.h"
 #include "debug.h"
-#include "commandtags.h"
+#include "lfuns.h"
+#include "dimension.h"
+
+#include <map>
 
-using std::map;
-using std::endl;
 using std::max;
 
 
@@ -302,10 +302,10 @@ named_deco_struct deco_table[] = {
        {"check",          angle,      1 },
        {"breve",          parenth,    1 },
        {"vec",            arrow,      3 },
-       {"not",            slash,      0 },
        {"mathring",       ring,       0 },
 
        // Dots
+       {"dots",           hline3,     0 },
        {"ldots",          hline3,     0 },
        {"cdots",          hline3,     0 },
        {"vdots",          hline3,     1 },
@@ -318,7 +318,7 @@ named_deco_struct deco_table[] = {
 };
 
 
-map<string, deco_struct> deco_list;
+std::map<string, deco_struct> deco_list;
 
 // sort the table on startup
 struct init_deco_table {
@@ -338,7 +338,7 @@ static init_deco_table dummy;
 
 deco_struct const * search_deco(string const & name)
 {
-       map<string, deco_struct>::const_iterator p = deco_list.find(name);
+       std::map<string, deco_struct>::const_iterator p = deco_list.find(name);
        return (p == deco_list.end()) ? 0 : &(p->second);
 }
 
@@ -346,12 +346,11 @@ deco_struct const * search_deco(string const & name)
 } // namespace anon
 
 
-void mathed_char_dim(LyXFont const & font,
-       unsigned char c, int & asc, int & des, int & wid)
+void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim)
 {
-       des = font_metrics::descent(c, font);
-       asc = font_metrics::ascent(c, font);
-       wid = mathed_char_width(font, c);
+       dim.d = font_metrics::descent(c, font);
+       dim.a = font_metrics::ascent(c, font);
+       dim.w = mathed_char_width(font, c);
 }
 
 
@@ -373,15 +372,20 @@ int mathed_char_width(LyXFont const & font, unsigned char c)
 }
 
 
-void mathed_string_dim(LyXFont const & font,
-       string const & s, int & asc, int & des, int & wid)
+void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
 {
-       asc = des = 0;
+#if 1
+       dim.a = 0;
+       dim.d = 0;
        for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
-               des = max(des, font_metrics::descent(*it, font));
-               asc = max(asc, font_metrics::ascent(*it, font));
+               dim.a = max(dim.a, font_metrics::ascent(*it, font));
+               dim.d = max(dim.d, font_metrics::descent(*it, font));
        }
-       wid = font_metrics::width(s, font);
+#else
+       dim.a = font_metrics::maxAscent(font);
+       dim.d = font_metrics::maxDescent(font);
+#endif
+       dim.w = font_metrics::width(s, font);
 }
 
 
@@ -391,25 +395,6 @@ int mathed_string_width(LyXFont const & font, string const & s)
 }
 
 
-int mathed_string_ascent(LyXFont const & font, string const & s)
-{
-       int asc = 0;
-       for (string::const_iterator it = s.begin(); it != s.end(); ++it)
-               asc = max(asc, font_metrics::ascent(*it, font));
-       return asc;
-}
-
-
-int mathed_string_descent(LyXFont const & font, string const & s)
-{
-       int des = 0;
-       for (string::const_iterator it = s.begin(); it != s.end(); ++it)
-               des = max(des, font_metrics::descent(*it, font));
-       return des;
-}
-
-
-
 void mathed_draw_deco(MathPainterInfo & pi, int x, int y, int w, int h,
        const string & name)
 {
@@ -455,8 +440,8 @@ void mathed_draw_deco(MathPainterInfo & pi, int x, int y, int w, int h,
                                mt.transform(xx, yy);
                        mt.transform(x2, y2);
                        pi.pain.line(
-                               x + int(xx + 0.5), y + int(yy + 0.5),
-                               x + int(x2 + 0.5), y + int(y2 + 0.5),
+                               int(x + xx + 0.5), int(y + yy + 0.5),
+                               int(x + x2 + 0.5), int(y + y2 + 0.5),
                                LColor::math);
                }       else {
                        int xp[32];
@@ -465,14 +450,14 @@ void mathed_draw_deco(MathPainterInfo & pi, int x, int y, int w, int h,
                        for (int j = 0; j < n; ++j) {
                                double xx = d[i++];
                                double yy = d[i++];
-//          lyxerr << " " << xx << " " << yy << " ";
+//          lyxerr << ' ' << xx << ' ' << yy << ' ';
                                if (code == 4)
                                        sqmt.transform(xx, yy);
                                else
                                        mt.transform(xx, yy);
-                               xp[j] = x + int(xx + 0.5);
-                               yp[j] = y + int(yy + 0.5);
-                               //  lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]";
+                               xp[j] = int(x + xx + 0.5);
+                               yp[j] = int(y + yy + 0.5);
+                               //  lyxerr << "P[" << j ' ' << xx << ' ' << yy << ' ' << x << ' ' << y << ']';
                        }
                        pi.pain.lines(xp, yp, n, LColor::math);
                }
@@ -525,28 +510,6 @@ void math_font_max_dim(LyXFont const & font, int & asc, int & des)
 }
 
 
-string convertDelimToLatexName(string const & name)
-{
-       if (name == "(")
-               return name;
-       if (name == "[")
-               return name;
-       if (name == ".")
-               return name;
-       if (name == ")")
-               return name;
-       if (name == "]")
-               return name;
-       if (name == "/")
-               return name;
-       if (name == "|")
-               return name;
-       return "\\" + name + " ";
-}
-
-
-
-
 struct fontinfo {
        string cmd_;
        LyXFont::FONT_FAMILY family_;
@@ -558,24 +521,30 @@ struct fontinfo {
 
 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; 
-
+LyXFont::FONT_SHAPE  const inh_shape  = LyXFont::INHERIT_SHAPE;
 
 
+// mathnormal should be the first, otherwise the fallback further down
+// does not work
 fontinfo fontinfos[] = {
-       {"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},
+       {"mathnormal",
+               inh_family, LyXFont::MEDIUM_SERIES, LyXFont::UP_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},
-       {"mathnormal", inh_family,inh_series, LyXFont::UP_SHAPE, LColor::math},
        {"mathrm", LyXFont::ROMAN_FAMILY, inh_series, inh_shape, LColor::math},
        {"mathsf", LyXFont::SANS_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},
+       {"mathbb", LyXFont::MSB_FAMILY, inh_series, inh_shape, LColor::math},
+       {"mathtt", LyXFont::TYPEWRITER_FAMILY, inh_series, inh_shape, LColor::math},
+       {"cmex",   LyXFont::CMEX_FAMILY, inh_series, inh_shape, LColor::none},
+       {"cmm",    LyXFont::CMM_FAMILY, inh_series, inh_shape, LColor::none},
+       {"cmr",    LyXFont::CMR_FAMILY, inh_series, inh_shape, LColor::none},
+       {"cmsy",   LyXFont::CMSY_FAMILY, inh_series, inh_shape, LColor::none},
+       {"eufrak", LyXFont::EUFRAK_FAMILY, inh_series, inh_shape, LColor::none},
+       {"msa",    LyXFont::MSA_FAMILY, inh_series, inh_shape, LColor::none},
+       {"msb",    LyXFont::MSB_FAMILY, inh_series, inh_shape, LColor::none},
+       {"wasy",   LyXFont::WASY_FAMILY, inh_series, inh_shape, LColor::none},
+       {"text",   inh_family, inh_series, inh_shape, LColor::black},
        {"textbf", inh_family, LyXFont::BOLD_SERIES, inh_shape, LColor::black},
        {"textit", inh_family, inh_series, LyXFont::ITALIC_SHAPE, LColor::black},
        {"textmd", inh_family, LyXFont::MEDIUM_SERIES, inh_shape, LColor::black},
@@ -587,7 +556,11 @@ fontinfo fontinfos[] = {
        {"texttt", LyXFont::TYPEWRITER_FAMILY, inh_series, inh_shape, LColor::black},
        {"textup", inh_family, inh_series, LyXFont::UP_SHAPE, LColor::black},
 
+       // TIPA support
+       {"textipa",   inh_family, inh_series, inh_shape, LColor::black},
+
        {"lyxtex", inh_family, inh_series, inh_shape, LColor::latex},
+       {"lyxert", LyXFont::TYPEWRITER_FAMILY, inh_series, inh_shape, LColor::latex},
        {"lyxsymbol", LyXFont::SYMBOL_FAMILY, inh_series, inh_shape, LColor::math},
        {"lyxboldsymbol",
                LyXFont::SYMBOL_FAMILY, LyXFont::BOLD_SERIES, inh_shape, LColor::math},
@@ -606,16 +579,31 @@ fontinfo fontinfos[] = {
 };
 
 
-fontinfo * searchFont(string const & name)
+fontinfo * lookupFont(string const & name)
 {
+       //lyxerr << "searching font '" << name << "'\n";
        int const n = sizeof(fontinfos) / sizeof(fontinfo);
-       //lyxerr << "searching font '" << name << "'\n"; 
        for (int i = 0; i < n; ++i)
                if (fontinfos[i].cmd_ == name) {
-                       //lyxerr << "found '" << i << "'\n"; 
+                       //lyxerr << "found '" << i << "'\n";
                        return fontinfos + i;
                }
-       return searchFont("mathnormal");
+       return 0;
+}
+
+
+fontinfo * searchFont(string const & name)
+{
+       fontinfo * f = lookupFont(name);
+       return f ? f : fontinfos;
+       // this should be mathnormal
+       //return searchFont("mathnormal");
+}
+
+
+bool isFontName(string const & name)
+{
+       return lookupFont(name);
 }
 
 
@@ -641,16 +629,16 @@ void fakeFont(string const & orig, string const & fake)
        }
 }
 
+
 void augmentFont(LyXFont & font, string const & name)
 {
        static bool initialized = false;
        if (!initialized) {
                initialized = true;
-
                // fake fonts if necessary
-               if (!fontloader.available(getFont("mathfrak")))
+               if (!lyx_gui::font_available(getFont("mathfrak")))
                        fakeFont("mathfrak", "lyxfakefrak");
-               if (!fontloader.available(getFont("mathcal")))
+               if (!lyx_gui::font_available(getFont("mathcal")))
                        fakeFont("mathcal", "lyxfakecal");
        }
        fontinfo * info = searchFont(name);