* 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
math_defs.h \
math_deliminset.C \
math_deliminset.h \
+ math_diminset.C \
+ math_diminset.h \
math_dotsinset.C \
math_dotsinset.h \
math_fracinset.C \
#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";
}
#ifndef MATH_DOTSINSET_H
#define MATH_DOTSINSET_H
-#include "math_inset.h"
+#include "math_diminset.h"
#include "math_defs.h"
#ifdef __GNUG__
struct latexkeys;
/// The different kinds of ellipsis
-class MathDotsInset : public MathInset {
+class MathDotsInset : public MathDimInset {
public:
///
explicit MathDotsInset(latexkeys const *);
MathFuncInset::MathFuncInset(string const & nm)
- : MathInset(nm)
-{}
+{
+ name_ = nm;
+}
MathInset * MathFuncInset::clone() const
#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
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();
}
}
-void MathInset::push_back(MathInset * p)
+void MathInset::push_back(MathInset *)
{
lyxerr << "can't push without a cell\n";
}
{
return
x >= xo_ &&
- x <= xo_ + width_ &&
- y >= yo_ - ascent_ &&
- y <= yo_ + descent_;
+ x <= xo_ + width() &&
+ y >= yo_ - ascent() &&
+ y <= yo_ + descent();
}
{
code_ = t;
}
+
+
+void MathInset::metrics(MathStyles st)
+{
+ size_ = st;
+}
/// 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;
///
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_;
lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
<< n << std::endl;
}
+ str_[0] = '#';
+ str_[1] = '0' + n;
+ str_[2] = '\0';
}
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_);
}
///
MathInset * clone() const;
///
- void metrics(MathStyles st);
+ //void metrics(MathStyles st);
///
void draw(Painter &, int x, int baseline);
///
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
MathNestInset::MathNestInset(int nargs, string const & name)
- : MathInset(name), cells_(nargs)
-{}
+ : MathDimInset(), cells_(nargs)
+{
+ name_ = name;
+}
int MathNestInset::nargs() const
#pragma interface
#endif
-#include "math_inset.h"
+#include "math_diminset.h"
/** Abstract base class for all math objects that conatin nested items.
*/
class LaTeXFeatures;
-class MathNestInset : public MathInset {
+class MathNestInset : public MathDimInset {
public:
///
explicit MathNestInset(int na = 0, string const & nm = string());
#ifndef MATH_SPACEINSET_H
#define MATH_SPACEINSET_H
-#include "math_inset.h"
+#include "math_diminset.h"
#include "math_defs.h"
#ifdef __GNUG__
#endif
/// Smart spaces
-class MathSpaceInset : public MathInset {
+class MathSpaceInset : public MathDimInset {
public:
///
explicit MathSpaceInset(int sp);
#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 *);
void draw(Painter &, int, int);
///
bool isScriptable() const { return true; }
+
private:
///
latexkeys const * sym_;
} // 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);
}
+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)) {
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);
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);