]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_metricsinfo.C
small up/down tweaking
[lyx.git] / src / mathed / math_metricsinfo.C
index 90d553c6f08c83299c917bd18407453bb1e9da7f..15382d952b250111bbce0b678981d6593ce8fa95 100644 (file)
@@ -1,8 +1,12 @@
+#ifdef __GNUG__
+#pragma implementation
+#endif
 
 #include <config.h>
 
 #include "math_metricsinfo.h"
 #include "math_support.h"
+#include "debug.h"
 #include "frontends/Painter.h"
 
 
@@ -16,7 +20,7 @@ MathMetricsBase::MathMetricsBase()
 
 
 MathMetricsInfo::MathMetricsInfo()
-       : view(0), fullredraw(false)
+       : fullredraw(false)
 {}
 
 
@@ -33,65 +37,53 @@ void MathPainterInfo::draw(int x, int y, char c)
 }
 
 
-
-
-MathScriptChanger::MathScriptChanger(MathMetricsBase & mb)
-       : MathChanger<MathMetricsBase>(mb)
+MathStyles smallerScriptStyle(MathStyles st)
 {
-       save_ = mb;
-       switch (mb.style) {
+       switch (st) {
                case LM_ST_DISPLAY:
                case LM_ST_TEXT:
-                       mb.style = LM_ST_SCRIPT;
-                       mb.font.decSize();
-                       mb.font.decSize();
-                       break;
+                       return LM_ST_SCRIPT;
                case LM_ST_SCRIPT:
-                       mb.style = LM_ST_SCRIPTSCRIPT;
-                       mb.font.decSize();
-               default:
-                       break;
+               case LM_ST_SCRIPTSCRIPT:
+                       return LM_ST_SCRIPTSCRIPT;
        }
+       // shut up compiler
+       lyxerr << "should not happen\n";
+       return LM_ST_DISPLAY;
 }
 
-MathScriptChanger::~MathScriptChanger()
-{
-       orig_ = save_;
-}
-
+MathScriptChanger::MathScriptChanger(MathMetricsBase & mb)
+       : MathStyleChanger(mb, smallerScriptStyle(mb.style))
+{}
 
 
 
-// decrease math size for fractions
-MathFracChanger::MathFracChanger(MathMetricsBase & mb)
-       : MathChanger<MathMetricsBase>(mb)
+MathStyles smallerFracStyle(MathStyles st)
 {
-       save_ = mb;
-       switch (mb.style) {
+       switch (st) {
                case LM_ST_DISPLAY:
-                       mb.style = LM_ST_TEXT;
-                       break;
+                       return LM_ST_TEXT;
                case LM_ST_TEXT:
-                       mb.style = LM_ST_SCRIPT;
-                       mb.font.decSize();
-                       mb.font.decSize();
-                       break;
+                       return LM_ST_SCRIPT;
                case LM_ST_SCRIPT:
-                       mb.style = LM_ST_SCRIPTSCRIPT;
-                       mb.font.decSize();
-                       break;
-               default:
-                       break;
+               case LM_ST_SCRIPTSCRIPT:
+                       return LM_ST_SCRIPTSCRIPT;
        }
+       // shut up compiler
+       lyxerr << "should not happen\n";
+       return LM_ST_DISPLAY;
 }
 
-MathFracChanger::~MathFracChanger()
-{
-       orig_ = save_;
-}
+MathFracChanger::MathFracChanger(MathMetricsBase & mb)
+       : MathStyleChanger(mb, smallerFracStyle(mb.style))
+{}
 
 
 
+MathArrayChanger::MathArrayChanger(MathMetricsBase & mb)
+       : MathStyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
+{}
+
 
 MathShapeChanger::MathShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
        : MathChanger<LyXFont, LyXFont::FONT_SHAPE>(font)
@@ -107,26 +99,24 @@ MathShapeChanger::~MathShapeChanger()
 
 
 
-
-void changeSize(LyXFont & font, int diff)
-{
-       if (diff < 0) {
-               font.decSize();
-               changeSize(font, diff + 1);
-       } else if (diff > 0) {
-               font.incSize();
-               changeSize(font, diff - 1);
-       }
-}
-
 MathStyleChanger::MathStyleChanger(MathMetricsBase & mb, MathStyles style)
        :       MathChanger<MathMetricsBase>(mb)
 {
+       static const int diff[4][4]  = { { 0, 0, -3, -5 },
+                                        { 0, 0, -3, -5 },
+                                        { 3, 3,  0, -2 },
+                                        { 5, 5,  2,  0 } };
        save_ = mb;
-       changeSize(mb.font, mb.style - style);
+       int t = diff[mb.style][style];
+       if (t > 0)
+               while (t--)
+                       mb.font.incSize();
+       else
+               while (t++)
+                       mb.font.decSize();
+       mb.style = style;
 }
 
-
 MathStyleChanger::~MathStyleChanger()
 {
        orig_ = save_;
@@ -134,11 +124,10 @@ MathStyleChanger::~MathStyleChanger()
 
 
 
-
 MathFontSetChanger::MathFontSetChanger(MathMetricsBase & mb, char const * name)
        :       MathChanger<MathMetricsBase>(mb)
 {
-       save_ = mb;     
+       save_ = mb;
        mb.fontname = name;
        augmentFont(mb.font, name);
 }
@@ -152,7 +141,7 @@ MathFontSetChanger::~MathFontSetChanger()
 MathWidthChanger::MathWidthChanger(MathMetricsBase & mb, int w)
        :       MathChanger<MathMetricsBase>(mb)
 {
-       save_ = mb;     
+       save_ = mb;
        mb.restrictwidth = true;
        mb.textwidth     = w;
 }
@@ -162,4 +151,3 @@ MathWidthChanger::~MathWidthChanger()
 {
        orig_ = save_;
 }
-