]> git.lyx.org Git - features.git/blobdiff - src/mathed/support.C
write \mathrm{x}\mathrm{y} as \mathrm{xy} again
[features.git] / src / mathed / support.C
index 9cb0cd114e5775116baad1b792ea3ce3d434954a..bf19f55d65b854686ee2710f10b090ce4e2002e4 100644 (file)
@@ -7,6 +7,7 @@
 #include "FontLoader.h"
 #include "font.h"
 #include "math_defs.h"
+#include "math_inset.h"
 #include "math_parser.h"
 #include "Painter.h"
 #include "debug.h"
@@ -188,11 +189,13 @@ LyXFont const & whichFontBase(MathTextCodes type)
 }
 
 
-LyXFont whichFont(MathTextCodes type, MathStyles size)
+LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size)
 {
        LyXFont f = whichFontBase(type);
+       // use actual size
+       f.setSize(size.font.size());
 
-       switch (size) {
+       switch (size.style) {
        case LM_ST_DISPLAY:
                if (type == LM_TC_BOLDSYMB || type == LM_TC_CMEX) {
                        f.incSize();
@@ -215,7 +218,7 @@ LyXFont whichFont(MathTextCodes type, MathStyles size)
                break;
 
        default:
-               lyxerr << "Math Error: wrong font size: " << size << endl;
+               lyxerr << "Math Error: wrong font size: " << size.style << endl;
                break;
        }
 
@@ -235,8 +238,7 @@ bool math_font_available(MathTextCodes type)
 {
        if (!font_available_initialized[type]) {
                font_available_initialized[type] = true;
-               font_available[type] =
-                       fontloader.available(whichFontBase(type));
+               font_available[type] = fontloader.available(whichFontBase(type));
        }
        return font_available[type];
 }
@@ -505,8 +507,8 @@ deco_struct const * search_deco(string const & name)
 } // namespace anon
 
 
-void mathed_char_dim(MathTextCodes type, MathStyles size, unsigned char c,
-       int & asc, int & des, int & wid)
+void mathed_char_dim(MathTextCodes type, MathMetricsInfo const & size,
+       unsigned char c, int & asc, int & des, int & wid)
 {
        LyXFont const font = whichFont(type, size);
        des = lyxfont::descent(c, font);
@@ -515,8 +517,8 @@ void mathed_char_dim(MathTextCodes type, MathStyles size, unsigned char c,
 }
 
 
-int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c,
-       int & asc, int & des)
+int mathed_char_height(MathTextCodes type, MathMetricsInfo const & size,
+       unsigned char c, int & asc, int & des)
 {
        LyXFont const font = whichFont(type, size);
        des = lyxfont::descent(c, font);
@@ -525,7 +527,8 @@ int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c,
 }
 
 
-int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c)
+int mathed_char_height(MathTextCodes type, MathMetricsInfo const & size,
+       unsigned char c)
 {
        int asc;
        int des;
@@ -533,21 +536,24 @@ int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c)
 }
 
 
-int mathed_char_ascent(MathTextCodes type, MathStyles size, unsigned char c)
+int mathed_char_ascent(MathTextCodes type, MathMetricsInfo const & size,
+       unsigned char c)
 {
        LyXFont const font = whichFont(type, size);
        return lyxfont::ascent(c, font);
 }
 
 
-int mathed_char_descent(MathTextCodes type, MathStyles size, unsigned char c)
+int mathed_char_descent(MathTextCodes type, MathMetricsInfo const & size,
+       unsigned char c)
 {
        LyXFont const font = whichFont(type, size);
        return lyxfont::descent(c, font);
 }
 
 
-int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c)
+int mathed_char_width(MathTextCodes type, MathMetricsInfo const & size,
+       unsigned char c)
 {
        LyXFont const font = whichFont(type, size);
        if (isBinaryOp(c, type))
@@ -557,16 +563,16 @@ int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c)
 }
 
 
-void mathed_string_dim(MathTextCodes type, MathStyles size, string const & s,
-                        int & asc, int & des, int & wid)
+void mathed_string_dim(MathTextCodes type, MathMetricsInfo const & size,
+       string const & s, int & asc, int & des, int & wid)
 {
        mathed_string_height(type, size, s, asc, des);
        wid = mathed_string_width(type, size, s);
 }
 
 
-int mathed_string_height(MathTextCodes type, MathStyles size, string const & s,
-                        int & asc, int & des)
+int mathed_string_height(MathTextCodes type, MathMetricsInfo const & size,
+       string const & s, int & asc, int & des)
 {
        LyXFont const font = whichFont(type, size);
        asc = des = 0;
@@ -578,12 +584,36 @@ int mathed_string_height(MathTextCodes type, MathStyles size, string const & s,
 }
 
 
-int mathed_string_width(MathTextCodes type, MathStyles size, string const & s)
+int mathed_string_width(MathTextCodes type, MathMetricsInfo const & size,
+       string const & s)
 {
        return lyxfont::width(s, whichFont(type, size));
 }
 
 
+int mathed_string_ascent(MathTextCodes type, MathMetricsInfo const & size,
+       string const & s)
+{
+       LyXFont const font = whichFont(type, size);
+       int asc = 0;
+       for (string::const_iterator it = s.begin(); it != s.end(); ++it)
+               asc = max(asc, lyxfont::ascent(*it, font));
+       return asc;
+}
+
+
+int mathed_string_descent(MathTextCodes type, MathMetricsInfo const & size,
+       string const & s)
+{
+       LyXFont const font = whichFont(type, size);
+       int des = 0;
+       for (string::const_iterator it = s.begin(); it != s.end(); ++it)
+               des = max(des, lyxfont::descent(*it, font));
+       return des;
+}
+
+
+
 void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
        const string & name)
 {
@@ -653,15 +683,15 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
 
 
 // In the future maybe we use a better fonts renderer
-void drawStr(Painter & pain, MathTextCodes type, MathStyles siz,
+void drawStr(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
        int x, int y, string const & s)
 {
        pain.text(x, y, s, whichFont(type, siz));
 }
 
 
-void drawChar
-       (Painter & pain, MathTextCodes type, MathStyles siz, int x, int y, char c)
+void drawChar(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
+       int x, int y, char c)
 {
        string s;
        if (isBinaryOp(c, type))
@@ -674,30 +704,29 @@ void drawChar
 
 
 // decrease math size for super- and subscripts
-MathStyles smallerStyleScript(MathStyles st)
+void smallerStyleScript(MathMetricsInfo & st)
 {
-       switch (st) {
+       switch (st.style) {
                case LM_ST_DISPLAY:
-               case LM_ST_TEXT:    st = LM_ST_SCRIPT; break;
-               default:            st = LM_ST_SCRIPTSCRIPT;
+               case LM_ST_TEXT:    st.style = LM_ST_SCRIPT; break;
+               default:            st.style = LM_ST_SCRIPTSCRIPT;
        }
-       return st;
 }
 
 
 // decrease math size for fractions
-MathStyles smallerStyleFrac(MathStyles st)
+void smallerStyleFrac(MathMetricsInfo & st)
 {
-       switch (st) {
-               case LM_ST_DISPLAY: st = LM_ST_TEXT; break;
-               case LM_ST_TEXT:    st = LM_ST_SCRIPT; break;
-               default:            st = LM_ST_SCRIPTSCRIPT;
+       switch (st.style) {
+               case LM_ST_DISPLAY: st.style = LM_ST_TEXT; break;
+               case LM_ST_TEXT:    st.style = LM_ST_SCRIPT; break;
+               default:            st.style = LM_ST_SCRIPTSCRIPT;
        }
-       return st;
 }
 
 
-void math_font_max_dim(MathTextCodes code, MathStyles siz, int & asc, int & des)
+void math_font_max_dim(MathTextCodes code, MathMetricsInfo const & siz,
+       int & asc, int & des)
 {
        LyXFont font = whichFont(code, siz);
        asc = lyxfont::maxAscent(font);
@@ -708,3 +737,22 @@ void math_font_max_dim(MathTextCodes code, MathStyles siz, int & asc, int & des)
 char const * latex_mathspace[] = {
        "!", ",", ":", ";", "quad", "qquad"
 };
+
+
+char const * math_font_name(MathTextCodes code)
+{
+       static char const * theFontNames[] = {
+               "mathrm",
+               "mathcal",
+               "mathbf",
+               "mathbb",
+               "mathsf",
+               "mathtt",
+               "mathit",
+               "textrm"
+       };
+
+       if (code >= LM_TC_RM && code <= LM_TC_TEXTRM) 
+               return theFontNames[code - LM_TC_RM];
+       return 0;
+}