]> git.lyx.org Git - lyx.git/commitdiff
move width_/ascent_/descent_ cache into seperate ABC.
authorAndré Pönitz <poenitz@gmx.net>
Fri, 3 Aug 2001 17:55:10 +0000 (17:55 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 3 Aug 2001 17:55:10 +0000 (17:55 +0000)
sizeof(MathInset) == 24 on IA32

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2414 a592a061-630c-0410-9148-cb99ea01b6c8

16 files changed:
src/mathed/ChangeLog
src/mathed/Makefile.am
src/mathed/formulabase.C
src/mathed/math_dotsinset.h
src/mathed/math_funcinset.C
src/mathed/math_funcinset.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_macroarg.C
src/mathed/math_macroarg.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_spaceinset.h
src/mathed/math_symbolinset.h
src/mathed/support.C
src/mathed/support.h

index fef8d59e5bf7b396298b724a83b94b7066203cb9..c83bbb342b325a54c25f973ab499e04e383f7331 100644 (file)
@@ -8,6 +8,14 @@
        *       formula*.[Ch]: seperation of the "pimpl" MathInset * into
        MathMatrixInset * and MathMacroTemplate * to save a few casts
 
+       * all over the place: everything is an inset now
+
+       * math_nestinset.[Ch]: new abstract base class for insets containing
+       other insets.
+
+       * math_diminset.[Ch]: new abstract base class for insets that need
+       the width_/ascent_/descent_ cache
+
 2001-07-25  André Pönitz  <poenitz@gmx.net>
        
        * formulabase.C: re-enable 'space enlargement' feature
index 827b50c3c8c0860b46b11317d349eb1d3eb15bf8..f81e176edb6ad9092db3650f71e2f906e3163530 100644 (file)
@@ -29,6 +29,8 @@ libmathed_la_SOURCES = \
        math_defs.h \
        math_deliminset.C \
        math_deliminset.h \
+       math_diminset.C \
+       math_diminset.h \
        math_dotsinset.C \
        math_dotsinset.h \
        math_fracinset.C \
index f5c457b8de5fdbf2d5c9b321f593162c5599e2f2..9179dfc9083d56713996a87e2f8f01f9a73f7d75 100644 (file)
@@ -121,7 +121,7 @@ InsetFormulaBase::InsetFormulaBase()
 #warning This is needed as long the math parser is not re-entrant
 #endif
        MathMacroTable::builtinMacros();
-       //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
+       lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
 }
 
 
index cf8fb21fce830bb634c50a6ad153a605d882b08d..2e0c8cb79818cf2ee7f79bfcc456fb2227ba12da 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_DOTSINSET_H
 #define MATH_DOTSINSET_H
 
-#include "math_inset.h"
+#include "math_diminset.h"
 #include "math_defs.h"
 
 #ifdef __GNUG__
@@ -12,7 +12,7 @@
 struct latexkeys;
 
 /// The different kinds of ellipsis
-class MathDotsInset : public MathInset {
+class MathDotsInset : public MathDimInset {
 public:
        ///
        explicit MathDotsInset(latexkeys const *);
index 32537b799d025edb9b49db74b99b0f36b3170289..36f83a10561379dd13f9265e1e01a62043f6e2ea 100644 (file)
@@ -15,8 +15,9 @@ extern LyXFont WhichFont(short type, int size);
 
 
 MathFuncInset::MathFuncInset(string const & nm)
-       : MathInset(nm)
-{}
+{
+       name_ = nm;
+}
 
 
 MathInset * MathFuncInset::clone() const
index 781d40ccc00219f160c73ac29a501d2fadc2fcf1..70c0ce61e65abdedf6e537ddb3d6645e4be0cb91 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_FUNCINSET_H
 #define MATH_FUNCINSET_H
 
-#include "math_inset.h"
+#include "math_diminset.h"
 #include "math_defs.h"
 
 #ifdef __GNUG__
 /**
  Functions or LaTeX names for objects that I don't know how to draw.
  */
-class MathFuncInset : public MathInset {
+class MathFuncInset : public MathDimInset {
 public:
        ///
        explicit MathFuncInset(string const & nm);
        ///
-       virtual MathInset * clone() const;
+       MathInset * clone() const;
+       ///
+       void MathFuncInset::metrics(MathStyles st);
        ///
        void draw(Painter &, int, int);
        ///
        void write(std::ostream &, bool fragile) const;
        ///
        void writeNormal(std::ostream &) const;
-       ///
-       void metrics(MathStyles st);
 };
 #endif
index 8d58533d40a47b2ecd5691de6c39263c50911720..c086bb9b504508db591b3f72d208e01b08080b8d 100644 (file)
@@ -27,32 +27,13 @@ int MathInset::workwidth;
 
 
 MathInset::MathInset(string const & name)
-       : name_(name), width_(0), ascent_(0), descent_(0),
-               size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0)
+       : name_(name), size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0)
 {}
 
 
-int MathInset::ascent() const
-{
-       return ascent_;
-}
-
-
-int MathInset::descent() const
-{
-       return descent_;
-}
-
-
-int MathInset::width() const
-{
-       return width_;
-}
-
-
 int MathInset::height() const
 {
-       return ascent_ + descent_;
+       return ascent() + descent();
 }
 
 
@@ -285,7 +266,7 @@ void MathInset::push_back(unsigned char, MathTextCodes)
 }
 
 
-void MathInset::push_back(MathInset * p)
+void MathInset::push_back(MathInset *)
 {
        lyxerr << "can't push without a cell\n";
 }
@@ -295,9 +276,9 @@ bool MathInset::covers(int x, int y) const
 {
        return
                x >= xo_ &&
-               x <= xo_ + width_ &&
-               y >= yo_ - ascent_ &&
-               y <= yo_ + descent_;
+               x <= xo_ + width() &&
+               y >= yo_ - ascent() &&
+               y <= yo_ + descent();
 }
 
 
@@ -324,3 +305,9 @@ void MathInset::code(MathTextCodes t)
 {
        code_ = t;
 }
+
+
+void MathInset::metrics(MathStyles st)
+{
+       size_ = st;
+}
index bd97f31d3375a9d0d950336ef4d9642296ad447c..b2c215d19df806509068f5b9ec726492412122c3 100644 (file)
@@ -60,13 +60,13 @@ public:
        /// appends itself with macro arguments substituted
        virtual void substitute(MathArray & array, MathMacro const & macro) const;
        /// compute the size of the object, sets ascend_, descend_ and width_
-       virtual void metrics(MathStyles st) = 0;
+       virtual void metrics(MathStyles st);
        /// 
-       virtual int ascent() const;
+       virtual int ascent() const = 0;
        ///
-       virtual int descent() const;
+       virtual int descent() const = 0;
        ///
-       virtual int width() const;
+       virtual int width() const = 0;
        ///
        virtual int height() const;
        ///
@@ -203,13 +203,7 @@ public:
 protected:
        /// usually the LaTeX name of the thingy
        string name_;
-       /// the width of this inset as computed by metrics()
-       int width_;
-       /// 
-       int ascent_;
        ///
-       int descent_;
-       /// 
        void size(MathStyles s);
        /// the used font size
        MathStyles size_;
index efd0e392e189b4324de2138fc7333e9c93a97a32..22ff523059d5dd0fa7dfeff0fb2f556b248ef6a8 100644 (file)
@@ -17,6 +17,9 @@ MathMacroArgument::MathMacroArgument(int n)
                lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
                        << n << std::endl;
        }
+       str_[0] = '#';
+       str_[1] = '0' + n;
+       str_[2] = '\0';
 }
 
 
@@ -28,18 +31,25 @@ MathInset * MathMacroArgument::clone() const
 
 void MathMacroArgument::draw(Painter & pain, int x, int y)
 {
-       char str[] = "#0";
-       str[1] += number_; 
-       drawStr(pain, LM_TC_TEX, size(), x, y, str);
+       drawStr(pain, LM_TC_TEX, size(), x, y, str_);
 }
 
 
-void MathMacroArgument::metrics(MathStyles st)
+int MathMacroArgument::ascent() const
 {
-       char str[] = "#0";
-       str[1] += number_; 
-       size_ = st;
-       mathed_string_dim(LM_TC_TEX, size(), str, ascent_, descent_, width_);
+       return mathed_char_ascent(LM_TC_TEX, size(), 'I');
+}
+
+
+int MathMacroArgument::descent() const
+{
+       return mathed_char_descent(LM_TC_TEX, size(), 'I');
+}
+
+
+int MathMacroArgument::width() const
+{
+       return mathed_string_width(LM_TC_TEX, size(), str_);
 }
 
 
index 0e2f7aa70ec5cbbf6fe586512fd8113dd8d33e36..10f92482497be95de9d4bf85cd3959899dfd0cf1 100644 (file)
@@ -18,7 +18,7 @@ public:
        ///
        MathInset * clone() const;
        ///
-       void metrics(MathStyles st);
+       //void metrics(MathStyles st);
        ///
        void draw(Painter &, int x, int baseline);
        ///
@@ -27,10 +27,18 @@ public:
        void writeNormal(std::ostream &) const;
        ///
        void substitute(MathArray & array, MathMacro const & macro) const;
+       /// 
+       int ascent() const;
+       ///
+       int descent() const;
+       ///
+       int width() const;
 
 private:
        /// A number between 1 and 9
        int number_;
+       ///
+       char str_[3];
 };
 
 #endif
index aed935a19fa9d88f99c600eb95d4e661796405c5..86743e483beb44abb318c05f34fb3b9689c9a5a6 100644 (file)
@@ -7,8 +7,10 @@
 
 
 MathNestInset::MathNestInset(int nargs, string const & name)
-       : MathInset(name), cells_(nargs)
-{}
+       : MathDimInset(), cells_(nargs)
+{
+       name_ = name;
+}
 
 
 int MathNestInset::nargs() const
index 114b7994de7cd42b0e296579ffbef728b6c887b3..f2f37a22aef401f8fcfd88a95f4f40fbd2a57d42 100644 (file)
@@ -5,7 +5,7 @@
 #pragma interface
 #endif
 
-#include "math_inset.h"
+#include "math_diminset.h"
 
 /** Abstract base class for all math objects that conatin nested items.
 */
@@ -13,7 +13,7 @@
 
 class LaTeXFeatures;
 
-class MathNestInset : public MathInset {
+class MathNestInset : public MathDimInset {
 public: 
        ///
        explicit MathNestInset(int na = 0, string const & nm = string());
index 10c72e3ff1681c72ee3d0506b90a8666b354605f..b6c0f525c173f9e2401d008d0f731c1f44f6434d 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_SPACEINSET_H
 #define MATH_SPACEINSET_H
 
-#include "math_inset.h"
+#include "math_diminset.h"
 #include "math_defs.h"
 
 #ifdef __GNUG__
@@ -10,7 +10,7 @@
 #endif
 
 /// Smart spaces
-class MathSpaceInset : public MathInset {
+class MathSpaceInset : public MathDimInset {
 public:
        ///
        explicit MathSpaceInset(int sp);
index 823fdf65718c15e142627d24b21e052a43d41292..88a3414bac0f2188cd6675adc7ee9236ff927768 100644 (file)
@@ -2,12 +2,12 @@
 #ifndef MATH_SYMBOLINSET_H
 #define MATH_SYMBOLINSET_H
 
-#include "math_inset.h"
+#include "math_diminset.h"
 
 struct latexkeys;
 
 /// big operators
-class MathSymbolInset : public MathInset {
+class MathSymbolInset : public MathDimInset {
 public:
        ///
        explicit MathSymbolInset(latexkeys const *);
@@ -23,6 +23,7 @@ public:
        void draw(Painter &, int, int);
        ///
        bool isScriptable() const { return true; }
+
 private:
        ///
        latexkeys const * sym_;
index a0de5d315408c0f02decaf723802fc517e75c7ed..b006164ee179dc9e2c6aacefe7b48a3027b2df57 100644 (file)
@@ -513,7 +513,7 @@ static init_deco_table idt;
 
 } // namespace anon
 
-void mathed_char_dim (MathTextCodes type, MathStyles size, unsigned char c,
+void mathed_char_dim(MathTextCodes type, MathStyles size, unsigned char c,
        int & asc, int & des, int & wid)
 {
        LyXFont const font = WhichFont(type, size);
@@ -532,6 +532,27 @@ int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c,
 }
 
 
+int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c)
+{
+       int asc;
+       int des;
+       return mathed_char_height(type, size, c, asc, des);
+}
+
+int mathed_char_ascent(MathTextCodes type, MathStyles 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)
+{
+       LyXFont const font = WhichFont(type, size);
+       return lyxfont::descent(c, font);
+}
+
+
+
 int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c)
 {
        if (MathIsBinary(type)) {
index 75963dd38ff46978bb2352ab575f13980b4e0ce4..73a79643f1ae6968f14366b58e2e3f1fadf20b80 100644 (file)
@@ -15,9 +15,11 @@ extern char const * latex_mathspace[];
 
 int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c,
        int & asc, int & des);
-int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c);
 void mathed_char_dim(MathTextCodes type, MathStyles size, unsigned char c,
        int & asc, int & des, int & wid);
+int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c);
+int mathed_char_ascent(MathTextCodes type, MathStyles size, unsigned char c);
+int mathed_char_descent(MathTextCodes type, MathStyles size, unsigned char c);
 
 void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, int code);
 
@@ -25,7 +27,10 @@ void mathed_string_dim(MathTextCodes type, MathStyles size, string const & s,
   int & asc, int & des, int & wid);
 int mathed_string_height(MathTextCodes type, MathStyles size, string const & s,
   int & asc, int & des);
+
 int mathed_string_width(MathTextCodes type, MathStyles size, string const & s);
+int mathed_string_ascent(MathTextCodes type, MathStyles size, string const & s);
+int mathed_string_descent(MathTextCodes type, MathStyles size, string const & s);
 
 bool MathIsInset(MathTextCodes x);
 bool MathIsAlphaFont(MathTextCodes x);