From: André Pönitz Date: Fri, 3 Aug 2001 17:55:10 +0000 (+0000) Subject: move width_/ascent_/descent_ cache into seperate ABC. X-Git-Tag: 1.6.10~20931 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=244d75e9422f046ec150412e0e43a479f9abed90;p=lyx.git move width_/ascent_/descent_ cache into seperate ABC. sizeof(MathInset) == 24 on IA32 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2414 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index fef8d59e5b..c83bbb342b 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -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 * formulabase.C: re-enable 'space enlargement' feature diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 827b50c3c8..f81e176edb 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -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 \ diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index f5c457b8de..9179dfc908 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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"; } diff --git a/src/mathed/math_dotsinset.h b/src/mathed/math_dotsinset.h index cf8fb21fce..2e0c8cb798 100644 --- a/src/mathed/math_dotsinset.h +++ b/src/mathed/math_dotsinset.h @@ -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 *); diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C index 32537b799d..36f83a1056 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -15,8 +15,9 @@ extern LyXFont WhichFont(short type, int size); MathFuncInset::MathFuncInset(string const & nm) - : MathInset(nm) -{} +{ + name_ = nm; +} MathInset * MathFuncInset::clone() const diff --git a/src/mathed/math_funcinset.h b/src/mathed/math_funcinset.h index 781d40ccc0..70c0ce61e6 100644 --- a/src/mathed/math_funcinset.h +++ b/src/mathed/math_funcinset.h @@ -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__ @@ -12,19 +12,19 @@ /** 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 diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 8d58533d40..c086bb9b50 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -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; +} diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index bd97f31d33..b2c215d19d 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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_; diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index efd0e392e1..22ff523059 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -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_); } diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index 0e2f7aa70e..10f9248249 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -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 diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index aed935a19f..86743e483b 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -7,8 +7,10 @@ MathNestInset::MathNestInset(int nargs, string const & name) - : MathInset(name), cells_(nargs) -{} + : MathDimInset(), cells_(nargs) +{ + name_ = name; +} int MathNestInset::nargs() const diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 114b7994de..f2f37a22ae 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -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()); diff --git a/src/mathed/math_spaceinset.h b/src/mathed/math_spaceinset.h index 10c72e3ff1..b6c0f525c1 100644 --- a/src/mathed/math_spaceinset.h +++ b/src/mathed/math_spaceinset.h @@ -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); diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index 823fdf6571..88a3414bac 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -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_; diff --git a/src/mathed/support.C b/src/mathed/support.C index a0de5d3154..b006164ee1 100644 --- a/src/mathed/support.C +++ b/src/mathed/support.C @@ -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)) { diff --git a/src/mathed/support.h b/src/mathed/support.h index 75963dd38f..73a79643f1 100644 --- a/src/mathed/support.h +++ b/src/mathed/support.h @@ -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);