]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_support.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[lyx.git] / src / mathed / math_support.C
index 3cc3cae92d1a3c7ad21dc96210638744d36ee52f..14c37c95c552540227253498569cef8c431c3af8 100644 (file)
@@ -6,6 +6,7 @@
 #include "lyxfont.h"
 #include "FontLoader.h"
 #include "font.h"
+#include "math_cursor.h"
 #include "math_defs.h"
 #include "math_inset.h"
 #include "math_parser.h"
@@ -67,8 +68,6 @@ enum MathFont {
        FONT_SYMBOL,
        FONT_SYMBOLI,
        FONT_BF,
-       FONT_BB,
-       FONT_CAL,
        FONT_TT,
        FONT_RM,
        FONT_SF,
@@ -79,17 +78,15 @@ enum MathFont {
        FONT_MSA,
        FONT_MSB,
        FONT_EUFRAK,
+       FONT_FAKEBB,
+       FONT_FAKECAL,
+       FONT_FAKEFRAK,
        FONT_NUM
 };
 
 void mathed_init_fonts()
 {
-       MathFonts = new LyXFont[FONT_NUM]; //DEC cxx cannot initialize all fonts
-       //at once (JMarc) rc
-
-       for (int i = 0 ; i < FONT_NUM ; ++i) {
-               MathFonts[i] = LyXFont(LyXFont::ALL_SANE);
-       }
+       MathFonts = new LyXFont[FONT_NUM];
 
        MathFonts[FONT_IT].setShape(LyXFont::ITALIC_SHAPE);
 
@@ -100,16 +97,8 @@ void mathed_init_fonts()
 
        MathFonts[FONT_BF].setSeries(LyXFont::BOLD_SERIES);
 
-       MathFonts[FONT_BB].setSeries(LyXFont::BOLD_SERIES);
-       MathFonts[FONT_BB].setFamily(LyXFont::TYPEWRITER_FAMILY);
-
-       MathFonts[FONT_CAL].setFamily(LyXFont::SANS_FAMILY);
-       MathFonts[FONT_CAL].setShape(LyXFont::ITALIC_SHAPE);
-
        MathFonts[FONT_TT].setFamily(LyXFont::TYPEWRITER_FAMILY);
-
        MathFonts[FONT_RM].setFamily(LyXFont::ROMAN_FAMILY);
-
        MathFonts[FONT_SF].setFamily(LyXFont::SANS_FAMILY);
 
        MathFonts[FONT_CMR].setFamily(LyXFont::CMR_FAMILY);
@@ -120,12 +109,21 @@ void mathed_init_fonts()
        MathFonts[FONT_MSB].setFamily(LyXFont::MSB_FAMILY);
        MathFonts[FONT_EUFRAK].setFamily(LyXFont::EUFRAK_FAMILY);
 
+       MathFonts[FONT_FAKEBB].setFamily(LyXFont::TYPEWRITER_FAMILY);
+       MathFonts[FONT_FAKEBB].setSeries(LyXFont::BOLD_SERIES);
+
+       MathFonts[FONT_FAKECAL].setFamily(LyXFont::SANS_FAMILY);
+       MathFonts[FONT_FAKECAL].setShape(LyXFont::ITALIC_SHAPE);
+
+       MathFonts[FONT_FAKEFRAK].setFamily(LyXFont::SANS_FAMILY);
+       MathFonts[FONT_FAKEFRAK].setSeries(LyXFont::BOLD_SERIES);
+
        for (int i = 0; i < LM_FONT_END; ++i)
                font_available_initialized[i] = false;
 }
 
 
-LyXFont const & whichFontBase(MathTextCodes type)
+LyXFont const & whichFontBaseIntern(MathTextCodes type)
 {
        if (!MathFonts)
                mathed_init_fonts();
@@ -143,20 +141,15 @@ LyXFont const & whichFontBase(MathTextCodes type)
                return MathFonts[FONT_BF];
 
        case LM_TC_BB:
-               if (math_font_available(LM_TC_MSB))
-                       return MathFonts[FONT_MSB];
-               else
-                       return MathFonts[FONT_BB];
+               return MathFonts[FONT_MSB];
 
        case LM_TC_CAL:
-               if (math_font_available(LM_TC_CMSY))
-                       return MathFonts[FONT_CMSY];
-               else
-                       return MathFonts[FONT_CAL];
+               return MathFonts[FONT_CMSY];
 
        case LM_TC_TT:
                return MathFonts[FONT_TT];
 
+       case LM_TC_BOX:
        case LM_TC_TEXTRM:
        case LM_TC_CONST:
        case LM_TC_TEX:
@@ -184,16 +177,44 @@ LyXFont const & whichFontBase(MathTextCodes type)
        case LM_TC_MSB:
                return MathFonts[FONT_MSB];
 
+       case LM_TC_EUFRAK:
+               return MathFonts[FONT_EUFRAK];
+
+       default:
+               break;
+       }
+       return MathFonts[1];
+}
+
+
+LyXFont const & whichFontBase(MathTextCodes type)
+{
+       if (!MathFonts)
+               mathed_init_fonts();
+
+       switch (type) {
+       case LM_TC_BB:
+               if (math_font_available(LM_TC_MSB))
+                       return MathFonts[FONT_MSB];
+               else
+                       return MathFonts[FONT_FAKEBB];
+
+       case LM_TC_CAL:
+               if (math_font_available(LM_TC_CMSY))
+                       return MathFonts[FONT_CMSY];
+               else
+                       return MathFonts[FONT_FAKECAL];
+
        case LM_TC_EUFRAK:
                if (math_font_available(LM_TC_EUFRAK))
                        return MathFonts[FONT_EUFRAK];
                else
-                       return MathFonts[FONT_BB];
+                       return MathFonts[FONT_FAKEFRAK];
 
        default:
                break;
        }
-       return MathFonts[1];
+       return whichFontBaseIntern(type);
 }
 
 
@@ -230,7 +251,7 @@ LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size)
                break;
        }
 
-       if (type != LM_TC_TEXTRM)
+       if (type != LM_TC_TEXTRM && type != LM_TC_BOX)
                f.setColor(LColor::math);
 
        if (type == LM_TC_TEX)
@@ -246,7 +267,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(whichFontBaseIntern(type));
        }
        return font_available[type];
 }
@@ -690,6 +711,14 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
 }
 
 
+void mathed_draw_framebox(Painter & pain, int x, int y, MathInset const * p)
+{
+       if (mathcursor && mathcursor->isInside(p))
+               pain.rectangle(x, y - p->ascent(), p->width(), p->height(),
+                       LColor::mathframe);
+}
+
+
 // In the future maybe we use a better fonts renderer
 void drawStr(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
        int x, int y, string const & s)
@@ -747,6 +776,13 @@ char const * latex_mathspace[] = {
 };
 
 
+char const * latex_mathstyle[] = {
+       "textstyle", "displaystyle", "scriptstyle", "scriptscriptstyle", 
+       "mathbf", "mathcal","mathrm","mathtt", "mathsf", "mathit",
+       "mathbb","mathfrak", "textrm", "mathnormal"
+};
+
+
 char const * math_font_name(MathTextCodes code)
 {
        static char const * theFontNames[] = {