* math_hash.C: Use std::map instead of faking it
- * symbol_def.C: remove unneded symbol definitions
+ * symbol_def.h: remove unneeded symbol definitions
+
+ * support.C: use the decorations' name for drawing
2001-09-02 Dekel Tsur <dekelts@tau.ac.il>
#endif
#include "math_binominset.h"
-#include "math_parser.h"
#include "support.h"
#include "support/LOstream.h"
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
- mathed_draw_deco(pain, x, y - ascent_,
- dw(), height(), in_word_set("("));
- mathed_draw_deco(pain, x + width() - dw(), y - ascent_,
- dw(), height(), in_word_set(")"));
+ mathed_draw_deco(pain, x, y - ascent_, dw(), height(), "(");
+ mathed_draw_deco(pain, x + width() - dw(), y - ascent_, dw(), height(), ")");
}
using std::ostream;
-MathDecorationInset::MathDecorationInset(latexkeys const * key)
- : MathNestInset(1), key_(key)
-{
-}
+MathDecorationInset::MathDecorationInset(string const & name)
+ : MathNestInset(1), name_(name)
+{}
MathInset * MathDecorationInset::clone() const
bool MathDecorationInset::upper() const
{
- return key_->id != LM_underline && key_->id != LM_underbrace;
+ return name_ != "underline" && name_ != "underbrace";
}
bool MathDecorationInset::protect() const
{
return
- key_->name == "overbrace" ||
- key_->name == "underbrace" ||
- key_->name == "overleftarrow" ||
- key_->name == "overrightarrow";
+ name_ == "overbrace" ||
+ name_ == "underbrace" ||
+ name_ == "overleftarrow" ||
+ name_ == "overrightarrow";
}
dy_ = descent_ + 1;
descent_ += dh_ + 2;
}
-
- if (key_->id == LM_not) {
- ascent_ += dh_;
- descent_ += dh_;
- dh_ = height();
- dy_ = - ascent_;
- }
}
+
void MathDecorationInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(x);
xcell(0).draw(pain, x, y);
- mathed_draw_deco(pain, x, y + dy_, width_, dh_, key_);
+ mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
}
{
if (fragile && protect())
os << "\\protect";
- os << '\\' << key_->name;
-
- if (key_->id == LM_not)
- os << ' ';
- else
- os << '{';
-
+ os << '\\' << name_ << '{';
cell(0).write(os, fragile);
-
- if (key_->id != LM_not)
- os << '}';
+ os << '}';
}
void MathDecorationInset::writeNormal(ostream & os) const
{
- os << "[" << key_->name << " ";
+ os << "[" << name_ << " ";
cell(0).writeNormal(os);
os << "] ";
}
#define MATH_DECORATIONINSET_H
#include "math_nestinset.h"
+#include "LString.h"
#ifdef __GNUG__
#pragma interface
\author Alejandro Aguilar Sierra
*/
-struct latexkeys;
-
class MathDecorationInset : public MathNestInset {
public:
///
- explicit MathDecorationInset(latexkeys const *);
+ explicit MathDecorationInset(string const & name);
///
MathInset * clone() const;
///
bool protect() const;
///
- latexkeys const * key_;
+ string const name_;
/// height cache of deco
mutable int dh_;
/// vertical offset cache of deco
int const w = dw();
int const b = y - ascent_ - 2;
xcell(0).draw(pain, x + w + 2, y);
- mathed_draw_deco(pain, x + 1, b, w, height() + 4, left_);
- mathed_draw_deco(pain, x + width() - w - 1, b, w, height() + 4, right_);
+ mathed_draw_deco(pain, x + 1, b, w, height() + 4, left_->name);
+ mathed_draw_deco(pain, x + width() - w - 1, b, w, height() + 4, right_->name);
}
#include "math_dotsinset.h"
#include "mathed/support.h"
-#include "mathed/math_parser.h"
#include "support/LOstream.h"
using std::ostream;
-MathDotsInset::MathDotsInset(latexkeys const * key)
- : key_(key)
+MathDotsInset::MathDotsInset(string const & name)
+ : name_(name)
{}
void MathDotsInset::draw(Painter & pain, int x, int y) const
{
- mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_);
- if (key_->id == LM_vdots || key_->id == LM_ddots)
+ mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, name_);
+ char const c = name_[0];
+ if (c == 'v' || c == 'd')
++x;
- if (key_->id != LM_vdots)
+ if (c != 'v')
--y;
- mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_);
+ mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, name_);
}
{
size(st);
mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_);
- switch (key_->id) {
- case LM_ldots: dh_ = 0; break;
- case LM_cdots: dh_ = ascent_ / 2; break;
- case LM_vdots: width_ /= 2;
- case LM_ddots: dh_ = ascent_; break;
+ switch (name_[0]) {
+ case 'l': dh_ = 0; break;
+ case 'c': dh_ = ascent_ / 2; break;
+ case 'v': width_ /= 2;
+ case 'd': dh_ = ascent_; break;
}
}
void MathDotsInset::write(ostream & os, bool /* fragile */) const
{
- os << '\\' << key_->name << ' ';
+ os << '\\' << name_ << ' ';
}
void MathDotsInset::writeNormal(ostream & os) const
{
- os << "[" << key_->name << "] ";
+ os << "[" << name_ << "] ";
}
#define MATH_DOTSINSET_H
#include "math_diminset.h"
-#include "math_defs.h"
+#include "LString.h"
#ifdef __GNUG__
#pragma interface
#endif
-struct latexkeys;
-
/// The different kinds of ellipsis
class MathDotsInset : public MathDimInset {
public:
///
- explicit MathDotsInset(latexkeys const *);
+ explicit MathDotsInset(string const &);
///
MathInset * clone() const;
///
/// cache for the thing's heigth
mutable int dh_;
///
- latexkeys const * key_;
+ string const name_;
};
#endif
case LM_TK_ROOT:
return new MathRootInset;
case LM_TK_DECORATION:
- return new MathDecorationInset(l);
+ return new MathDecorationInset(l->name);
case LM_TK_SPACE:
return new MathSpaceInset(l->id);
case LM_TK_DOTS:
- return new MathDotsInset(l);
+ return new MathDotsInset(l->name);
}
return new MathFuncInset(l->name);
}
#include "support/lyxfunctional.h"
#include <map>
-#include <algorithm>
namespace {
{"\\", LM_TK_NEWLINE, static_cast<unsigned>(-1)}, // -1 needed in mathed_parse_lines!
{"]", LM_TK_END, LM_OT_EQUATION},
{"_", LM_TK_SPECIAL, '_'},
- {"acute", LM_TK_DECORATION, LM_acute},
+ {"acute", LM_TK_DECORATION, 0},
{"arccos", LM_TK_FUNC, 0},
{"arcsin", LM_TK_FUNC, 0},
{"arctan", LM_TK_FUNC, 0},
{"arg", LM_TK_FUNC, 0},
{"atop", LM_TK_ATOP, 0},
{"backslash", LM_TK_SPECIAL, '\\'},
- {"bar", LM_TK_DECORATION, LM_bar},
+ {"bar", LM_TK_DECORATION, 0},
{"begin", LM_TK_BEGIN, 0},
{"binom", LM_TK_BINOM, 0},
{"bmod", LM_TK_FUNC, 0},
- {"breve", LM_TK_DECORATION, LM_breve},
+ {"breve", LM_TK_DECORATION, 0},
{"cal", LM_TK_OLDFONT, LM_TC_CAL},
- {"cdots", LM_TK_DOTS, LM_cdots},
- {"check", LM_TK_DECORATION, LM_check},
+ {"cdots", LM_TK_DOTS, 0},
+ {"check", LM_TK_DECORATION, 0},
{"choose", LM_TK_CHOOSE, 0},
{"cos", LM_TK_FUNC, 0},
{"cosh", LM_TK_FUNC, 0},
{"cot", LM_TK_FUNC, 0},
{"coth", LM_TK_FUNC, 0},
{"csc", LM_TK_FUNC, 0},
- {"ddot", LM_TK_DECORATION, LM_ddot},
- {"ddots", LM_TK_DOTS, LM_ddots},
+ {"ddot", LM_TK_DECORATION, 0},
+ {"ddots", LM_TK_DOTS, 0},
{"deg", LM_TK_FUNC, 0},
{"det", LM_TK_FUNCLIM, 0},
{"dim", LM_TK_FUNC, 0},
//{"displaystyle", LM_TK_STY, LM_ST_DISPLAY},
- {"dot", LM_TK_DECORATION, LM_dot},
+ {"dot", LM_TK_DECORATION, 0},
{"end", LM_TK_END, 0},
{"exp", LM_TK_FUNC, 0},
{"frac", LM_TK_FRAC, 0},
{"gcd", LM_TK_FUNCLIM, 0},
- {"grave", LM_TK_DECORATION, LM_grave},
- {"hat", LM_TK_DECORATION, LM_hat},
+ {"grave", LM_TK_DECORATION, 0},
+ {"hat", LM_TK_DECORATION, 0},
{"hom", LM_TK_FUNC, 0},
{"inf", LM_TK_FUNCLIM, 0},
{"ker", LM_TK_FUNC, 0},
{"kern", LM_TK_KERN, 0},
{"label", LM_TK_LABEL, 0},
- {"ldots", LM_TK_DOTS, LM_ldots},
+ {"ldots", LM_TK_DOTS, 0},
{"left", LM_TK_LEFT, 0},
{"lg", LM_TK_FUNC, 0},
{"lim", LM_TK_FUNCLIM, 0},
{"newcommand", LM_TK_NEWCOMMAND, 0 },
{"nolimits", LM_TK_LIMIT, static_cast<unsigned>(-1)},
{"nonumber", LM_TK_NONUM, 0},
- {"not", LM_TK_NOT, LM_not},
+ {"not", LM_TK_NOT, 0},
{"over", LM_TK_OVER, 0},
- {"overbrace", LM_TK_DECORATION, LM_overbrace},
- {"overleftarrow", LM_TK_DECORATION, LM_overleftarrow},
- {"overline", LM_TK_DECORATION, LM_overline},
- {"overrightarrow", LM_TK_DECORATION, LM_overightarrow},
+ {"overbrace", LM_TK_DECORATION, 0},
+ {"overleftarrow", LM_TK_DECORATION, 0},
+ {"overline", LM_TK_DECORATION, 0},
+ {"overrightarrow", LM_TK_DECORATION, 0},
{"protect", LM_TK_PROTECT, 0},
{"qquad", LM_TK_SPACE, 5},
{"quad", LM_TK_SPACE, 4},
{"tanh", LM_TK_FUNC, 0},
{"textrm", LM_TK_FONT, LM_TC_TEXTRM},
//{"textstyle", LM_TK_STY, LM_ST_TEXT},
- {"tilde", LM_TK_DECORATION, LM_tilde},
- {"underbrace", LM_TK_DECORATION, LM_underbrace},
- {"underline", LM_TK_DECORATION, LM_underline},
- {"vdots", LM_TK_DOTS, LM_vdots},
- {"vec", LM_TK_DECORATION, LM_vec},
- {"widehat", LM_TK_DECORATION, LM_widehat},
- {"widetilde", LM_TK_DECORATION, LM_widetilde},
+ {"tilde", LM_TK_DECORATION, 0},
+ {"underbrace", LM_TK_DECORATION, 0},
+ {"underline", LM_TK_DECORATION, 0},
+ {"vdots", LM_TK_DOTS, 0},
+ {"vec", LM_TK_DECORATION, 0},
+ {"widehat", LM_TK_DECORATION, 0},
+ {"widetilde", LM_TK_DECORATION, 0},
{"{", LM_TK_SPECIAL, '{'},
{"|", LM_TK_UNDEF, '|'},
{"}", LM_TK_SPECIAL, '}'},
#pragma interface
#endif
-#include "symbol_def.h"
#include "xarray.h"
/** Abstract base class for all math objects.
#include "math_diminset.h"
-struct latexkeys;
-
// \\not
class MathNotInset : public MathDimInset {
#endif
#include "LString.h"
-
#include "math_defs.h"
-#include "symbol_def.h"
class MathMatrixInset;
class MathMacroTemplate;
#define MATH_ROOT_H
#include "math_nestinset.h"
-#include "symbol_def.h"
#ifdef __GNUG__
#pragma interface
#include <config.h>
-#include <algorithm>
+#include <map>
#include "mathed/support.h"
#include "lyxfont.h"
#include "Painter.h"
#include "debug.h"
-using std::sort;
-using std::lower_bound;
using std::endl;
using std::max;
struct deco_struct {
- int code;
float const * data;
int angle;
};
-deco_struct deco_table[] = {
- // Decorations
- { LM_widehat, &angle[0], 3 },
- { LM_widetilde, &tilde[0], 0 },
- { LM_underline, &hline[0], 0 },
- { LM_overline, &hline[0], 0 },
- { LM_underbrace, &brace[0], 1 },
- { LM_overbrace, &brace[0], 3 },
- { LM_overleftarrow, &arrow[0], 1 },
- { LM_overightarrow, &arrow[0], 3 },
-
- // Delimiters
- { '(', &parenth[0], 0 },
- { ')', &parenth[0], 2 },
- { '{', &brace[0], 0 },
- { '}', &brace[0], 2 },
- { '[', &brack[0], 0 },
- { ']', &brack[0], 2 },
- { '|', &vert[0], 0 },
- { '/', &slash[0], 0 },
- { LM_Vert, &Vert[0], 0 },
- { '\\', &slash[0], 1 },
- { LM_langle, &angle[0], 0 },
- { LM_lceil, &corner[0], 0 },
- { LM_lfloor, &corner[0], 1 },
- { LM_rangle, &angle[0], 2 },
- { LM_rceil, &corner[0], 3 },
- { LM_rfloor, &corner[0], 2 },
- { LM_downarrow, &arrow[0], 2 },
- { LM_Downarrow, &Arrow[0], 2 },
- { LM_uparrow, &arrow[0], 0 },
- { LM_Uparrow, &Arrow[0], 0 },
- { LM_updownarrow, &udarrow[0], 0 },
- { LM_Updownarrow, &Udarrow[0], 0 },
-
- // Accents
- { LM_ddot, &hline2[0], 0 },
- { LM_hat, &angle[0], 3 },
- { LM_grave, &slash[0], 1 },
- { LM_acute, &slash[0], 0 },
- { LM_tilde, &tilde[0], 0 },
- { LM_bar, &hline[0], 0 },
- { LM_dot, &hlinesmall[0], 0 },
- { LM_check, &angle[0], 1 },
- { LM_breve, &parenth[0], 1 },
- { LM_vec, &arrow[0], 3 },
- { LM_not, &slash[0], 0 },
-
- // Dots
- { LM_ldots, &hline3[0], 0 },
- { LM_cdots, &hline3[0], 0 },
- { LM_vdots, &hline3[0], 1 },
- { LM_ddots, &dline3[0], 0 }
+struct named_deco_struct {
+ char const * name;
+ float const * data;
+ int angle;
};
-
-struct deco_compare {
- /// for use by sort and lower_bound
- int operator()(deco_struct const & a, deco_struct const & b) const
- {
- return a.code < b.code;
- }
+named_deco_struct deco_table[] = {
+ // Decorations
+ {"widehat", angle, 3 },
+ {"widetilde", tilde, 0 },
+ {"underline", hline, 0 },
+ {"overline", hline, 0 },
+ {"underbrace", brace, 1 },
+ {"overbrace", brace, 3 },
+ {"overleftarrow", arrow, 1 },
+ {"overightarrow", arrow, 3 },
+
+ // Delimiters
+ {"(", parenth, 0 },
+ {")", parenth, 2 },
+ {"{", brace, 0 },
+ {"}", brace, 2 },
+ {"[", brack, 0 },
+ {"]", brack, 2 },
+ {"|", vert, 0 },
+ {"/", slash, 0 },
+ {"Vert", Vert, 0 },
+ {"'", slash, 1 },
+ {"langle", angle, 0 },
+ {"lceil", corner, 0 },
+ {"lfloor", corner, 1 },
+ {"rangle", angle, 2 },
+ {"rceil", corner, 3 },
+ {"rfloor", corner, 2 },
+ {"downarrow", arrow, 2 },
+ {"Downarrow", Arrow, 2 },
+ {"uparrow", arrow, 0 },
+ {"Uparrow", Arrow, 0 },
+ {"updownarrow", udarrow, 0 },
+ {"Updownarrow", Udarrow, 0 },
+
+ // Accents
+ {"ddot", hline2, 0 },
+ {"hat", angle, 3 },
+ {"grave", slash, 1 },
+ {"acute", slash, 0 },
+ {"tilde", tilde, 0 },
+ {"bar", hline, 0 },
+ {"dot", hlinesmall, 0 },
+ {"check", angle, 1 },
+ {"breve", parenth, 1 },
+ {"vec", arrow, 3 },
+ {"not", slash, 0 },
+
+ // Dots
+ {"ldots", hline3, 0 },
+ {"cdots", hline3, 0 },
+ {"vdots", hline3, 1 },
+ {"ddots", dline3, 0 }
};
-int const deco_table_size = sizeof(deco_table) / sizeof(deco_struct);
-
+std::map<string, deco_struct> deco_list;
// sort the table on startup
struct init_deco_table {
init_deco_table() {
- std::sort(deco_table,
- deco_table + deco_table_size,
- deco_compare());
+ unsigned const n = sizeof(deco_table) / sizeof(deco_table[0]);
+ for (named_deco_struct * p = deco_table; p != deco_table + n; ++p) {
+ deco_struct d;
+ d.data = p->data;
+ d.angle = p->angle;
+ deco_list[p->name]= d;
+ }
}
};
static init_deco_table dummy;
-deco_struct const * search_deco(int code)
+deco_struct const * search_deco(string const & name)
{
- const deco_struct search_elem = { code, 0, 0 };
-
- deco_struct const * res =
- lower_bound(deco_table, deco_table + deco_table_size, search_elem,
- deco_compare());
- if (res != deco_table + deco_table_size &&
- res->code == code)
- return res;
- return 0;
+ map<string, deco_struct>::const_iterator p = deco_list.find(name);
+ return (p == deco_list.end()) ? 0 : &(p->second);
}
void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
- latexkeys const * l)
+ const string & name)
{
Matrix mt;
Matrix sqmt;
int i = 0;
- string const & name = l->name;
- int code = (name.size() > 1) ? l->id : name[0];
if (name == ".") {
pain.line(x + w/2, y, x + w/2, y + h,
return;
}
- deco_struct const * mds = search_deco(code);
+ deco_struct const * mds = search_deco(name);
if (!mds) {
lyxerr << "Deco was not found. Programming error?\n";
- lyxerr << "name: '" << name << "', code: " << code << "\n";
+ lyxerr << "name: '" << name << "\n";
return;
}
int const r = mds->angle;
float const * d = mds->data;
- if (h > 70 && (mds->code == int('(') || mds->code == int(')')))
+ if (h > 70 && (name == "(" || name == ")"))
d = parenthHigh;
mt.rotate(r);
if (r >= 2)
x += w;
+ int code;
do {
float xx;
float yy;
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, latexkeys const * l);
+ (Painter & pain, int x, int y, int w, int h, string const & name);
void mathed_string_dim(MathTextCodes type, MathStyles size, string const & s,
int & asc, int & des, int & wid);
+++ /dev/null
-// This -*- C++ -*- file was created automatically.
-// Don't change it! [asierra18jan96]
-// Why? [andre]
-
-#ifndef SYMBOL_DEF
-#define SYMBOL_DEF
-
-enum Math_Symbols_enum {
-// Accents
- LM_acute = '\'',
- LM_grave = '`',
- LM_hat = '^',
- LM_tilde = '~',
- LM_dot = '.',
- LM_bar = '-',
-
-/// Symbols that don't exist in X11 symbol font but that we fake
- LM_not = 10,
-
-// Symbols that do exist in X11 symbol font
- LM_uparrow = 0xad,
- LM_downarrow = 0xaf,
- LM_Leftrightarrow = 0xdb,
- LM_Leftarrow = 0xdc,
- LM_Uparrow = 0xdd,
- LM_Rightarrow = 0xde,
- LM_Downarrow = 0xdf,
- LM_langle = 0xe1,
- LM_lceil = 0xe9,
- LM_lfloor = 0xeb,
- LM_rangle = 0xf1,
- LM_int = 0xf2,
- LM_rceil = 0xf9,
- LM_rfloor = 0xfb,
-
-/// Symbols that don't exist in X11 symbol font
- LM_NoFont = 256,
-
-/// needed as decoration
- LM_Vert,
- LM_updownarrow,
- LM_Updownarrow,
-
-/// decorations
- LM_widehat,
- LM_widetilde,
- LM_underline,
- LM_overline,
- LM_underbrace,
- LM_overbrace,
- LM_overleftarrow,
- LM_overightarrow,
-
-/// dots
- LM_ldots,
- LM_cdots,
- LM_vdots,
- LM_ddots,
- LM_emptyset,
-
-/// Accents that don't exist in X11 symbol font
- LM_ddot,
- LM_check,
- LM_vec,
- LM_breve
-};
-
-#endif