+
+2002-05-30 André Pönitz <poenitz@gmx.net>
+
+ * *.[Ch]: "fonts as inset"
+
2002-05-29 Lars Gullik Bjønnes <larsbj@birdstep.com>
* switch from SigC signals to boost::signals.
math_exintinset.h \
math_factory.C \
math_factory.h \
+ math_fontinset.C \
+ math_fontinset.h \
math_fracinset.C \
math_fracinset.h \
math_fracbase.C \
math_fracbase.h \
- math_funcinset.C \
- math_funcinset.h \
math_funcliminset.C \
math_funcliminset.h \
math_gridinset.C \
math_gridinset.h \
- math_hash.C \
math_hullinset.C \
math_hullinset.h \
math_inset.C \
int w = par_->width();
int h = par_->height();
int a = par_->ascent();
- Painter & pain = bv->painter();
+
+ MathPainterInfo pi(bv->painter());
+ pi.base.font = font;
+ pi.base.font.setColor(LColor::math);
+ pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
if (lcolor.getX11Name(LColor::mathbg)!=lcolor.getX11Name(LColor::background))
- pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
+ pi.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
if (mathcursor &&
const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
{
- mathcursor->drawSelection(pain);
- pain.rectangle(x, y - a, w, h, LColor::mathframe);
+ mathcursor->drawSelection(pi);
+ pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
}
- par_->draw(pain, x, y);
+ par_->draw(pi, x, y);
// preview stuff
#if 0
mathcursor->last();
mathcursor->stripFromLastEqualSign();
ar = mathcursor->cursor().cell();
- mathcursor->insert(MathAtom(new MathCharInset('=', LM_TC_VAR)));
+ mathcursor->insert('=');
//lyxerr << "use whole cell: " << ar << "\n";
}
#include "math_charinset.h"
#include "math_cursor.h"
#include "math_factory.h"
+#include "math_fontinset.h"
#include "math_hullinset.h"
#include "math_iterator.h"
#include "math_macrotable.h"
int first_y;
+
bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
{
if (!bv->insertInset(new_inset)) {
//lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
//lyxerr << "sizeof(MathMetricsInfo): " << sizeof(MathMetricsInfo) << "\n";
//lyxerr << "sizeof(MathCharInset): " << sizeof(MathCharInset) << "\n";
+ //lyxerr << "sizeof(LyXFont): " << sizeof(LyXFont) << "\n";
}
}
+void InsetFormulaBase::handleFont
+ (BufferView * bv, string const & arg, string const & font)
+{
+ bv->lockedInsetStoreUndo(Undo::EDIT);
+ bool sel = mathcursor->selection();
+ if (sel)
+ updateLocal(bv, true);
+ mathcursor->handleNest(new MathFontInset(font));
+ for (string::const_iterator it = arg.begin(); it != arg.end(); ++it)
+ mathcursor->insert(*it);
+ if (!sel)
+ updateLocal(bv, false);
+}
+
+
// Check if uses AMS macros
void InsetFormulaBase::validate(LaTeXFeatures &) const
{}
{
if (bv)
view_ = bv;
- MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+ MathMetricsInfo mi;
+ mi.view = view_;
+ mi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
+ mi.base.font = font_;
+ mi.base.font.setColor(LColor::math);
+ //whichFont(mi.font, LM_TC_MIN, mi);
par()->metrics(mi);
}
}
-void InsetFormulaBase::handleFont
- (BufferView * bv, string const & arg, MathTextCodes t)
-{
- if (mathcursor->selection()) {
- bv->lockedInsetStoreUndo(Undo::EDIT);
- updateLocal(bv, true);
- }
- mathcursor->handleFont(t);
- for (string::const_iterator it = arg.begin(); it != arg.end(); ++it)
- mathcursor->insert(*it);
- updateLocal(bv, false);
-}
-
-
void InsetFormulaBase::insetUnlock(BufferView * bv)
{
if (mathcursor) {
break;
// Math fonts
- case LFUN_GREEK_TOGGLE: handleFont(bv, arg, LM_TC_GREEK); break;
- case LFUN_BOLD: handleFont(bv, arg, LM_TC_BF); break;
- case LFUN_SANS: handleFont(bv, arg, LM_TC_SF); break;
- case LFUN_EMPH: handleFont(bv, arg, LM_TC_CAL); break;
- case LFUN_ROMAN: handleFont(bv, arg, LM_TC_RM); break;
- case LFUN_CODE: handleFont(bv, arg, LM_TC_TT); break;
- case LFUN_FRAK: handleFont(bv, arg, LM_TC_EUFRAK); break;
- case LFUN_ITAL: handleFont(bv, arg, LM_TC_IT); break;
- case LFUN_NOUN: handleFont(bv, arg, LM_TC_BB); break;
- case LFUN_DEFAULT: handleFont(bv, arg, LM_TC_VAR); break;
- case LFUN_FREE: handleFont(bv, arg, LM_TC_TEXTRM); break;
+ case LFUN_GREEK_TOGGLE: handleFont(bv, arg, "lyxgreek"); break;
+ case LFUN_BOLD: handleFont(bv, arg, "textbf"); break;
+ case LFUN_SANS: handleFont(bv, arg, "textsf"); break;
+ case LFUN_EMPH: handleFont(bv, arg, "mathcal"); break;
+ case LFUN_ROMAN: handleFont(bv, arg, "mathrm"); break;
+ case LFUN_CODE: handleFont(bv, arg, "texttt"); break;
+ case LFUN_FRAK: handleFont(bv, arg, "mathfrak"); break;
+ case LFUN_ITAL: handleFont(bv, arg, "mathit"); break;
+ case LFUN_NOUN: handleFont(bv, arg, "mathbb"); break;
+ case LFUN_DEFAULT: handleFont(bv, arg, "textnormal"); break;
+ case LFUN_FREE: handleFont(bv, arg, "textrm"); break;
case LFUN_GREEK:
- handleFont(bv, arg, LM_TC_GREEK1);
+ handleFont(bv, arg, "lyxgreek1");
if (arg.size())
mathcursor->interpret(arg);
break;
case LFUN_MATH_MODE:
#if 1
- handleFont(bv, arg, LM_TC_TEXTRM);
+ handleFont(bv, arg, "textrm");
#endif
#if 0
result = UNDISPATCHED;
break;
+ case LFUN_INSET_TOGGLE:
+ mathcursor->insetToggle();
+ break;
+
default:
result = UNDISPATCHED;
}
}
-void InsetFormulaBase::revealCodes(BufferView * /*bv*/) const
+void InsetFormulaBase::revealCodes(BufferView * bv) const
{
if (!mathcursor)
return;
+ bv->owner()->message(mathcursor->info());
+
#if 0
// write something to the minibuffer
// translate to latex
// formula otherwise
if (sel.find("\\newcommand") == string::npos &&
sel.find("\\def") == string::npos)
+ {
f = new InsetFormula(sel);
- else {
+ } else {
string name;
if (!mathed_parse_macro(name, sel))
return;
#pragma interface
#endif
-#include <iosfwd>
#include "insets/inset.h"
#include "frontends/mouse_state.h"
#include "lyxfont.h"
// only for getType():
#include "math_defs.h"
+#include <iosfwd>
+
class Buffer;
class BufferView;
class MathAtom;
///
void metrics(BufferView * bv = 0) const;
///
- void handleFont(BufferView * bv, string const & arg, MathTextCodes t);
+ void handleFont(BufferView * bv, string const & arg, string const & font);
///
mutable int xo_;
void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
int y, float & xx, bool /*cleared*/) const
{
- Painter & pain = bv->painter();
+ MathPainterInfo pain = MathPainterInfo(bv->painter());
LyXFont font(f);
// label
int const h = ascent(bv, font) + descent(bv, font) - 2;
// LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
- pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
- pain.rectangle(x, a, w, h, LColor::mathframe);
+ pain.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
+ pain.pain.rectangle(x, a, w, h, LColor::mathframe);
if (mathcursor &&
const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
mathcursor->drawSelection(pain);
- pain.text(x + 2, y, prefix(), font);
+ pain.pain.text(x + 2, y, prefix(), font);
// formula
par()->draw(pain, x + font_metrics::width(prefix(), f) + 5, y);
}
-void MathAMSArrayInset::metrics(MathMetricsInfo const & st) const
+void MathAMSArrayInset::metrics(MathMetricsInfo & mi) const
{
- MathMetricsInfo mi = st;
- if (mi.style == LM_ST_DISPLAY)
- mi.style = LM_ST_TEXT;
- MathGridInset::metrics(mi);
+ MathMetricsInfo m = mi;
+ if (m.base.style == LM_ST_DISPLAY)
+ m.base.style = LM_ST_TEXT;
+ MathGridInset::metrics(m);
width_ += 12;
}
-void MathAMSArrayInset::draw(Painter & pain, int x, int y) const
+void MathAMSArrayInset::draw(MathPainterInfo & pi, int x, int y) const
{
- MathGridInset::draw(pain, x + 6, y);
+ MathGridInset::draw(pi, x + 6, y);
int yy = y - ascent_;
- mathed_draw_deco(pain, x + 1, yy, 5, height(), name_left());
- mathed_draw_deco(pain, x + width_ - 6, yy, 5, height(), name_right());
+ mathed_draw_deco(pi, x + 1, yy, 5, height(), name_left());
+ mathed_draw_deco(pi, x + width_ - 6, yy, 5, height(), name_right());
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter & pain, int x, int y) const;
+ void draw(MathPainterInfo & pain, int x, int y) const;
///
MathAMSArrayInset * asAMSArrayInset() { return this; }
}
-void MathArrayInset::metrics(MathMetricsInfo const & st) const
+void MathArrayInset::metrics(MathMetricsInfo & mi) const
{
- MathMetricsInfo mi = st;
- if (mi.style == LM_ST_DISPLAY)
- mi.style = LM_ST_TEXT;
- MathGridInset::metrics(mi);
+ MathMetricsInfo m = mi;
+ if (m.base.style == LM_ST_DISPLAY)
+ m.base.style = LM_ST_TEXT;
+ MathGridInset::metrics(m);
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
MathArrayInset * asArrayInset() { return this; }
}
-void MathBigInset::metrics(MathMetricsInfo const & mi) const
+void MathBigInset::metrics(MathMetricsInfo & mi) const
{
- LyXFont font;
- whichFont(font, LM_TC_VAR, mi);
- double h = mathed_char_ascent(font, 'I');
+ double h = mathed_char_ascent(mi.base.font, 'I');
double f = increase();
width_ = 6;
ascent_ = int(h + f * h);
}
-void MathBigInset::draw(Painter & pain, int x, int y) const
+void MathBigInset::draw(MathPainterInfo & pi, int x, int y) const
{
- mathed_draw_deco(pain, x + 1, y - ascent_, 4, height(), delim_);
+ mathed_draw_deco(pi, x + 1, y - ascent_, 4, height(), delim_);
}
///
MathInset * clone() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
void normalize(NormalStream & os) const;
#endif
#include "math_binaryopinset.h"
-#include "frontends/Painter.h"
+#include "MathPainterInfo.h"
#include "support/LOstream.h"
#include "math_support.h"
#include "math_mathmlstream.h"
}
-void MathBinaryOpInset::metrics(MathMetricsInfo const & mi) const
+void MathBinaryOpInset::metrics(MathMetricsInfo & mi) const
{
mi_ = mi;
xcell(0).metrics(mi);
}
-void MathBinaryOpInset::draw(Painter & pain, int x, int y) const
+void MathBinaryOpInset::draw(MathPainterInfo & pain, int x, int y) const
{
xcell(0).draw(pain, x, y);
drawChar(pain, LM_TC_CONST, mi_, x + xcell(0).width() , y, op_);
///
MathInset * clone() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
void normalize(NormalStream &) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
private:
///
int opwidth() const;
}
-void MathBinomInset::metrics(MathMetricsInfo const & st) const
+void MathBinomInset::metrics(MathMetricsInfo & mi) const
{
- MathMetricsInfo mi = st;
- smallerStyleFrac(mi);
+ MathScriptChanger(mi.base);
xcell(0).metrics(mi);
xcell(1).metrics(mi);
ascent_ = xcell(0).height() + 4 + 5;
}
-void MathBinomInset::draw(Painter & pain, int x, int y) const
+void MathBinomInset::draw(MathPainterInfo & pi, int x, int y) const
{
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(), "(");
- mathed_draw_deco(pain, x + width() - dw(), y - ascent_, dw(), height(), ")");
+ MathScriptChanger(pi.base);
+ xcell(0).draw(pi, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
+ xcell(1).draw(pi, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
+ mathed_draw_deco(pi, x, y - ascent_, dw(), height(), "(");
+ mathed_draw_deco(pi, x + width() - dw(), y - ascent_, dw(), height(), ")");
}
///
void normalize(NormalStream &) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
private:
///
int dw() const;
}
-void MathBoxInset::draw(Painter & pain, int x, int y) const
+void MathBoxInset::draw(MathPainterInfo & pain, int x, int y) const
{
MathGridInset::draw(pain, x, y);
mathed_draw_framebox(pain, x, y, this);
///
void normalize(NormalStream &) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
private:
///
}
-void MathBraceInset::metrics(MathMetricsInfo const & mi) const
+void MathBraceInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
int a, d;
- whichFont(font_, LM_TC_TEX, mi);
- mathed_char_dim(font_, '{', a, d, wid_);
+ mathed_char_dim(mi.base.font, '{', a, d, wid_);
ascent_ = max(xcell(0).ascent(), a);
descent_ = max(xcell(0).descent(), a);
width_ = xcell(0).width() + 2 * wid_;
}
-void MathBraceInset::draw(Painter & pain, int x, int y) const
+void MathBraceInset::draw(MathPainterInfo & pi, int x, int y) const
{
- drawChar(pain, font_, x, y, '{');
- xcell(0).draw(pain, x + wid_, y);
- drawChar(pain, font_, x + width_ - wid_, y, '}');
+ LyXFont font = pi.base.font;
+ font.setColor(LColor::latex);
+ drawChar(pi, font, x, y, '{');
+ xcell(0).draw(pi, x + wid_, y);
+ drawChar(pi, font, x + width_ - wid_, y, '}');
}
///
MathBraceInset * asBraceInset() { return this; }
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream &) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
private:
/// width of brace character
mutable int wid_;
- ///
- mutable LyXFont font_;
};
#endif
#include "math_parser.h"
#include "math_mathmlstream.h"
#include "math_support.h"
-#include "frontends/Painter.h"
MathCasesInset::MathCasesInset(row_type n)
}
-void MathCasesInset::metrics(MathMetricsInfo const & mi) const
+void MathCasesInset::metrics(MathMetricsInfo & mi) const
{
MathGridInset::metrics(mi);
width_ += 8;
}
-void MathCasesInset::draw(Painter & pain, int x, int y) const
+void MathCasesInset::draw(MathPainterInfo & pain, int x, int y) const
{
mathed_draw_deco(pain, x + 1, y - ascent(), 6, height(), "{");
MathGridInset::draw(pain, x + 8, y);
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter & pain, int x, int y) const;
+ void draw(MathPainterInfo & pain, int x, int y) const;
///
void normalize(NormalStream &) const;
#endif
-bool isBinaryOp(char c, MathTextCodes type)
-{
- return type < LM_TC_SYMB && strchr("+-<>=/*", c);
-}
+namespace {
+ bool isBinaryOp(char c)
+ {
+ return strchr("+-<>=/*", c);
+ }
-MathCharInset::MathCharInset(char c)
- : char_(c), code_(nativeCode(c))
-{
-//lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
-}
+ bool slanted(char c)
+ {
+ //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
+ return isalpha(c);
+ }
-MathCharInset::MathCharInset(char c, MathTextCodes t)
- : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
-{
-//lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
}
-MathTextCodes MathCharInset::nativeCode(char c)
-{
- if (isalpha(c))
- return LM_TC_VAR;
- //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
- return LM_TC_CONST;
-}
+MathCharInset::MathCharInset(char c)
+ : char_(c)
+{}
+
MathInset * MathCharInset::clone() const
}
-void MathCharInset::metrics(MathMetricsInfo const & mi) const
+void MathCharInset::metrics(MathMetricsInfo & mi) const
{
+#if 1
+ if (slanted(char_) && !mi.base.fontinset) {
+ MathShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE);
+ mathed_char_dim(mi.base.font, char_, ascent_, descent_, width_);
+ } else {
+ mathed_char_dim(mi.base.font, char_, ascent_, descent_, width_);
+ }
+ if (isBinaryOp(char_))
+ width_ += 2 * font_metrics::width(' ', mi.base.font);
+#else
whichFont(font_, code_, mi);
mathed_char_dim(font_, char_, ascent_, descent_, width_);
if (isBinaryOp(char_, code_))
width_ += 2 * font_metrics::width(' ', font_);
+#endif
}
-void MathCharInset::draw(Painter & pain, int x, int y) const
+void MathCharInset::draw(MathPainterInfo & pi, int x, int y) const
{
- //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
- if (isBinaryOp(char_, code_))
- x += font_metrics::width(' ', font_);
+ //lyxerr << "drawing '" << char_ << "' code: " << pi.code << endl;
+ if (isBinaryOp(char_))
+ x += font_metrics::width(' ', pi.base.font);
+#if 1
+ if (slanted(char_) && !pi.base.fontinset) {
+ MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
+ pi.draw(x, y, char_);
+ } else {
+ pi.draw(x, y, char_);
+ }
+#else
drawChar(pain, font_, x, y, char_);
+#endif
}
}
-void MathCharInset::writeHeader(ostream & os) const
-{
- if (math_font_name(code_))
- os << '\\' << math_font_name(code_) << '{';
-}
-
-
-void MathCharInset::writeTrailer(ostream & os) const
-{
- if (math_font_name(code_))
- os << '}';
-}
-
-
-void MathCharInset::writeRaw(ostream & os) const
-{
- os << char_;
-}
-
-
void MathCharInset::write(WriteStream & os) const
{
- writeHeader(os.os());
- writeRaw(os.os());
- writeTrailer(os.os());
+ os << char_;
}
}
-void MathCharInset::handleFont(MathTextCodes t)
-{
- code_ = (code_ == t) ? LM_TC_VAR : t;
-}
-
-
-void MathCharInset::validate(LaTeXFeatures & features) const
-{
- // Make sure amssymb is put in preamble if Blackboard Bold or
- // Fraktur used:
- if ((code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK))
- features.require("amssymb");
-}
-
-
bool MathCharInset::match(MathInset * p) const
{
MathCharInset const * q = p->asCharInset();
- return q && char_ == q->char_ && code_ == q->code_;
+ return q && char_ == q->char_;
}
///
explicit MathCharInset(char c);
///
- MathCharInset(char c, MathTextCodes t);
- ///
MathInset * clone() const;
///
- static MathTextCodes nativeCode(char c);
- ///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void metricsT(TextMetricsInfo const & st) const;
///
///
void write(WriteStream & os) const;
///
- void writeHeader(std::ostream &) const;
- ///
- void writeTrailer(std::ostream &) const;
- ///
- void writeRaw(std::ostream &) const;
- ///
void normalize(NormalStream &) const;
/// identifies Charinsets
MathCharInset const * asCharInset() const { return this; }
///
char getChar() const { return char_; }
///
- MathTextCodes code() const { return code_; }
- ///
bool isRelOp() const;
///
- void validate(LaTeXFeatures & features) const;
- ///
- void handleFont(MathTextCodes t);
- ///
bool match(MathInset *) const;
/// identifies complicated things that need braces if used as arg
bool needsBraces() const { return false; }
private:
/// the character
char char_;
- /// the font to be used on screen
- MathTextCodes code_;
- ///
- mutable LyXFont font_;
};
#endif
#include "math_spaceinset.h"
#include "math_specialcharinset.h"
#include "math_support.h"
+#include "math_unknowninset.h"
#include <algorithm>
#include <cctype>
MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
- : formula_(formula), lastcode_(LM_TC_MIN),
- autocorrect_(false), selection_(false)
+ : formula_(formula), autocorrect_(false), selection_(false)
{
left ? first() : last();
}
autocorrect_ = false;
if (inMacroMode()) {
macroModeClose();
- lastcode_ = LM_TC_MIN;
return true;
}
selHandle(sel);
- lastcode_ = LM_TC_MIN;
if (hasPrevAtom() && openable(prevAtom(), sel)) {
pushRight(prevAtom());
autocorrect_ = false;
if (inMacroMode()) {
macroModeClose();
- lastcode_ = LM_TC_MIN;
return true;
}
selHandle(sel);
- lastcode_ = LM_TC_MIN;
if (hasNextAtom() && openable(nextAtom(), sel)) {
pushLeft(nextAtom());
autocorrect_ = false;
selHandle(sel);
macroModeClose();
- lastcode_ = LM_TC_MIN;
if (!par()->idxHome(idx(), pos()))
popLeft();
dump("home 2");
autocorrect_ = false;
selHandle(sel);
macroModeClose();
- lastcode_ = LM_TC_MIN;
if (!par()->idxEnd(idx(), pos()))
popRight();
dump("end 2");
void MathCursor::markInsert()
{
//lyxerr << "inserting mark\n";
- array().insert(pos(), MathAtom(new MathCharInset(0, lastcode_)));
+ array().insert(pos(), MathAtom(new MathCharInset(0)));
}
}
-void MathCursor::insert(char c, MathTextCodes t)
-{
- //lyxerr << "inserting '" << c << "'\n";
- selClearOrDel();
- plainInsert(MathAtom(new MathCharInset(c, t)));
-}
-
-
void MathCursor::insert(char c)
{
- insert(c, lastcode_);
+ //lyxerr << "inserting '" << c << "'\n";
+ selClearOrDel();
+ plainInsert(MathAtom(new MathCharInset(c)));
}
void MathCursor::macroModeClose()
{
- MathInset::difference_type const t = macroNamePos();
- if (t == -1)
+ MathUnknownInset * p = inMacroMode();
+ if (!p)
return;
- string s = macroName();
- array().erase(t, pos());
- pos() = t;
+ p->finalize();
+ string s = p->name();
+ --pos();
+ array().erase(pos());
if (s != "\\")
interpret(s);
}
-MathInset::difference_type MathCursor::macroNamePos() const
-{
- for (MathInset::difference_type i = pos() - 1; i >= 0; --i) {
- MathAtom & p = array().at(i);
- if (p->code() == LM_TC_TEX && p->getChar() == '\\')
- return i;
- }
- return -1;
-}
-
-
string MathCursor::macroName() const
{
- string s;
- MathInset::difference_type i = macroNamePos();
- for (; i >= 0 && i < int(pos()); ++i)
- s += array().at(i)->getChar();
- return s;
+ return inMacroMode() ? inMacroMode()->name() : "";
}
-void MathCursor::drawSelection(Painter & pain) const
+void MathCursor::drawSelection(MathPainterInfo & pain) const
{
if (!selection_)
return;
int y1 = c.yo() - c.ascent();
int x2 = c.xo() + c.pos2x(i2.pos_);
int y2 = c.yo() + c.descent();
- pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+ pain.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
} else {
vector<MathInset::idx_type> indices
= i1.par_->idxBetween(i1.idx_, i2.idx_);
int y1 = c.yo() - c.ascent();
int x2 = c.xo() + c.width();
int y2 = c.yo() + c.descent();
- pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+ pain.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
}
}
}
-void MathCursor::handleFont(MathTextCodes t)
-{
- macroModeClose();
- if (selection_) {
- MathCursorPos i1;
- MathCursorPos i2;
- getSelection(i1, i2);
- if (i1.idx_ == i2.idx_) {
- MathArray & ar = i1.cell();
- for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
- ar.at(pos)->handleFont(t);
- }
- } else
- lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
-}
-
-
void MathCursor::handleDelim(string const & l, string const & r)
{
handleNest(new MathDelimInset(l, r));
}
-bool MathCursor::inMacroMode() const
+MathUnknownInset * MathCursor::inMacroMode() const
{
- return macroNamePos() != -1;
+ if (pos() == 0)
+ return 0;
+ MathUnknownInset * p = prevAtom()->asUnknownInset();
+ return (p && !p->final()) ? p : 0;
}
return true;
}
- latexkeys const * l = in_word_set(name);
- if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) {
- lastcode_ = static_cast<MathTextCodes>(l->id);
- return true;
- }
-
// prevent entering of recursive macros
if (formula()->lyxCode() == Inset::MATHMACRO_CODE
&& formula()->getInsetName() == name)
int n = c - '0';
MathMacroTemplate * p = formula()->par()->asMacroTemplate();
if (p && 1 <= n && n <= p->numargs())
- insert(MathAtom(new MathMacroArgument(c - '0', lastcode_)));
+ insert(MathAtom(new MathMacroArgument(c - '0')));
else {
insert(MathAtom(new MathSpecialCharInset('#')));
interpret(c); // try again
string name = macroName();
//lyxerr << "interpret name: '" << name << "'\n";
- // extend macro name if possible
- if (isalpha(c)) {
- insert(c, LM_TC_TEX);
+ if (name.empty() && c == '\\') {
+ backspace();
+ interpret("\\backslash");
return true;
}
- // leave macro mode if explicitly requested
- if (c == ' ') {
- macroModeClose();
+ if (isalpha(c)) {
+ inMacroMode()->name() += c;
return true;
}
selClearOrDel();
- if (lastcode_ == LM_TC_TEXTRM || par()->asBoxInset()) {
+ if (/*lastcode_ == LM_TC_TEXTRM ||*/ par()->asBoxInset()) {
// suppress direct insertion of two spaces in a row
// the still allows typing '<space>a<space>' and deleting the 'a', but
// it is better than nothing...
if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
return true;
- insert(c, LM_TC_TEXTRM);
+ insert(c); // LM_TC_TEXTRM;
+ return true;
+ }
+
+ if (c == '\\') {
+ lyxerr << "starting with macro\n";
+ insert(MathAtom(new MathUnknownInset("\\", false)));
return true;
}
}
if (c == '#') {
- insert(c, LM_TC_TEX);
+ insert(c); // LM_TC_TEX;
return true;
}
/*
if (c == '{' || c == '}', c)) {
- insert(c, LM_TC_TEX);
+ insert(c); // LM_TC_TEX;
return true;
}
*/
if (c == '$' || c == '%') {
insert(MathAtom(new MathSpecialCharInset(c)));
- lastcode_ = LM_TC_VAR;
return true;
}
+/*
if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
insert(c, LM_TC_VAR);
return true;
//bv->owner()->message(_("TeX mode"));
return true;
}
+*/
// try auto-correction
if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
return true;
// no special circumstances, so insert the character without any fuss
- insert(c, lastcode_ == LM_TC_MIN ? MathCharInset::nativeCode(c) : lastcode_);
- lastcode_ = LM_TC_MIN;
- autocorrect_ = true;
+ insert(c);
+ autocorrect_ = true;
return true;
}
}
+void MathCursor::insetToggle()
+{
+ if (hasNextAtom())
+ nextAtom()->lock(!nextAtom()->lock());
+}
+
+
string MathCursor::info() const
{
ostringstream os;
- if (pos() > 0)
- prevAtom()->infoize(os);
+ os << "Math editor mode ";
+ for (int i = 0, n = Cursor_.size(); i < n; ++i) {
+ Cursor_[i].par_->infoize(os);
+ os << " ";
+ }
+ //if (pos() > 0)
+ // prevAtom()->infoize(os);
+ os << " ";
return os.str().c_str(); // .c_str() needed for lyxstring
}
#pragma interface
#endif
-#include "math_defs.h"
#include "math_inset.h"
#include "math_pos.h"
#include "LString.h"
class InsetFormulaBase;
-class Painter;
+class MathPainterInfo;
+class MathUnknownInset;
class Selection;
/**
/// interpret name a name of a macro
void macroModeClose();
/// are we currently typing the name of a macro?
- bool inMacroMode() const;
+ MathUnknownInset * inMacroMode() const;
/// are we currently typing '#1' or '#2' or...?
bool inMacroArgMode() const;
///
void selGet(MathArray & ar);
///
- void drawSelection(Painter & pain) const;
- ///
- void handleFont(MathTextCodes t);
+ void drawSelection(MathPainterInfo & pain) const;
///
void handleDelim(string const & l, string const & r);
///
/// read contents of line into an array
void readLine(MathArray & ar) const;
/// remove this as soon as LyXFunc::getStatus is "localized"
- MathTextCodes getLastCode() const { return lastcode_; }
+ string getLastCode() const { return "mathnormal"; }
///
void pullArg(bool goright);
///
bool isInside(MathInset const *) const;
///
- MathTextCodes nextCode() const;
- ///
char valign() const;
///
char halign() const;
void setSelection(cursor_type const & where, size_type n);
///
void insert(char);
+ /// lock/unlock inset
+ void insetToggle();
/// hack for reveal codes
void markInsert();
string macroName() const;
///
MathInset::difference_type macroNamePos() const;
- ///
- void insert(char, MathTextCodes t);
/// can we enter the inset?
bool openable(MathAtom const &, bool selection) const;
/// write access to cursor cell position
mutable cursor_type Anchor_;
/// pointer to enclsing LyX inset
InsetFormulaBase * formula_;
+ // Selection stuff
/// text code of last char entered
- MathTextCodes lastcode_;
+ //MathTextCodes lastcode_;
/// do we allow autocorrection
bool autocorrect_;
/// do we currently select
bool selection_;
+ /// are we entering a macro name?
+ bool macromode_;
};
extern MathCursor * mathcursor;
}
-void MathDecorationInset::metrics(MathMetricsInfo const & mi) const
+void MathDecorationInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
width_ = xcell(0).width();
}
-void MathDecorationInset::draw(Painter & pain, int x, int y) const
+void MathDecorationInset::draw(MathPainterInfo & pain, int x, int y) const
{
xcell(0).draw(pain, x, y);
if (wide())
///
MathInset * clone() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
void normalize(NormalStream & os) const;
///
#endif
-///
-enum MathTextCodes {
- ///
- LM_TC_MIN = 0,
- /// internal code for variables
- LM_TC_VAR,
- /// internal code for stuff in wrapped in mbox etc
- LM_TC_BOX,
- ///
- LM_TC_CONST,
- ///
- LM_TC_RM,
- ///
- LM_TC_CAL,
- ///
- LM_TC_EUFRAK,
- ///
- LM_TC_BF,
- //
- LM_TC_BB,
- ///
- LM_TC_SF,
- ///
- LM_TC_TT,
- ///
- LM_TC_IT,
- ///
- LM_TC_TEXTRM,
- /// math mode TeX characters ",;:{}"
- LM_TC_TEX,
- /// internal code when typing greek
- LM_TC_GREEK,
- /// internal code when typing a single greek character
- LM_TC_GREEK1,
- /// internal code for symbols
- LM_TC_SYMB,
- /// internal code for symbols that get bigger in displayed math
- LM_TC_BOLDSYMB,
- ///
- LM_TC_CMR,
- ///
- LM_TC_CMSY,
- ///
- LM_TC_CMM,
- ///
- LM_TC_CMEX,
- ///
- LM_TC_MSA,
- ///
- LM_TC_MSB,
- ///
- LM_FONT_END
-};
-
-
/// Types of lyx-math insets
enum MathInsetTypes {
///
LM_OT_MATRIX,
/// A LaTeX macro
- LM_OT_UNDEF,
- ///
- LM_OT_FUNCLIM,
- ///
LM_OT_MACRO,
///
- LM_OT_MAX
+ LM_OT_NONE
};
#endif
}
-void MathDelimInset::metrics(MathMetricsInfo const & mi) const
+void MathDelimInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
int a, d, w;
- LyXFont font;
- whichFont(font, LM_TC_VAR, mi);
- mathed_char_dim(font, 'I', a, d, w);
+ mathed_char_dim(mi.base.font, 'I', a, d, w);
int h0 = (a + d) / 2;
int a0 = max(xcell(0).ascent(), a) - h0;
int d0 = max(xcell(0).descent(), d) + h0;
}
-void MathDelimInset::draw(Painter & pain, int x, int y) const
+void MathDelimInset::draw(MathPainterInfo & pi, int x, int y) const
{
int const w = dw();
int const b = y - ascent_;
- xcell(0).draw(pain, x + w + 4, y);
- mathed_draw_deco(pain, x + 4, b, w, height(), left_);
- mathed_draw_deco(pain, x + width() - w - 4, b, w, height(), right_);
+ xcell(0).draw(pi, x + w + 4, y);
+ mathed_draw_deco(pi, x + 4, b, w, height(), left_);
+ mathed_draw_deco(pi, x + width() - w - 4, b, w, height(), right_);
}
/// is it |...|?
bool isAbs() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
}
-void MathDiffInset::metrics(MathMetricsInfo const &) const
+void MathDiffInset::metrics(MathMetricsInfo &) const
{
lyxerr << "should not happen\n";
}
-void MathDiffInset::draw(Painter &, int, int) const
+void MathDiffInset::draw(MathPainterInfo &, int, int) const
{
lyxerr << "should not happen\n";
}
///
void addDer(MathArray const & der);
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void normalize(NormalStream &) const;
}
-void MathDotsInset::metrics(MathMetricsInfo const & mi) const
+void MathDotsInset::metrics(MathMetricsInfo & mi) const
{
- LyXFont font;
- whichFont(font, LM_TC_VAR, mi);
- mathed_char_dim(font, 'M', ascent_, descent_, width_);
+ mathed_char_dim(mi.base.font, 'M', ascent_, descent_, width_);
if (name_ == "ldots" || name_ == "dotsm")
dh_ = 0;
else if (name_ == "cdots" || name_ == "dotsb"
}
-void MathDotsInset::draw(Painter & pain, int x, int y) const
+void MathDotsInset::draw(MathPainterInfo & pain, int x, int y) const
{
mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, name_);
if (name_ == "vdots" || name_ == "ddots")
///
MathInset * clone() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
void normalize(NormalStream &) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
protected:
/// cache for the thing's heigth
mutable int dh_;
}
-void MathExFuncInset::metrics(MathMetricsInfo const & mi) const
+void MathExFuncInset::metrics(MathMetricsInfo & mi) const
{
- whichFont(font_, LM_TC_TEXTRM, mi);
- mathed_string_dim(font_, name_, ascent_, descent_, width_);
+ mathed_string_dim(mi.base.font, name_, ascent_, descent_, width_);
}
-void MathExFuncInset::draw(Painter & pain, int x, int y) const
+void MathExFuncInset::draw(MathPainterInfo & pi, int x, int y) const
{
- drawStr(pain, font_, x, y, name_);
+ drawStrBlack(pi, x, y, name_);
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void normalize(NormalStream &) const;
private:
///
string const name_;
- ///
- mutable LyXFont font_;
};
#endif
}
-void MathExIntInset::metrics(MathMetricsInfo const &) const
+void MathExIntInset::metrics(MathMetricsInfo &) const
{
lyxerr << "should not happen" << endl;
}
-void MathExIntInset::draw(Painter &, int, int) const
+void MathExIntInset::draw(MathPainterInfo &, int, int) const
{
lyxerr << "should not happen" << endl;
}
///
void symbol(string const &);
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void normalize(NormalStream &) const;
#include "math_diffinset.h"
#include "math_exfuncinset.h"
#include "math_exintinset.h"
-#include "math_funcinset.h"
#include "math_fracinset.h"
#include "math_matrixinset.h"
#include "math_mathmlstream.h"
#include "math_scriptinset.h"
#include "math_stringinset.h"
#include "math_symbolinset.h"
+#include "math_unknowninset.h"
#include "Lsstream.h"
#include "debug.h"
// returns sequence of char with same code starting at it up to end
// it might be less, though...
MathArray::const_iterator charSequence(MathArray::const_iterator it,
- MathArray::const_iterator end, string & s, MathTextCodes & c)
+ MathArray::const_iterator end, string & s)
{
- MathCharInset const * p = (*it)->asCharInset();
- c = p->code();
- for (; it != end; ++it) {
- p = (*it)->asCharInset();
- if (!p || p->code() != c)
- break;
- s += p->getChar();
- }
+ for (; it != end && (*it)->asCharInset(); ++it)
+ s += (*it)->getChar();
return it;
}
// create proper string inset
MathStringInset * p = new MathStringInset;
MathArray::const_iterator
- jt = charSequence(it, ar.end(), p->str_, p->code_);
+ jt = charSequence(it, ar.end(), p->str_);
// clean up
(*it).reset(p);
bool extractNumber(MathArray const & ar, int & i)
{
string s;
- MathTextCodes c;
- charSequence(ar.begin(), ar.end(), s, c);
+ charSequence(ar.begin(), ar.end(), s);
istringstream is(s.c_str());
is >> i;
return is;
bool extractNumber(MathArray const & ar, double & i)
{
string s;
- MathTextCodes c;
- charSequence(ar.begin(), ar.end(), s, c);
+ charSequence(ar.begin(), ar.end(), s);
istringstream is(s.c_str());
is >> i;
return is;
string name;
// is it a function?
- if ((*it)->asFuncInset()) {
+ if ((*it)->asUnknownInset()) {
// it certainly is if it is well known...
- name = (*it)->asFuncInset()->name();
+ name = (*it)->asUnknownInset()->name();
} else {
// is this a user defined function?
// it it probably not, if it doesn't have a name.
#include "math_casesinset.h"
#include "math_decorationinset.h"
#include "math_dotsinset.h"
-#include "math_funcinset.h"
+#include "math_fontinset.h"
#include "math_funcliminset.h"
#include "math_fracinset.h"
#include "math_kerninset.h"
#include "math_xyarrowinset.h"
-MathAtom createMathInset(latexkeys const * l)
+#include "math_metricsinfo.h"
+#include "debug.h"
+#include "math_support.h"
+#include "Lsstream.h"
+#include "support/filetools.h" // LibFileSearch
+
+#include <map>
+#include <fstream>
+
+
+namespace {
+
+// file scope
+typedef std::map<string, latexkeys> WordList;
+WordList theWordList;
+
+
+struct key_type {
+ ///
+ char const * name;
+ ///
+ char const * inset;
+ ///
+ int id;
+};
+
+
+key_type wordlist_array[] =
{
- switch (l->token) {
- case LM_TK_FUNCLIM:
- return MathAtom(new MathFuncLimInset(l->name));
- case LM_TK_SPECIAL:
- return MathAtom(new MathSpecialCharInset(static_cast<char>(l->id)));
- case LM_TK_SYM:
- case LM_TK_CMR:
- case LM_TK_CMSY:
- case LM_TK_CMM:
- case LM_TK_CMEX:
- case LM_TK_MSA:
- case LM_TK_MSB:
- return MathAtom(new MathSymbolInset(l));
- case LM_TK_STACK:
- return MathAtom(new MathStackrelInset);
- case LM_TK_UNDERSET:
- return MathAtom(new MathUndersetInset);
- case LM_TK_BINOM:
- case LM_TK_CHOOSE:
- return MathAtom(new MathBinomInset);
- case LM_TK_OVER:
- case LM_TK_FRAC:
- return MathAtom(new MathFracInset);
- case LM_TK_ATOP:
- return MathAtom(new MathFracInset(true));
- case LM_TK_NOT:
- return MathAtom(new MathNotInset);
- case LM_TK_LEFTEQN:
- return MathAtom(new MathLefteqnInset);
- case LM_TK_SQRT:
- return MathAtom(new MathSqrtInset);
- case LM_TK_ROOT:
- return MathAtom(new MathRootInset);
- case LM_TK_DECORATION:
- return MathAtom(new MathDecorationInset(l->name));
- case LM_TK_SPACE:
- return MathAtom(new MathSpaceInset(l->id));
- case LM_TK_DOTS:
- return MathAtom(new MathDotsInset(l->name));
- case LM_TK_BOX:
- return MathAtom(new MathBoxInset(l->name));
- case LM_TK_FUNC:
- return MathAtom(new MathFuncInset(l->name));
- case LM_TK_STY:
- return MathAtom(new MathSizeInset(l));
- default:
- return MathAtom(new MathUnknownInset(l->name));
+ {"!", "space", 0},
+ {"#", "special", 0},
+ {"$", "special", 0},
+ {"%", "special", 0},
+ {"&", "special", 0},
+ {"(", "begin", LM_OT_SIMPLE},
+ {")", "end", LM_OT_SIMPLE},
+ {",", "space", 1},
+ {".", "special", 0},
+ {":", "space", 2},
+ {";", "space", 3},
+ {"Pr", "funclim", 0},
+ {"[", "begin", LM_OT_EQUATION},
+ {"]", "end", LM_OT_EQUATION},
+ {"_", "special", '_'},
+ {"acute", "decoration", 0},
+ {"arccos", "func", 0},
+ {"arcsin", "func", 0},
+ {"arctan", "func", 0},
+ {"arg", "func", 0},
+ {"bar", "decoration", 0},
+ {"begin", "begin", 0},
+ {"bf", "oldfont", 0},
+ {"bmod", "func", 0},
+ {"breve", "decoration", 0},
+ {"cal", "oldfont", 0},
+ {"cdots", "dots", 0},
+ {"check", "decoration", 0},
+ {"cos", "func", 0},
+ {"cosh", "func", 0},
+ {"cot", "func", 0},
+ {"coth", "func", 0},
+ {"csc", "func", 0},
+ {"ddot", "decoration", 0},
+ {"dddot", "decoration", 0},
+ {"ddots", "dots", 0},
+ {"deg", "func", 0},
+ {"det", "funclim", 0},
+ {"dim", "func", 0},
+ {"displaystyle", "style", LM_ST_DISPLAY},
+ {"dot", "decoration", 0},
+ {"dotsb", "dots", 0},
+ {"dotsc", "dots", 0},
+ {"dotsi", "dots", 0},
+ {"dotsm", "dots", 0},
+ {"dotso", "dots", 0},
+ {"end", "end", 0},
+ {"exp", "func", 0},
+ {"frak", "font", 0},
+ {"gcd", "funclim", 0},
+ {"grave", "decoration", 0},
+ {"hat", "decoration", 0},
+ {"hom", "func", 0},
+ {"inf", "funclim", 0},
+ {"it", "oldfont", 0},
+ {"ker", "func", 0},
+ {"label", "label", 0},
+ {"ldots", "dots", 0},
+ {"left", "left", 0},
+ {"lg", "func", 0},
+ {"lim", "funclim", 0},
+ {"liminf", "funclim", 0},
+ {"limits", "limit", 1 },
+ {"limsup", "funclim", 0},
+ {"ln", "func", 0},
+ {"log", "func", 0},
+ {"lyxbox", "box", 0},
+ {"lyxnegspace", "space", 6},
+ {"mathbb", "font", 0},
+ {"mathbf", "font", 0},
+ {"mathcal", "font", 0},
+ {"mathfrak", "font", 0},
+ {"mathit", "font", 0},
+ {"mathnormal", "font", 0},
+ {"mathring", "decoration", 0},
+ {"mathrm", "font", 0},
+ {"mathsf", "font", 0},
+ {"mathtt", "font", 0},
+ {"max", "funclim", 0},
+ {"mbox", "box", 0},
+ {"min", "funclim", 0},
+ {"newcommand", "newcommand", 0 },
+ {"nolimits", "limit", -1},
+ {"nonumber", "nonum", 0},
+ {"overbrace", "decoration", 0},
+ {"overleftarrow", "decoration", 0},
+ {"overline", "decoration", 0},
+ {"overrightarrow", "decoration", 0},
+ {"overleftrightarrow", "decoration", 0},
+ {"protect", "protect", 0},
+ {"qquad", "space", 5},
+ {"quad", "space", 4},
+ {"right", "right", 0},
+ {"rm", "oldfont", 0},
+ {"scriptscriptstyle", "style", LM_ST_SCRIPTSCRIPT},
+ {"scriptstyle", "style", LM_ST_SCRIPT},
+ {"sec", "func", 0},
+ {"sin", "func", 0},
+ {"sinh", "func", 0},
+ {"sup", "funclim", 0},
+ {"tan", "func", 0},
+ {"tanh", "func", 0},
+ {"textbf", "font", 0},
+ {"textit", "font", 0},
+ {"textmd", "font", 0},
+ {"textrm", "font", 0},
+ {"textsl", "font", 0},
+ {"textup", "font", 0},
+ {"textstyle", "style", LM_ST_TEXT},
+ {"tilde", "decoration", 0},
+ {"tt", "oldfont", 0},
+ {"underbar", "decoration", 0},
+ {"underbrace", "decoration", 0},
+ {"underleftarrow", "decoration", 0},
+ {"underline", "decoration", 0},
+ {"underrightarrow", "decoration", 0},
+ {"underleftrightarrow", "decoration", 0},
+ {"underset", "underset", 0},
+ {"vdots", "dots", 0},
+ {"vec", "decoration", 0},
+ {"widehat", "decoration", 0},
+ {"widetilde", "decoration", 0},
+ {"{", "special", '{'},
+ {"}", "special", '}'}
+};
+
+
+
+void readSymbols(string const & filename)
+{
+ std::ifstream fs(filename.c_str());
+ while (fs) {
+ int charid = 0;
+ int fallbackid = 0;
+ latexkeys tmp;
+ string line;
+ getline(fs, line);
+ istringstream is(line);
+ is >> tmp.name
+ >> tmp.inset
+ >> charid
+ >> fallbackid
+ >> tmp.extra
+ >> tmp.xmlname;
+ if (!is)
+ continue;
+
+ // tmp.inset _is_ the fontname here.
+ if (math_font_available(tmp.inset)) {
+ tmp.draw += char(charid);
+ } else {
+ if (tmp.inset == "cmex")
+ tmp.inset = "lyxsymb";
+ else
+ tmp.inset = "lyxboldsymb";
+ tmp.draw += char(fallbackid);
+ }
+
+ if (theWordList.find(tmp.name) != theWordList.end())
+ lyxerr << "readSymbols: inset " << tmp.name
+ << " already exists.\n";
+ else
+ theWordList[tmp.name] = tmp;
+ lyxerr << "read symbol '" << tmp.name
+ << " inset: " << tmp.inset
+ << " draw: " << int(tmp.draw[0])
+ << " extra: " << tmp.extra
+ << "'\n";
+ }
+}
+
+
+void initSymbols()
+{
+ unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
+ for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
+ latexkeys tmp;
+ tmp.name = p->name;
+ tmp.inset = p->inset;
+ tmp.draw = p->name;
+ theWordList[p->name] = tmp;
}
+
+ lyxerr[Debug::MATHED] << "reading symbols file\n";
+ string const file = LibFileSearch(string(), "symbols");
+ if (file.empty())
+ lyxerr << "Could not find symbols file\n";
+ else
+ readSymbols(file);
+}
+
+
+} // namespace anon
+
+
+latexkeys const * in_word_set(string const & str)
+{
+ static bool initialized = false;
+
+ if (!initialized) {
+ initSymbols();
+ initialized = true;
+ }
+
+ WordList::iterator it = theWordList.find(str);
+ lyxerr << "looking up '" << str << "' found: " << (it !=
+ theWordList.end()) << "\n";
+ return (it != theWordList.end()) ? &(it->second) : 0;
}
MathAtom createMathInset(string const & s)
{
- //cerr << "creating inset with name: '" << s << "'\n";
+ cerr << "creating inset with name: '" << s << "'\n";
if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
return MathAtom(new MathMacroArgument(s[1] - '0'));
if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
&& s[2] >= '1' && s[2] <= '9')
return MathAtom(new MathMacroArgument(s[2] - '0'));
-
if (s == "kern")
return MathAtom(new MathKernInset);
-
if (s == "xymatrix")
return MathAtom(new MathXYMatrixInset);
-
if (s == "xrightarrow" || s == "xleftarrow")
return MathAtom(new MathXArrowInset(s));
-
if (s == "split" || s == "gathered" || s == "aligned")
return MathAtom(new MathSplitInset(s));
-
if (s == "cases")
return MathAtom(new MathCasesInset);
-
if (s == "substack")
return MathAtom(new MathSubstackInset);
-
if (s == "subarray" || s == "array")
return MathAtom(new MathArrayInset(s, 1, 1));
-
if (s == "pmatrix" || s == "bmatrix" || s == "vmatrix" || s == "Vmatrix" ||
s == "matrix")
return MathAtom(new MathAMSArrayInset(s));
+ if (s == "sqrt")
+ return MathAtom(new MathSqrtInset);
+ if (s == "root")
+ return MathAtom(new MathRootInset);
+ if (s == "stack")
+ return MathAtom(new MathStackrelInset);
+ if (s == "binom" || s == "choose")
+ return MathAtom(new MathBinomInset);
+ if (s == "over" || s == "frac")
+ return MathAtom(new MathFracInset);
+ if (s == "atop")
+ return MathAtom(new MathFracInset(true));
+ if (s == "not")
+ return MathAtom(new MathNotInset);
+ if (s == "lefteqn")
+ return MathAtom(new MathLefteqnInset);
latexkeys const * l = in_word_set(s);
- if (l)
- return createMathInset(l);
+ if (l) {
+ string const & inset = l->inset;
+ cerr << " fount inset: '" << inset << "'\n";
+ if (inset == "funclim")
+ return MathAtom(new MathFuncLimInset(s));
+ if (inset == "special")
+ return MathAtom(new MathSpecialCharInset(s[0]));
+ if (inset == "lyxsym" ||
+ inset == "cmr" ||
+ inset == "cmsy" ||
+ inset == "cmm" ||
+ inset == "cmex" ||
+ inset == "msa" ||
+ inset == "msb")
+ return MathAtom(new MathSymbolInset(l));
+ if (inset == "underset")
+ return MathAtom(new MathUndersetInset);
+ if (inset == "decoration")
+ return MathAtom(new MathDecorationInset(l->name));
+ //if (inset == "space")
+ // return MathAtom(new MathSpaceInset(l->id));
+ if (inset == "dots")
+ return MathAtom(new MathDotsInset(l->name));
+ if (inset == "box")
+ return MathAtom(new MathBoxInset(l->name));
+ if (inset == "style")
+ return MathAtom(new MathSizeInset(l));
+ if (inset == "font")
+ return MathAtom(new MathFontInset(l->name));
+ if (inset == "oldfont")
+ return MathAtom(new MathFontInset(l->name));
+ if (inset == "func")
+ return MathAtom(new MathUnknownInset(l->name, true, true));
+
+ return MathAtom(new MathUnknownInset(l->name));
+ }
if (MathMacroTable::has(s))
return MathAtom(new MathMacro(s));
class latexkeys;
MathAtom createMathInset(string const &);
-MathAtom createMathInset(latexkeys const *);
#endif
--- /dev/null
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_fontinset.h"
+#include "debug.h"
+#include "math_mathmlstream.h"
+#include "math_streamstr.h"
+#include "math_support.h"
+#include "LaTeXFeatures.h"
+#include "textpainter.h"
+
+
+
+
+MathFontInset::MathFontInset(string const & name)
+ : MathNestInset(1), name_(name)
+{
+ lock(true);
+}
+
+
+MathInset * MathFontInset::clone() const
+{
+ return new MathFontInset(*this);
+}
+
+
+void MathFontInset::metrics(MathMetricsInfo & mi) const
+{
+ MathFontSetChanger dummy(mi.base, name_.c_str());
+ xcell(0).metrics(mi);
+ width_ = xcell(0).width();
+ ascent_ = xcell(0).ascent();
+ descent_ = xcell(0).descent();
+}
+
+
+void MathFontInset::draw(MathPainterInfo & pi, int x, int y) const
+{
+ //lyxerr << "MathFontInset::draw\n";
+ MathFontSetChanger dummy(pi.base, name_.c_str());
+ xcell(0).draw(pi, x, y);
+}
+
+
+void MathFontInset::metricsT(TextMetricsInfo const & mi) const
+{
+ xcell(0).metricsT(mi);
+ width_ = xcell(0).width();
+ ascent_ = xcell(0).ascent();
+ descent_ = xcell(0).descent();
+}
+
+
+void MathFontInset::drawT(TextPainter & pain, int x, int y) const
+{
+ //lyxerr << "drawing font code: " << code_ << '\n';
+ xcell(0).drawT(pain, x, y);
+}
+
+
+void MathFontInset::write(WriteStream & os) const
+{
+ os << '\\' << name_ << '{' << cell(0) << '}';
+}
+
+
+void MathFontInset::normalize(NormalStream & os) const
+{
+ os << "[font_ " << name_ << " " << cell(0) << "]";
+}
+
+
+void MathFontInset::validate(LaTeXFeatures & features) const
+{
+ // Make sure amssymb is put in preamble if Blackboard Bold or
+ // Fraktur used:
+ if (name_ == "mathfrak" || name_ == "mathbb")
+ features.require("amssymb");
+}
+
+
+void MathFontInset::infoize(std::ostream & os) const
+{
+ os << "Font: " << name_;
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_FONTINSET_H
+#define MATH_FONTINSET_H
+
+#include "math_nestinset.h"
+#include "LString.h"
+#include "lyxfont.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** The base character inset.
+ \author André Pönitz
+ */
+
+class MathFontInset : public MathNestInset {
+public:
+ ///
+ explicit MathFontInset(string const & name);
+ ///
+ MathInset * clone() const;
+ ///
+ void metrics(MathMetricsInfo & st) const;
+ ///
+ void draw(MathPainterInfo &, int x, int y) const;
+ ///
+ void metricsT(TextMetricsInfo const & st) const;
+ ///
+ void drawT(TextPainter &, int x, int y) const;
+ ///
+ void write(WriteStream & os) const;
+ ///
+ void normalize(NormalStream &) const;
+ /// identifies Fontinsets
+ MathFontInset const * asFontInset() const { return this; }
+ ///
+ void validate(LaTeXFeatures & features) const;
+ ///
+ void infoize(std::ostream & os) const;
+
+private:
+ /// the font to be used on screen
+ string name_;
+};
+#endif
}
-void MathFracInset::metrics(MathMetricsInfo const & mi) const
+void MathFracInset::metrics(MathMetricsInfo & mi) const
{
- MathMetricsInfo m = mi;
- smallerStyleFrac(m);
- xcell(0).metrics(m);
- xcell(1).metrics(m);
+ MathFracChanger dummy(mi.base);
+ xcell(0).metrics(mi);
+ xcell(1).metrics(mi);
width_ = max(xcell(0).width(), xcell(1).width()) + 2;
ascent_ = xcell(0).height() + 2 + 5;
descent_ = xcell(1).height() + 2 - 5;
}
-void MathFracInset::draw(Painter & pain, int x, int y) const
+void MathFracInset::draw(MathPainterInfo & pi, int x, int y) const
{
int m = x + width() / 2;
- xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
- xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 2 - 5);
+ MathFracChanger dummy(pi.base);
+ xcell(0).draw(pi, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
+ xcell(1).draw(pi, m - xcell(1).width() / 2, y + xcell(1).ascent() + 2 - 5);
if (!atop_)
- pain.line(x, y - 5, x + width(), y - 5, LColor::math);
+ pi.pain.line(x, y - 5, x + width(), y - 5, LColor::math);
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & mi) const;
+ void metrics(MathMetricsInfo & mi) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void metricsT(TextMetricsInfo const & mi) const;
///
}
-void MathFuncInset::metrics(MathMetricsInfo const & mi) const
+void MathFuncInset::metrics(MathMetricsInfo & mi) const
{
- whichFont(font_, LM_TC_TEXTRM, mi);
- mathed_string_dim(font_, name_, ascent_, descent_, width_);
+ mathed_string_dim(mi.font_, name_, ascent_, descent_, width_);
}
void MathFuncInset::draw(Painter & pain, int x, int y) const
{
- drawStr(pain, font_, x, y, name_);
+ drawStr(pain, mi.font_, x, y, name_);
}
#define MATH_FUNCINSET_H
#include "math_diminset.h"
-#include "math_defs.h"
#ifdef __GNUG__
#pragma interface
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
void draw(Painter &, int x, int y) const;
///
bool MathFuncLimInset::isScriptable() const
{
- //return mi_.style == LM_ST_DISPLAY;
- return true;
+ return scriptable_;
}
}
-void MathFuncLimInset::metrics(MathMetricsInfo const & mi) const
+void MathFuncLimInset::metrics(MathMetricsInfo & mi) const
{
- whichFont(font_, LM_TC_TEXTRM, mi);
- mathed_string_dim(font_, name_, ascent_, descent_, width_);
+ scriptable_ = (mi.base.style == LM_ST_DISPLAY);
+ mathed_string_dim(mi.base.font, name_, ascent_, descent_, width_);
}
-void MathFuncLimInset::draw(Painter & pain, int x, int y) const
+void MathFuncLimInset::draw(MathPainterInfo & pi, int x, int y) const
{
- drawStr(pain, font_, x, y, name_);
+ drawStrBlack(pi, x, y, name_);
}
///
void normalize(NormalStream &) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
bool isScriptable() const;
///
string const name_;
///
- mutable LyXFont font_;
+ mutable bool scriptable_;
};
#endif
}
-void MathGridInset::metrics(MathMetricsInfo const & mi) const
+void MathGridInset::metrics(MathMetricsInfo & mi) const
{
// let the cells adjust themselves
MathNestInset::metrics(mi);
}
-void MathGridInset::draw(Painter & pain, int x, int y) const
+void MathGridInset::draw(MathPainterInfo & pain, int x, int y) const
{
for (idx_type idx = 0; idx < nargs(); ++idx)
xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx));
for (int i = 0; i < rowinfo_[row].lines_; ++i) {
int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
- i * hlinesep() - hlinesep()/2 - rowsep()/2;
- pain.line(x + 1, yy, x + width_ - 1, yy);
+ pain.pain.line(x + 1, yy, x + width_ - 1, yy);
}
for (col_type col = 0; col <= ncols(); ++col)
for (int i = 0; i < colinfo_[col].lines_; ++i) {
int xx = x + colinfo_[col].offset_
- i * vlinesep() - vlinesep()/2 - colsep()/2;
- pain.line(xx, y - ascent_ + 1, xx, y + descent_ - 1);
+ pain.pain.line(xx, y - ascent_ + 1, xx, y + descent_ - 1);
}
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void metricsT(TextMetricsInfo const & st) const;
///
+++ /dev/null
-#include <config.h>
-
-#include "math_parser.h"
-#include "math_metricsinfo.h"
-#include "lyxlex.h"
-#include "debug.h"
-#include "support/filetools.h" // LibFileSearch
-
-#include <map>
-
-using std::map;
-
-namespace {
-
-// file scope
-typedef map<string, latexkeys> WordList;
-WordList theWordList;
-
-
-struct key_type {
- ///
- char const * name;
- ///
- MathTokenEnum token;
- ///
- unsigned int id;
-};
-
-
-key_type wordlist_array[] =
-{
- {"!", LM_TK_SPACE, 0},
- {"#", LM_TK_SPECIAL, '#'},
- {"$", LM_TK_SPECIAL, '$'},
- {"%", LM_TK_SPECIAL, '%'},
- {"&", LM_TK_SPECIAL, '&'},
- {"(", LM_TK_BEGIN, LM_OT_SIMPLE},
- {")", LM_TK_END, LM_OT_SIMPLE},
- {",", LM_TK_SPACE, 1},
- {".", LM_TK_SPECIAL, '.'},
- {":", LM_TK_SPACE, 2},
- {";", LM_TK_SPACE, 3},
- {"Pr", LM_TK_FUNCLIM, 0},
- {"[", LM_TK_BEGIN, LM_OT_EQUATION},
- {"]", LM_TK_END, LM_OT_EQUATION},
- {"_", LM_TK_SPECIAL, '_'},
- {"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},
- {"bar", LM_TK_DECORATION, 0},
- {"begin", LM_TK_BEGIN, 0},
- {"bf", LM_TK_OLDFONT, LM_TC_BF},
- {"binom", LM_TK_BINOM, 0},
- {"bmod", LM_TK_FUNC, 0},
- {"breve", LM_TK_DECORATION, 0},
- {"cal", LM_TK_OLDFONT, LM_TC_CAL},
- {"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, 0},
- {"dddot", LM_TK_DECORATION, 0},
- {"ddots", LM_TK_DOTS, 0},
- {"dotsb", LM_TK_DOTS, 0},
- {"dotsc", LM_TK_DOTS, 0},
- {"dotsi", LM_TK_DOTS, 0},
- {"dotsm", LM_TK_DOTS, 0},
- {"dotso", 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, 0},
- {"end", LM_TK_END, 0},
- {"exp", LM_TK_FUNC, 0},
- {"frac", LM_TK_FRAC, 0},
- {"frak", LM_TK_FONT, LM_TC_EUFRAK},
- {"gcd", LM_TK_FUNCLIM, 0},
- {"grave", LM_TK_DECORATION, 0},
- {"hat", LM_TK_DECORATION, 0},
- {"hom", LM_TK_FUNC, 0},
- {"inf", LM_TK_FUNCLIM, 0},
- {"it", LM_TK_OLDFONT, LM_TC_IT},
- {"ker", LM_TK_FUNC, 0},
- {"label", LM_TK_LABEL, 0},
- {"lefteqn", LM_TK_LEFTEQN, 1},
- {"ldots", LM_TK_DOTS, 0},
- {"left", LM_TK_LEFT, 0},
- {"lg", LM_TK_FUNC, 0},
- {"lim", LM_TK_FUNCLIM, 0},
- {"liminf", LM_TK_FUNCLIM, 0},
- {"limits", LM_TK_LIMIT, 1 },
- {"limsup", LM_TK_FUNCLIM, 0},
- {"ln", LM_TK_FUNC, 0},
- {"log", LM_TK_FUNC, 0},
- {"lyxbox", LM_TK_BOX, 0},
- {"lyxnegspace", LM_TK_SPACE, 6},
- {"mathbb", LM_TK_FONT, LM_TC_BB},
- {"mathbf", LM_TK_FONT, LM_TC_BF},
- {"mathcal", LM_TK_FONT, LM_TC_CAL},
- {"mathfrak", LM_TK_FONT, LM_TC_EUFRAK},
- {"mathit", LM_TK_FONT, LM_TC_IT},
- {"mathnormal", LM_TK_FONT, LM_TC_VAR},
- {"mathring", LM_TK_DECORATION, 0},
- {"mathrm", LM_TK_FONT, LM_TC_RM},
- {"mathsf", LM_TK_FONT, LM_TC_SF},
- {"mathtt", LM_TK_FONT, LM_TC_TT},
- {"max", LM_TK_FUNCLIM, 0},
- //{"mbox", LM_TK_BOX, 0},
- {"min", 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, 0},
- {"over", LM_TK_OVER, 0},
- {"overbrace", LM_TK_DECORATION, 0},
- {"overleftarrow", LM_TK_DECORATION, 0},
- {"overline", LM_TK_DECORATION, 0},
- {"overrightarrow", LM_TK_DECORATION, 0},
- {"overleftrightarrow", LM_TK_DECORATION, 0},
- {"protect", LM_TK_PROTECT, 0},
- {"qquad", LM_TK_SPACE, 5},
- {"quad", LM_TK_SPACE, 4},
- {"right", LM_TK_RIGHT, 0},
- {"rm", LM_TK_OLDFONT, LM_TC_RM},
- {"root", LM_TK_ROOT, 0},
- {"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT},
- {"scriptstyle", LM_TK_STY, LM_ST_SCRIPT},
- {"sec", LM_TK_FUNC, 0},
- {"sin", LM_TK_FUNC, 0},
- {"sinh", LM_TK_FUNC, 0},
- {"sqrt", LM_TK_SQRT, 0},
- {"stackrel", LM_TK_STACK, 0},
- {"sup", LM_TK_FUNCLIM, 0},
- {"tan", LM_TK_FUNC, 0},
- {"tanh", LM_TK_FUNC, 0},
- {"textrm", LM_TK_FONT, LM_TC_TEXTRM},
- {"textstyle", LM_TK_STY, LM_ST_TEXT},
- {"tilde", LM_TK_DECORATION, 0},
- {"tt", LM_TK_OLDFONT, LM_TC_TT},
- {"underbar", LM_TK_DECORATION, 0},
- {"underbrace", LM_TK_DECORATION, 0},
- {"underleftarrow", LM_TK_DECORATION, 0},
- {"underline", LM_TK_DECORATION, 0},
- {"underrightarrow", LM_TK_DECORATION, 0},
- {"underleftrightarrow", LM_TK_DECORATION, 0},
- {"underset", LM_TK_UNDERSET, 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_SPECIAL, '}'}
-};
-
-
-
-MathTokenEnum tokenEnum(const string & font)
-{
- if (font == "cmr")
- return LM_TK_CMR;
- if (font == "cmsy")
- return LM_TK_CMSY;
- if (font == "cmm")
- return LM_TK_CMM;
- if (font == "cmex")
- return LM_TK_CMEX;
- if (font == "msa")
- return LM_TK_MSA;
- if (font == "msb")
- return LM_TK_MSB;
- return LM_TK_SYM;
-}
-
-
-void readSymbols(string const & filename)
-{
- LyXLex lex(0, 0);
- lex.setFile(filename);
- while (lex.isOK() && lex.next()) {
- latexkeys tmp;
- tmp.name = lex.getString();
- if (lex.next())
- tmp.token = tokenEnum(lex.getString());
- if (lex.next())
- tmp.latex_font_id = lex.getInteger();
- if (lex.next())
- tmp.id = lex.getInteger();
- if (lex.next())
- tmp.type = lex.getString();
- if (lex.next())
- tmp.xmlname = lex.getString();
- if (theWordList.find(tmp.name) != theWordList.end())
- lyxerr << "readSymbols: token " << tmp.name
- << " already exists.\n";
- else
- theWordList[tmp.name] = tmp;
- }
-}
-
-
-void initSymbols()
-{
- unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
- for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
- latexkeys tmp;
- tmp.name = p->name;
- tmp.token = p->token;
- tmp.id = p->id;
- tmp.latex_font_id = 0;
- theWordList[p->name] = tmp;
- }
-
- lyxerr[Debug::MATHED] << "reading symbols file\n";
- string const file = LibFileSearch(string(), "symbols");
- if (file.empty())
- lyxerr << "Could not find symbols file\n";
- else
- readSymbols(file);
-}
-
-
-} // namespace anon
-
-
-latexkeys const * in_word_set(string const & str)
-{
- static bool initialized = false;
-
- if (!initialized) {
- initSymbols();
- initialized = true;
- }
-
- WordList::iterator it = theWordList.find(str);
- return (it != theWordList.end()) ? &(it->second) : 0;
-}
MathInsetTypes typecode(string const & s)
{
+ if (s == "none") return LM_OT_NONE;
if (s == "equation") return LM_OT_EQUATION;
if (s == "display") return LM_OT_EQUATION;
if (s == "eqnarray") return LM_OT_EQNARRAY;
}
-void MathHullInset::metrics(MathMetricsInfo const & mi) const
+void MathHullInset::metrics(MathMetricsInfo & mi) const
{
- mi_ = mi;
- mi_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
-
// let the cells adjust themselves
- MathGridInset::metrics(mi_);
+ MathGridInset::metrics(mi);
if (display()) {
ascent_ += 12;
descent_ += 12;
}
+ mi_ = mi;
+ mi_.base.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
+
if (numberedType()) {
- whichFont(mi_.font, LM_TC_BF, mi_);
+ //augmentFont(mi_.base.font, "mathbf");
int l = 0;
for (row_type row = 0; row < nrows(); ++row)
- l = max(l, mathed_string_width(mi_.font, nicelabel(row)));
+ l = max(l, mathed_string_width(mi_.base.font, nicelabel(row)));
if (l)
width_ += 30 + l;
// make it at least as high as the current font
int asc = 0;
int des = 0;
- math_font_max_dim(mi_.font, asc, des);
+ math_font_max_dim(mi_.base.font, asc, des);
ascent_ = max(ascent_, asc);
descent_ = max(descent_, des);
}
-void MathHullInset::draw(Painter & pain, int x, int y) const
+void MathHullInset::draw(MathPainterInfo & pi, int x, int y) const
{
- MathGridInset::draw(pain, x, y);
+ MathGridInset::draw(pi, x, y);
if (numberedType()) {
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
for (row_type row = 0; row < nrows(); ++row) {
int const yy = y + rowinfo_[row].offset_;
- drawStr(pain, mi_.font, xx, yy, nicelabel(row));
+ drawStrBlack(pi, xx, yy, nicelabel(row));
}
}
}
os << "\\begin{gather}\n";
break;
+ case LM_OT_NONE:
+ break;
+
default:
os << "\\begin{unknown" << star(n) << "}";
}
os << "\n\\end{gather}\n";
break;
+ case LM_OT_NONE:
+ os << "\n";
+ break;
+
default:
os << "\\end{unknown" << star(n) << "}";
}
}
+void MathHullInset::infoize(std::ostream & os) const
+{
+ os << normalName(getType());
+}
+
void MathHullInset::check() const
{
lyx::Assert(nonum_.size() == nrows());
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void metricsT(TextMetricsInfo const & st) const;
///
void mathmlize(MathMLStream &) const;
///
void normalize(NormalStream &) const;
+ ///
+ void infoize(std::ostream & os) const;
private:
///
}
-void MathInset::metrics(MathMetricsInfo const &) const
+void MathInset::metrics(MathMetricsInfo &) const
{
lyxerr << "MathInset::metrics() called directly!\n";
}
-void MathInset::draw(Painter &, int, int) const
+void MathInset::draw(MathPainterInfo &, int, int) const
{
lyxerr << "MathInset::draw() called directly!\n";
}
#pragma interface
#endif
+#include "LString.h"
#include "frontends/mouse_state.h"
#include "math_xdata.h"
-#include "math_defs.h"
/**
class MathBoxInset;
class MathCharInset;
class MathDelimInset;
+class MathFontInset;
class MathFuncInset;
class MathGridInset;
class MathFracInset;
virtual void substitute(MathMacro const & macro);
/// compute the size of the object, sets ascend_, descend_ and width_
// updates the (xo,yo)-caches of all contained cells
- virtual void metrics(MathMetricsInfo const & st) const;
+ virtual void metrics(MathMetricsInfo & st) const;
/// draw the object
- virtual void draw(Painter &, int x, int y) const;
+ virtual void draw(MathPainterInfo &, int x, int y) const;
/// the ascent of the inset above the baseline
/// compute the size of the object for text based drawing
virtual void metricsT(TextMetricsInfo const & st) const;
virtual MathCharInset const * asCharInset() const { return 0; }
virtual MathDelimInset * asDelimInset() { return 0; }
virtual MathDelimInset const * asDelimInset() const { return 0; }
+ virtual MathFontInset const * asFontInset() const { return 0; }
virtual MathFuncInset * asFuncInset() { return 0; }
virtual MathFracInset * asFracInset() { return 0; }
virtual MathGridInset * asGridInset() { return 0; }
virtual MathSpaceInset * asSpaceInset() { return 0; }
virtual MathStringInset * asStringInset() { return 0; }
virtual MathSymbolInset const * asSymbolInset() const { return 0; }
+ virtual MathUnknownInset * asUnknownInset() { return 0; }
virtual MathUnknownInset const * asUnknownInset() const { return 0; }
virtual MathXYMatrixInset const* asXYMatrixInset() const{ return 0; }
/// return the content as char if the inset is able to do so
virtual char getChar() const { return 0; }
- /// return the content's char code if it has one
- virtual MathTextCodes code() const { return LM_TC_MIN; }
/// identifies things that can get \limits or \nolimits
virtual bool takesLimits() const { return false; }
/// identifies complicated things that need braces if used as arg
/// request "external features"
virtual void validate(LaTeXFeatures & features) const;
/// char char code if possible
- virtual void handleFont(MathTextCodes) {}
+ virtual void handleFont(string const &) {}
/// is this inset equal to a given other inset?
virtual bool match(MathInset *) const { return false; }
/// replace things by other things
virtual void replace(ReplaceData &) {}
/// do we contain a given subsequence?
virtual bool contains(MathArray const &) { return false; }
+ /// access to the lock (only nest array have one)
+ virtual bool lock() const { return false; }
+ /// access to the lock (only nest array have one)
+ virtual void lock(bool) {}
/// write LaTeX and Lyx code
virtual void write(WriteStream & os) const;
}
-void MathKernInset::metrics(MathMetricsInfo const & /*mi*/) const
+void MathKernInset::metrics(MathMetricsInfo & /*mi*/) const
{
#ifdef WITH_WARNINGS
#warning fix this once the interface to LyXLength has improved
}
-void MathKernInset::draw(Painter &, int, int) const
+void MathKernInset::draw(MathPainterInfo &, int, int) const
{}
///
MathInset * clone() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
void normalize(NormalStream & ns) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
private:
/// width in em
LyXLength wid_;
}
-void MathLefteqnInset::metrics(MathMetricsInfo const & mi) const
+void MathLefteqnInset::metrics(MathMetricsInfo & mi) const
{
MathNestInset::metrics(mi);
ascent_ = xcell(0).ascent() + 2;
}
-void MathLefteqnInset::draw(Painter & pain, int x, int y) const
+void MathLefteqnInset::draw(MathPainterInfo & pain, int x, int y) const
{
xcell(0).draw(pain, x + 2, y);
//mathed_draw_framebox(pain, x, y, this);
///
MathInset * clone() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
void normalize(NormalStream &) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
};
#endif
}
-void MathLimitOpInset::metrics(MathMetricsInfo const &) const
+void MathLimitOpInset::metrics(MathMetricsInfo &) const
{
lyxerr << "should not happen\n";
}
-void MathLimitOpInset::draw(Painter &, int, int) const
+void MathLimitOpInset::draw(MathPainterInfo &, int, int) const
{
lyxerr << "should not happen\n";
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
#include "support/lstrings.h"
#include "support/LAssert.h"
#include "debug.h"
-#include "frontends/Painter.h"
#include "LaTeXFeatures.h"
}
-void MathMacro::metrics(MathMetricsInfo const & mi) const
+void MathMacro::metrics(MathMetricsInfo & mi) const
{
- whichFont(font_, LM_TC_TEX, mi);
+ augmentFont(font_, "lyxtex");
mi_ = mi;
if (defining()) {
}
-void MathMacro::draw(Painter & pain, int x, int y) const
+void MathMacro::draw(MathPainterInfo & pain, int x, int y) const
{
metrics(mi_);
LyXFont texfont;
- whichFont(texfont, LM_TC_TEX, mi_);
+ augmentFont(texfont, "lyxtex");
if (defining()) {
drawStr(pain, texfont, x, y, name());
///
MathMacro(MathMacro const &);
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
MathInset * clone() const;
///
#include "math_macroarg.h"
#include "math_macro.h"
-#include "math_defs.h"
#include "math_mathmlstream.h"
#include "math_support.h"
#include "debug.h"
using std::endl;
-MathMacroArgument::MathMacroArgument(int n, MathTextCodes code)
- : MathNestInset(1), number_(n), expanded_(false), code_(code)
+MathMacroArgument::MathMacroArgument(int n)
+ : MathNestInset(1), number_(n), expanded_(false)
{
if (n < 1 || n > 9) {
lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
void MathMacroArgument::write(WriteStream & os) const
{
- if (code_ == LM_TC_MIN)
- os << str_;
- else
- os << '\\' << math_font_name(code_) << '{' << str_ << '}';
+ os << str_;
}
-void MathMacroArgument::metrics(MathMetricsInfo const & mi) const
+void MathMacroArgument::metrics(MathMetricsInfo & mi) const
{
- whichFont(font_, LM_TC_TEX, mi);
if (expanded_) {
xcell(0).metrics(mi);
width_ = xcell(0).width();
ascent_ = xcell(0).ascent();
descent_ = xcell(0).descent();
- } else
- mathed_string_dim(font_, str_, ascent_, descent_, width_);
+ } else {
+ mathed_string_dim(mi.base.font, str_, ascent_, descent_, width_);
+ }
}
-void MathMacroArgument::draw(Painter & pain, int x, int y) const
+void MathMacroArgument::draw(MathPainterInfo & pi, int x, int y) const
{
if (expanded_)
- xcell(0).draw(pain, x, y);
+ xcell(0).draw(pi, x, y);
else
- drawStr(pain, font_, x, y, str_);
+ drawStrRed(pi, x, y, str_);
}
void MathMacroArgument::substitute(MathMacro const & m)
{
cell(0) = m.cell(number_ - 1);
- if (code_ != LM_TC_MIN)
- for (MathArray::iterator it = cell(0).begin(); it != cell(0).end(); ++it)
- it->nucleus()->handleFont(code_);
expanded_ = true;
}
class MathMacroArgument : public MathNestInset {
public:
///
- explicit MathMacroArgument(int, MathTextCodes = LM_TC_MIN);
+ explicit MathMacroArgument(int);
///
MathInset * clone() const;
///
bool isActive() const { return false; }
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void substitute(MathMacro const & macro);
char str_[3];
///
bool expanded_;
- ///
- mutable LyXFont font_;
- ///
- MathTextCodes code_;
};
#endif
define("\\def\\Longleftrightarrow{\\Leftarrow\\kern-8mu\\Rightarrow}");
define("\\def\\doteq{\\stackrel{\\cdot}{\\=}}");
- if (math_font_available(LM_TC_CMSY)) {
+ //if (math_font_available(LM_TC_CMSY)) {
define("\\def\\longrightarrow{\\lyxbar\\kern-6mu\\rightarrow}");
define("\\def\\longleftarrow{\\leftarrow\\kern-6mu\\lyxbar}");
define("\\def\\mapsto{\\mapstochar\\kern-4mu\\rightarrow}");
define("\\def\\longmapsto{\\mapstochar\\kern-3mu\\lyxbar\\kern-6mu\\rightarrow}");
- }
+ //}
- if (math_font_available(LM_TC_CMR) && math_font_available(LM_TC_CMSY)) {
+ //if (math_font_available(LM_TC_CMR) && math_font_available(LM_TC_CMSY)) {
define("\\def\\Longrightarrow{\\lyxeq\\kern-5mu\\Rightarrow}");
define("\\def\\Longleftarrow{\\Leftarrow\\kern-5mu\\lyxeq}");
define("\\def\\models{\\vert\\kern-3mu\\lyxeq}");
- }
+ //}
- if (math_font_available(LM_TC_CMM)) {
+ //if (math_font_available(LM_TC_CMM)) {
define("\\def\\hookrightarrow{\\lhook\\kern-8mu\\rightarrow}");
define("\\def\\hookleftarrow{\\leftarrow\\kern-8mu\\rhook}");
define("\\def\\bowtie{\\triangleright\\kern-2mu\\triangleleft}");
- }
+ //}
- if (math_font_available(LM_TC_MSA)) {
+ //if (math_font_available(LM_TC_MSA)) {
//amsfonts.sty
define("\\def\\dashrightarrow{\\lyxdabar\\lyxdabar\\lyxright}");
define("\\def\\doublecap{\\Cap}");
define("\\def\\llless{\\lll}");
define("\\def\\gggtr{\\ggg}");
- }
+ //}
- if (math_font_available(LM_TC_MSB)) {
+ //if (math_font_available(LM_TC_MSB)) {
define("\\def\\Join{\\ltimes\\kern-12mu\\rtimes}");
- }
+ //}
//
define("\\def\\mathcircumflex{\\mbox{\\^{}}}\n" "{\\hat{}}");
}
-void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const
+void MathMacroTemplate::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
xcell(1).metrics(mi);
}
-void MathMacroTemplate::draw(Painter & pain, int x, int y) const
+void MathMacroTemplate::draw(MathPainterInfo & pain, int x, int y) const
{
int const w0 = xcell(0).width();
int const w1 = xcell(1).width();
xcell(0).draw(pain, x + 2, y + 1);
- pain.rectangle(x, y - ascent() + 1, w0 + 4, height(), LColor::blue);
+ pain.pain.rectangle(x, y - ascent() + 1, w0 + 4, height(), LColor::blue);
xcell(1).draw(pain, x + 8 + w0, y + 1);
- pain.rectangle(x + w0 + 6 , y - ascent() + 1, w1 + 4, height(), LColor::blue);
+ pain.pain.rectangle(x + w0 + 6 , y - ascent() + 1, w1 + 4, height(), LColor::blue);
}
///
string const & name() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
/// identifies macro templates
MathMacroTemplate * asMacroTemplate() { return this; }
private:
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const &) const {}
+ void metrics(MathMetricsInfo &) const {}
/// identifies MatrixInsets
MathMatrixInset const * asMatrixInset() const { return this; }
+
+#include <config.h>
+
+#include "math_metricsinfo.h"
+#include "math_support.h"
+#include "frontends/Painter.h"
+
+
+
+MathMetricsBase::MathMetricsBase()
+ : font(), style(LM_ST_TEXT), fontinset(false)
+{}
+
+
+
+
+MathMetricsInfo::MathMetricsInfo()
+ : view(0), inset(0), idx(0), fullredraw(false)
+{}
+
+
+
+
+MathPainterInfo::MathPainterInfo(Painter & p)
+ : pain(p)
+{}
+
+
+void MathPainterInfo::draw(int x, int y, char c)
+{
+ pain.text(x, y, c, base.font);
+}
+
+
+
+
+MathScriptChanger::MathScriptChanger(MathMetricsBase & mb)
+ : MathChanger<MathMetricsBase>(mb)
+{
+ save_ = mb;
+ switch (mb.style) {
+ case LM_ST_DISPLAY:
+ case LM_ST_TEXT:
+ mb.style = LM_ST_SCRIPT;
+ mb.font.decSize();
+ mb.font.decSize();
+ break;
+ case LM_ST_SCRIPT:
+ mb.style = LM_ST_SCRIPTSCRIPT;
+ mb.font.decSize();
+ default:
+ break;
+ }
+}
+
+MathScriptChanger::~MathScriptChanger()
+{
+ orig_ = save_;
+}
+
+
+
+
+// decrease math size for fractions
+MathFracChanger::MathFracChanger(MathMetricsBase & mb)
+ : MathChanger<MathMetricsBase>(mb)
+{
+ save_ = mb;
+ switch (mb.style) {
+ case LM_ST_DISPLAY:
+ mb.style = LM_ST_TEXT;
+ break;
+ case LM_ST_TEXT:
+ mb.style = LM_ST_SCRIPT;
+ mb.font.decSize();
+ mb.font.decSize();
+ break;
+ case LM_ST_SCRIPT:
+ mb.style = LM_ST_SCRIPTSCRIPT;
+ mb.font.decSize();
+ break;
+ default:
+ break;
+ }
+}
+
+MathFracChanger::~MathFracChanger()
+{
+ orig_ = save_;
+}
+
+
+
+
+MathShapeChanger::MathShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
+ : MathChanger<LyXFont, LyXFont::FONT_SHAPE>(font)
+{
+ save_ = orig_.shape();
+ orig_.setShape(shape);
+}
+
+MathShapeChanger::~MathShapeChanger()
+{
+ orig_.setShape(save_);
+}
+
+
+
+
+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)
+{
+ save_ = mb;
+ changeSize(mb.font, mb.style - style);
+}
+
+
+MathStyleChanger::~MathStyleChanger()
+{
+ orig_ = save_;
+}
+
+
+
+
+MathFontSetChanger::MathFontSetChanger(MathMetricsBase & mb, char const * cmd)
+ : MathChanger<MathMetricsBase>(mb)
+{
+ save_ = mb;
+ mb.fontinset = true;
+ augmentFont(mb.font, cmd);
+}
+
+MathFontSetChanger::~MathFontSetChanger()
+{
+ orig_ = save_;
+}
+
#define MATH_METRICSINFO_H
#include "lyxfont.h"
+#include "math_defs.h"
class BufferView;
+class Painter;
class MathNestInset;
};
-struct MathMetricsInfo {
- ///
- MathMetricsInfo()
- : view(0), font(), style(LM_ST_TEXT),
- inset(0), idx(0),
- fullredraw(false)
- {}
+struct MathMetricsBase {
///
- MathMetricsInfo(BufferView * v, LyXFont const & f, MathStyles s)
- : view(v), font(f), style(s),
- inset(0), idx(0),
- fullredraw(false)
- {}
+ MathMetricsBase();
- ///
- BufferView * view;
///
LyXFont font;
///
MathStyles style;
+ ///
+ bool fontinset;
+};
+
+
+struct MathMetricsInfo {
+ ///
+ MathMetricsInfo();
+
+ ///
+ MathMetricsBase base;
+ ///
+ BufferView * view;
/// used to pass some info down
MathNestInset const * inset;
///
};
-struct TextMetricsInfo {
+struct MathPainterInfo {
+ ///
+ MathPainterInfo(Painter & p);
+ ///
+ void draw(int x, int y, char c);
+
+ ///
+ MathMetricsBase base;
+ ///
+ Painter & pain;
+};
+
+
+struct TextMetricsInfo {};
+
+
+// Generic base for temporarily changing things.
+// The original state gets restored when the Changer is destructed
+template <class Struct, class Temp = Struct>
+struct MathChanger {
+ ///
+ MathChanger(Struct & orig) : orig_(orig) {}
+protected:
///
- TextMetricsInfo()
- {}
+ Struct & orig_;
+ ///
+ Temp save_;
};
+
+
+struct MathScriptChanger : public MathChanger<MathMetricsBase> {
+ ///
+ MathScriptChanger(MathMetricsBase & orig);
+ ///
+ ~MathScriptChanger();
+};
+
+
+struct MathFracChanger : public MathChanger<MathMetricsBase> {
+ ///
+ MathFracChanger(MathMetricsBase & orig);
+ ///
+ ~MathFracChanger();
+};
+
+
+
+struct MathFontChanger : public MathChanger<LyXFont> {
+ ///
+ MathFontChanger(LyXFont & orig, char const * font);
+ ///
+ ~MathFontChanger();
+};
+
+
+struct MathFontSetChanger : public MathChanger<MathMetricsBase> {
+ ///
+ MathFontSetChanger(MathMetricsBase & mb, char const * font);
+ ///
+ ~MathFontSetChanger();
+};
+
+
+struct MathStyleChanger : public MathChanger<MathMetricsBase> {
+ ///
+ MathStyleChanger(MathMetricsBase & mb, MathStyles shape);
+ ///
+ ~MathStyleChanger();
+};
+
+
+struct MathShapeChanger : public MathChanger<LyXFont, LyXFont::FONT_SHAPE> {
+ ///
+ MathShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape);
+ ///
+ ~MathShapeChanger();
+};
+
+
#endif
MathNestInset::MathNestInset(idx_type nargs)
- : MathDimInset(), cells_(nargs)
+ : MathDimInset(), cells_(nargs), lock_(false)
{}
{
return mathcursor && mathcursor->isInside(this);
}
+
+
+bool MathNestInset::lock() const
+{
+ return lock_;
+}
+
+
+void MathNestInset::lock(bool l)
+{
+ lock_ = l;
+}
+
+
+bool MathNestInset::isActive() const
+{
+ return !lock_ && nargs() > 0;
+}
/// number of cells currently governed by us
idx_type nargs() const;
+ /// access to the lock
+ bool lock() const;
+ /// access to the lock
+ void lock(bool);
/// direct access to the cell
MathArray & cell(idx_type);
MathXArray const & xcell(idx_type) const;
/// can we move into this cell (see macroarg.h)
- bool isActive() const { return nargs() > 0; }
+ bool isActive() const;
/// request "external features"
void validate(LaTeXFeatures & features) const;
typedef std::vector<MathXArray> cells_type;
/// thusly:
cells_type cells_;
+ /// if the inset is locked, it can't be enter with the cursor
+ bool lock_;
};
#endif
}
-void MathNotInset::metrics(MathMetricsInfo const & mi) const
+void MathNotInset::metrics(MathMetricsInfo & mi) const
{
- if (math_font_available(LM_TC_CMSY)) {
- whichFont(font_, LM_TC_CMSY, mi);
- mathed_char_dim(font_, 54, ascent_, descent_, width_);
- }
- else {
- whichFont(font_, LM_TC_VAR, mi);
- mathed_char_dim(font_, '/', ascent_, descent_, width_);
+ font_ = mi.base.font;
+ if (math_font_available("cmsy")) {
+ augmentFont(font_, "cmsy");
+ char_ = 54;
+ } else {
+ augmentFont(font_, "mathnormal");
+ char_ = '/';
}
+ mathed_char_dim(font_, char_, ascent_, descent_, width_);
width_ = 0;
}
-void MathNotInset::draw(Painter & pain, int x, int y) const
+void MathNotInset::draw(MathPainterInfo & pain, int x, int y) const
{
- if (math_font_available(LM_TC_CMSY))
- drawChar(pain, font_, x, y, 54);
- else
- drawChar(pain, font_, x, y, '/');
+ drawChar(pain, font_, x, y, char_);
}
///
void normalize(NormalStream & ns) const;
///
- void metrics(MathMetricsInfo const & mi) const;
+ void metrics(MathMetricsInfo & mi) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
private:
///
mutable LyXFont font_;
+ ///
+ mutable char char_;
};
#endif
#include "math_charinset.h"
#include "math_deliminset.h"
#include "math_factory.h"
-#include "math_funcinset.h"
#include "math_kerninset.h"
#include "math_macro.h"
#include "math_macrotable.h"
}
-void add(MathArray & ar, char c, MathTextCodes code)
+void add(MathArray & ar, char c)
{
- ar.push_back(MathAtom(new MathCharInset(c, code)));
+ ar.push_back(MathAtom(new MathCharInset(c)));
}
///
bool parse_normal(MathAtom &);
///
- void parse_into(MathArray & array, unsigned flags, MathTextCodes = LM_TC_MIN);
+ void parse_into(MathArray & array, unsigned flags);
///
int lineno() const { return lineno_; }
///
private:
///
- void parse_into1(MathArray & array, unsigned flags, MathTextCodes);
- ///
- string getArg(char lf, char rf);
+ void parse_into1(MathArray & array, unsigned flags);
+ /// get arg delimited by 'left' and 'right'
+ string getArg(char left, char right);
///
char getChar();
///
return true;
}
-
-
-
+
bool Parser::parse_macro(string & name)
{
int nargs = 0;
MathMacroTable::create(name, nargs, ar1, ar2);
return true;
}
-
+
bool Parser::parse_normal(MathAtom & matrix)
{
}
-void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
+void Parser::parse_into(MathArray & array, unsigned flags)
{
- parse_into1(array, flags, code);
+ parse_into1(array, flags);
// remove 'unnecessary' braces:
if (array.size() == 1 && array.back()->asBraceInset()) {
lyxerr << "extra braces removed\n";
}
-void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
+void Parser::parse_into1(MathArray & array, unsigned flags)
{
bool panic = false;
int limits = 0;
}
else if (t.cat() == catLetter)
- add(array, t.character(), code);
+ add(array, t.character());
- else if (t.cat() == catSpace && code == LM_TC_TEXTRM)
- add(array, t.character(), code);
+ else if (t.cat() == catSpace) //&& code == LM_TC_TEXTRM
+ add(array, t.character());
else if (t.cat() == catParameter) {
Token const & n = getToken();
- array.push_back(MathAtom(new MathMacroArgument(n.character()-'0', code)));
+ array.push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
}
else if (t.cat() == catBegin) {
lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
dump();
//lyxerr << "found tab unexpectedly\n";
- add(array, '&', LM_TC_TEX);
+ add(array, '&'); //, LM_TC_TEX;
}
else if (t.cat() == catSuper || t.cat() == catSub) {
return;
else if (t.cat() == catOther)
- add(array, t.character(), code);
+ add(array, t.character());
//
// control sequences
array.push_back(MathAtom(new MathKernInset(s)));
}
-/*
- else if (t.cs() == "lyxkern") {
- MathAtom p = createMathInset(t.cs());
- parse_into(p->cell(0), flags, code);
- array.push_back(p);
- }
-*/
-
else if (t.cs() == "label") {
curr_label_ = getArg('{', '}');
}
else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
MathAtom p = createMathInset(t.cs());
array.swap(p->cell(0));
- parse_into(p->cell(1), flags, code);
+ parse_into(p->cell(1), flags);
array.push_back(p);
return;
}
else if (t.cs().size()) {
latexkeys const * l = in_word_set(t.cs());
if (l) {
- if (l->token == LM_TK_FONT) {
- //lyxerr << "starting font\n";
+ if (l->inset == "font") {
+ lyxerr << "starting font " << t.cs() << "\n";
//CatCode catSpaceSave = theCatcode[' '];
//if (l->id == LM_TC_TEXTRM) {
// // temporarily change catcode
// theCatcode[' '] = catLetter;
//}
- MathArray ar;
- parse_into(ar, FLAG_ITEM, static_cast<MathTextCodes>(l->id));
- array.push_back(ar);
+ MathAtom p = createMathInset(t.cs());
+ parse_into(p->cell(0), FLAG_ITEM);
+ array.push_back(p);
// undo catcode changes
- ////theCatcode[' '] = catSpaceSave;
+ //theCatcode[' '] = catSpaceSave;
//lyxerr << "ending font\n";
}
- else if (l->token == LM_TK_OLDFONT) {
- code = static_cast<MathTextCodes>(l->id);
+ else if (l->inset == "oldfont") {
+ MathAtom p = createMathInset(t.cs());
+ parse_into(p->cell(0), flags);
+ array.push_back(p);
+ return;
}
- else if (l->token == LM_TK_BOX) {
+ else if (l->inset == "box") {
MathAtom p = createMathInset(t.cs());
- parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX, LM_TC_BOX);
+ parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX);
array.push_back(p);
}
- else if (l->token == LM_TK_STY) {
+ else if (l->inset == "style") {
MathAtom p = createMathInset(t.cs());
- parse_into(p->cell(0), flags, code);
+ parse_into(p->cell(0), flags);
array.push_back(p);
return;
}
class MathArray;
class LyXLex;
-///
-enum MathTokenEnum
-{
- ///
- LM_TK_SYM = 256,
- ///
- LM_TK_BOX,
- ///
- LM_TK_CHOOSE,
- ///
- LM_TK_BINOM,
- ///
- LM_TK_ATOP,
- ///
- LM_TK_OVER,
- ///
- LM_TK_FRAC,
- ///
- LM_TK_SQRT,
- ///
- LM_TK_ROOT,
- ///
- LM_TK_LEFTEQN,
- ///
- LM_TK_BEGIN,
- ///
- LM_TK_END,
- /// mathcal, mathrm...
- LM_TK_OLDFONT,
- /// cal,...
- LM_TK_FONT,
- ///
- LM_TK_LEFT,
- ///
- LM_TK_RIGHT,
- ///
- LM_TK_DECORATION,
- ///
- LM_TK_FUNC,
- ///
- LM_TK_FUNCLIM,
- ///
- LM_TK_CMR,
- ///
- LM_TK_CMSY,
- ///
- LM_TK_CMM,
- ///
- LM_TK_CMEX,
- ///
- LM_TK_MSA,
- ///
- LM_TK_MSB,
- ///
- LM_TK_LABEL,
- ///
- LM_TK_NONUM,
- ///
- LM_TK_SPACE,
- ///
- LM_TK_DOTS,
- ///
- LM_TK_LIMIT,
- ///
- LM_TK_PROTECT,
- ///
- LM_TK_STY,
- ///
- LM_TK_SPECIAL,
- ///
- LM_TK_ARGUMENT,
- ///
- LM_TK_NEWCOMMAND,
- ///
- LM_TK_MATH,
- ///
- LM_TK_NOT,
- ///
- LM_TK_UNDERSET,
- ///
- LM_TK_STACK
-};
-
///
struct latexkeys {
/// name of the macro or primitive
string name;
- /// one of the categories above
- MathTokenEnum token;
- /// an id within a category if needed (only for spaces?)
- unsigned int id;
- /// which font to use (optional)
- unsigned int latex_font_id;
- /// operator/...
- string type;
+ /// name of a inset that handles that macro
+ string inset;
+ /// position of the ting in a font
+ string draw;
+ /// operator/..., fontname e
+ string extra;
/// how is this called as XML entity?
string xmlname;
};
}
-void MathRootInset::metrics(MathMetricsInfo const & mi) const
+void MathRootInset::metrics(MathMetricsInfo & mi) const
{
MathNestInset::metrics(mi);
ascent_ = max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
}
-void MathRootInset::draw(Painter & pain, int x, int y) const
+void MathRootInset::draw(MathPainterInfo & pain, int x, int y) const
{
int const w = xcell(0).width();
// the "exponent"
xp[2] = x + w; yp[2] = y + d;
xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
xp[4] = x; yp[4] = y + (d - a)/2 + 2;
- pain.lines(xp, yp, 5, LColor::math);
+ pain.pain.lines(xp, yp, 5, LColor::math);
}
///
bool idxUpDown(idx_type & idx, bool up) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
}
-void MathScriptInset::metrics(MathMetricsInfo const & mi) const
+void MathScriptInset::metrics(MathMetricsInfo & mi) const
{
metrics(0, mi);
}
-void MathScriptInset::metrics(MathInset const * nuc,
- MathMetricsInfo const & mi) const
+void MathScriptInset::metrics(MathInset const * nuc, MathMetricsInfo & mi) const
{
- MathMetricsInfo m = mi;
- smallerStyleScript(m);
- MathNestInset::metrics(m);
- whichFont(font_, LM_TC_VAR, m);
+ MathScriptChanger dummy(mi.base);
+ MathNestInset::metrics(mi);
if (nuc)
nuc->metrics(mi);
ascent_ = ascent2(nuc);
}
-void MathScriptInset::draw(Painter & pain, int x, int y) const
+void MathScriptInset::draw(MathPainterInfo & pi, int x, int y) const
{
//lyxerr << "unexpected call to MathScriptInset::draw()\n";
- draw(0, pain, x, y);
+ MathScriptChanger dummy(pi.base);
+ draw(0, pi, x, y);
}
}
-void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
+void MathScriptInset::draw(MathInset const * nuc, MathPainterInfo & pi,
int x, int y) const
{
+ MathScriptChanger dummy(pi.base);
if (nuc)
- nuc->draw(pain, x + dxx(nuc), y);
+ nuc->draw(pi, x + dxx(nuc), y);
else if (editing())
- drawStr(pain, font_, x + dxx(nuc), y, ".");
+ drawStr(pi, font_, x + dxx(nuc), y, ".");
if (hasUp())
- up().draw(pain, x + dx1(nuc), y - dy1(nuc));
-
+ up().draw(pi, x + dx1(nuc), y - dy1(nuc));
if (hasDown())
- down().draw(pain, x + dx0(nuc), y + dy0(nuc));
+ down().draw(pi, x + dx0(nuc), y + dy0(nuc));
}
+
void MathScriptInset::drawT(TextPainter & pain, int x, int y) const
{
//lyxerr << "unexpected call to MathScriptInset::draw()\n";
///
void normalize(NormalStream & os) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void metricsT(TextMetricsInfo const & st) const;
///
void drawT(TextPainter &, int x, int y) const;
///
- void metrics(MathInset const * nuc, MathMetricsInfo const & st) const;
+ void metrics(MathInset const * nuc, MathMetricsInfo & st) const;
///
- void draw(MathInset const * nuc, Painter &, int x, int y) const;
+ void draw(MathInset const * nuc, MathPainterInfo &, int x, int y) const;
///
void metricsT(MathInset const * nuc, TextMetricsInfo const & st) const;
///
}
-void MathSizeInset::draw(Painter & pain, int x, int y) const
+void MathSizeInset::metrics(MathMetricsInfo & mi) const
{
- xcell(0).draw(pain, x + 1, y);
- mathed_draw_framebox(pain, x, y, this);
+ //MathStyleChanger dummy(mi.base, MathStyles(key_->id));
+ xcell(0).metrics(mi);
+ ascent_ = xcell(0).ascent_ + 1;
+ descent_ = xcell(0).descent_ + 1;
+ width_ = xcell(0).width_ + 2;
}
-void MathSizeInset::metrics(MathMetricsInfo const & mi) const
+void MathSizeInset::draw(MathPainterInfo & pi, int x, int y) const
{
- MathMetricsInfo m = mi;
- m.style = MathStyles(key_->id);
- xcell(0).metrics(m);
- ascent_ = xcell(0).ascent_ + 1;
- descent_ = xcell(0).descent_ + 1;
- width_ = xcell(0).width_ + 2;
+ //MathStyleChanger dummy(pi.base, MathStyles(key_->id));
+ xcell(0).draw(pi, x + 1, y);
+ mathed_draw_framebox(pi, x, y, this);
}
#define MATHSIZEINSET_H
#include "math_nestinset.h"
-#include "math_defs.h"
#ifdef __GNUG__
#pragma interface
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
bool needsBraces() const { return false; }
}
-void MathSpaceInset::metrics(MathMetricsInfo const &) const
+void MathSpaceInset::metrics(MathMetricsInfo &) const
{
switch (space_) {
case 0: width_ = 6; break;
}
-void MathSpaceInset::draw(Painter & pain, int x, int y) const
+void MathSpaceInset::draw(MathPainterInfo & pain, int x, int y) const
{
// Sadly, HP-UX CC can't handle that kind of initialization.
xp[2] = x + width_ - 2; yp[2] = y;
xp[3] = x + width_ - 2; yp[3] = y - 3;
- pain.lines(xp, yp, 4, space_ ? LColor::latex : LColor::math);
+ pain.pain.lines(xp, yp, 4, space_ ? LColor::latex : LColor::math);
}
#define MATH_SPACEINSET_H
#include "math_diminset.h"
-#include "math_defs.h"
#ifdef __GNUG__
#pragma interface
///
void incSpace();
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void normalize(NormalStream &) const;
}
-int MathSpecialCharInset::ascent() const
+void MathSpecialCharInset::metrics(MathMetricsInfo & mi) const
{
- return mathed_char_ascent(font_, char_);
+ MathShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE);
+ mathed_char_dim(mi.base.font, char_, ascent_, descent_, width_);
}
-int MathSpecialCharInset::descent() const
+void MathSpecialCharInset::draw(MathPainterInfo & pi, int x, int y) const
{
- return mathed_char_descent(font_, char_);
-}
-
-
-int MathSpecialCharInset::width() const
-{
- return mathed_char_width(font_, char_);
-}
-
-
-void MathSpecialCharInset::metrics(MathMetricsInfo const & mi) const
-{
- whichFont(font_, LM_TC_CONST, mi);
-}
-
-
-void MathSpecialCharInset::draw(Painter & pain, int x, int y) const
-{
- drawChar(pain, font_, x, y, char_);
+ MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE);
+ pi.draw(x, y, char_);
}
#ifndef MATH_SPECIALCHARINSET_H
#define MATH_SPECIALCHARINSET_H
-#include "math_inset.h"
+#include "math_diminset.h"
#ifdef __GNUG__
#pragma interface
\author André Pönitz
*/
-class MathSpecialCharInset : public MathInset {
+class MathSpecialCharInset : public MathDimInset {
public:
///
explicit MathSpecialCharInset(char c);
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
void normalize(NormalStream &) const;
- ///
- int ascent() const;
- ///
- int descent() const;
- ///
- int width() const;
private:
/// the character
char char_;
- ///
- mutable LyXFont font_;
};
#endif
}
-void MathSqrtInset::metrics(MathMetricsInfo const & mi) const
+void MathSqrtInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
ascent_ = xcell(0).ascent() + 4;
}
-void MathSqrtInset::draw(Painter & pain, int x, int y) const
+void MathSqrtInset::draw(MathPainterInfo & pain, int x, int y) const
{
xcell(0).draw(pain, x + 10, y);
int const a = ascent_;
xp[1] = x + 8; yp[1] = y - a + 1;
xp[2] = x + 5; yp[2] = y + d - 1;
xp[3] = x; yp[3] = y + (d - a)/2;
- pain.lines(xp, yp, 4, LColor::math);
+ pain.pain.lines(xp, yp, 4, LColor::math);
}
///
MathInset * clone() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
- void metrics(MathMetricsInfo const & mi) const;
+ void metrics(MathMetricsInfo & mi) const;
///
void drawT(TextPainter &, int x, int y) const;
///
}
-void MathStackrelInset::metrics(MathMetricsInfo const & mi) const
+void MathStackrelInset::metrics(MathMetricsInfo & mi) const
{
- MathMetricsInfo m = mi;
- smallerStyleFrac(m);
- xcell(0).metrics(m);
xcell(1).metrics(mi);
+ MathFracChanger dummy(mi.base);
+ xcell(0).metrics(mi);
width_ = max(xcell(0).width(), xcell(1).width()) + 4;
ascent_ = xcell(1).ascent() + xcell(0).height() + 4;
descent_ = xcell(1).descent();
}
-void MathStackrelInset::draw(Painter & pain, int x, int y) const
+void MathStackrelInset::draw(MathPainterInfo & pi, int x, int y) const
{
int m = x + width() / 2;
int yo = y - xcell(1).ascent() - xcell(0).descent() - 1;
- xcell(0).draw(pain, m - xcell(0).width() / 2, yo);
- xcell(1).draw(pain, m - xcell(1).width() / 2, y);
+ xcell(1).draw(pi, m - xcell(1).width() / 2, y);
+ MathFracChanger dummy(pi.base);
+ xcell(0).draw(pi, m - xcell(0).width() / 2, yo);
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
#include "math_mathmlstream.h"
#include "math_streamstr.h"
#include "LColor.h"
-#include "frontends/Painter.h"
#include "math_support.h"
#include "math_parser.h"
#include "LaTeXFeatures.h"
#include "debug.h"
-#include <cctype>
-
MathStringInset::MathStringInset()
- : str_(), code_(LM_TC_MIN)
+ : str_()
{}
-MathStringInset::MathStringInset(string const & s, MathTextCodes t)
- : str_(s), code_(t)
+MathStringInset::MathStringInset(string const & s)
+ : str_(s)
{}
}
-int MathStringInset::ascent() const
-{
- return mathed_string_ascent(font_, str_);
-}
-
-
-int MathStringInset::descent() const
+void MathStringInset::metrics(MathMetricsInfo & mi) const
{
- return mathed_string_descent(font_, str_);
+ mathed_string_dim(mi.base.font, str_, ascent_, descent_, width_);
}
-int MathStringInset::width() const
-{
- return mathed_string_width(font_, str_);
-}
-
-
-void MathStringInset::validate(LaTeXFeatures & features) const
-{
- //lyxerr << "stringinset amssymb" << endl;
- if (code_ == LM_TC_MSA || code_ == LM_TC_MSB)
- features.require("amssymb");
-}
-
-
-void MathStringInset::metrics(MathMetricsInfo const & mi) const
-{
- whichFont(font_, code_, mi);
-}
-
-
-void MathStringInset::draw(Painter & pain, int x, int y) const
+void MathStringInset::draw(MathPainterInfo & pi, int x, int y) const
{
//lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
- drawStr(pain, font_, x, y, str_);
+ drawStr(pi, pi.base.font, x, y, str_);
}
void MathStringInset::maplize(MapleStream & os) const
{
- if (code_ != LM_TC_VAR || str_.size() <= 1) {
+ if (/*code_ != LM_TC_VAR || */ str_.size() <= 1) {
os << ' ' << str_ << ' ';
return;
}
void MathStringInset::octavize(OctaveStream & os) const
{
- if (code_ != LM_TC_VAR || str_.size() <= 1) {
+ if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
os << ' ' << str_ << ' ';
return;
}
void MathStringInset::mathmlize(MathMLStream & os) const
{
+/*
if (code_ == LM_TC_VAR)
os << "<mi> " << str_ << " </mi>";
else if (code_ == LM_TC_CONST)
else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM)
os << "<mtext> " << str_ << " </mtext>";
else
+*/
os << str_;
}
void MathStringInset::write(WriteStream & os) const
{
- if (math_font_name(code_))
- os << '\\' << math_font_name(code_) << '{' << str_ << '}';
- else
- os << str_;
+ os << str_;
}
#ifndef MATH_STRINGINSET_H
#define MATH_STRINGINSET_H
-#include "math_inset.h"
+#include "math_diminset.h"
#ifdef __GNUG__
#pragma interface
\author André Pönitz
*/
-class MathStringInset : public MathInset {
+class MathStringInset : public MathDimInset {
public:
///
MathStringInset();
///
- MathStringInset(string const & s, MathTextCodes t = LM_TC_TEXTRM);
+ explicit MathStringInset(string const & s);
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
- ///
- int ascent() const;
- ///
- int descent() const;
- ///
- int width() const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
string str() const { return str_; }
///
MathStringInset * asStringInset() { return this; }
- /// request "external features"
- void validate(LaTeXFeatures & features) const;
///
void normalize(NormalStream &) const;
public:
/// the string
string str_;
- /// the font to be used on screen
- MathTextCodes code_;
- ///
- mutable LyXFont font_;
};
#endif
}
-void MathSubstackInset::metrics(MathMetricsInfo const & st) const
+void MathSubstackInset::metrics(MathMetricsInfo & mi) const
{
- MathMetricsInfo mi = st;
- if (mi.style == LM_ST_DISPLAY)
- mi.style = LM_ST_TEXT;
- MathGridInset::metrics(mi);
+ if (mi.base.style == LM_ST_DISPLAY) {
+ MathStyleChanger dummy(mi.base, LM_ST_TEXT);
+ MathGridInset::metrics(mi);
+ } else {
+ MathGridInset::metrics(mi);
+ }
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
MathSubstackInset const * asSubstackInset() const { return this; }
}
-namespace {
-
-LyXFont * MathFonts = 0;
-bool font_available[LM_FONT_END];
-bool font_available_initialized[LM_FONT_END];
-
-enum MathFont {
- FONT_IT,
- FONT_SYMBOL,
- FONT_SYMBOLI,
- FONT_BF,
- FONT_TT,
- FONT_RM,
- FONT_SF,
- FONT_CMR,
- FONT_CMSY,
- FONT_CMM,
- FONT_CMEX,
- FONT_MSA,
- FONT_MSB,
- FONT_EUFRAK,
- FONT_FAKEBB,
- FONT_FAKECAL,
- FONT_FAKEFRAK,
- FONT_NUM
-};
-
-void mathed_init_fonts()
-{
- MathFonts = new LyXFont[FONT_NUM];
-
- MathFonts[FONT_IT].setShape(LyXFont::ITALIC_SHAPE);
-
- MathFonts[FONT_SYMBOL].setFamily(LyXFont::SYMBOL_FAMILY);
-
- MathFonts[FONT_SYMBOLI].setFamily(LyXFont::SYMBOL_FAMILY);
- MathFonts[FONT_SYMBOLI].setShape(LyXFont::ITALIC_SHAPE);
-
- MathFonts[FONT_BF].setSeries(LyXFont::BOLD_SERIES);
-
- MathFonts[FONT_TT].setFamily(LyXFont::TYPEWRITER_FAMILY);
- MathFonts[FONT_RM].setFamily(LyXFont::ROMAN_FAMILY);
- MathFonts[FONT_SF].setFamily(LyXFont::SANS_FAMILY);
-
- MathFonts[FONT_CMR].setFamily(LyXFont::CMR_FAMILY);
- MathFonts[FONT_CMSY].setFamily(LyXFont::CMSY_FAMILY);
- MathFonts[FONT_CMM].setFamily(LyXFont::CMM_FAMILY);
- MathFonts[FONT_CMEX].setFamily(LyXFont::CMEX_FAMILY);
- MathFonts[FONT_MSA].setFamily(LyXFont::MSA_FAMILY);
- MathFonts[FONT_MSB].setFamily(LyXFont::MSB_FAMILY);
- MathFonts[FONT_EUFRAK].setFamily(LyXFont::EUFRAK_FAMILY);
-
- MathFonts[FONT_FAKEBB].setFamily(LyXFont::TYPEWRITER_FAMILY);
- MathFonts[FONT_FAKEBB].setSeries(LyXFont::BOLD_SERIES);
-
- MathFonts[FONT_FAKECAL].setFamily(LyXFont::SANS_FAMILY);
- MathFonts[FONT_FAKECAL].setShape(LyXFont::ITALIC_SHAPE);
-
- MathFonts[FONT_FAKEFRAK].setFamily(LyXFont::SANS_FAMILY);
- MathFonts[FONT_FAKEFRAK].setSeries(LyXFont::BOLD_SERIES);
-
- for (int i = 0; i < LM_FONT_END; ++i)
- font_available_initialized[i] = false;
-}
-
-
-LyXFont const & whichFontBaseIntern(MathTextCodes type)
-{
- if (!MathFonts)
- mathed_init_fonts();
-
- switch (type) {
- case LM_TC_SYMB:
- case LM_TC_BOLDSYMB:
- return MathFonts[FONT_SYMBOLI];
-
- case LM_TC_VAR:
- case LM_TC_IT:
- return MathFonts[FONT_IT];
-
- case LM_TC_BF:
- return MathFonts[FONT_BF];
-
- case LM_TC_BB:
- return MathFonts[FONT_MSB];
-
- case LM_TC_CAL:
- return MathFonts[FONT_CMSY];
-
- case LM_TC_TT:
- return MathFonts[FONT_TT];
-
- case LM_TC_BOX:
- case LM_TC_TEXTRM:
- case LM_TC_CONST:
- case LM_TC_TEX:
- case LM_TC_RM:
- return MathFonts[FONT_RM];
-
- case LM_TC_SF:
- return MathFonts[FONT_SF];
-
- case LM_TC_CMR:
- return MathFonts[FONT_CMR];
-
- case LM_TC_CMSY:
- return MathFonts[FONT_CMSY];
-
- case LM_TC_CMM:
- return MathFonts[FONT_CMM];
-
- case LM_TC_CMEX:
- return MathFonts[FONT_CMEX];
-
- case LM_TC_MSA:
- return MathFonts[FONT_MSA];
-
- case LM_TC_MSB:
- return MathFonts[FONT_MSB];
-
- case LM_TC_EUFRAK:
- return MathFonts[FONT_EUFRAK];
-
- default:
- break;
- }
- return MathFonts[1];
-}
-
-
-LyXFont const & whichFontBase(MathTextCodes type)
-{
- if (!MathFonts)
- mathed_init_fonts();
-
- switch (type) {
- case LM_TC_BB:
- if (math_font_available(LM_TC_MSB))
- return MathFonts[FONT_MSB];
- else
- return MathFonts[FONT_FAKEBB];
-
- case LM_TC_CAL:
- if (math_font_available(LM_TC_CMSY))
- return MathFonts[FONT_CMSY];
- else
- return MathFonts[FONT_FAKECAL];
-
- case LM_TC_EUFRAK:
- if (math_font_available(LM_TC_EUFRAK))
- return MathFonts[FONT_EUFRAK];
- else
- return MathFonts[FONT_FAKEFRAK];
-
- default:
- break;
- }
- return whichFontBaseIntern(type);
-}
-
-} // namespace
-
-
-void whichFont(LyXFont & f, MathTextCodes type, MathMetricsInfo const & size)
-{
- f = whichFontBase(type);
- // use actual size
- f.setSize(size.font.size());
-
- switch (size.style) {
- case LM_ST_DISPLAY:
- if (type == LM_TC_BOLDSYMB || type == LM_TC_CMEX) {
- f.incSize();
- f.incSize();
- }
- break;
-
- case LM_ST_TEXT:
- break;
-
- case LM_ST_SCRIPT:
- f.decSize();
- f.decSize();
- break;
-
- case LM_ST_SCRIPTSCRIPT:
- f.decSize();
- f.decSize();
- f.decSize();
- break;
-
- default:
- lyxerr << "Math Error: wrong font size: " << size.style << endl;
- break;
- }
-
- if (type != LM_TC_TEXTRM && type != LM_TC_BOX)
- f.setColor(LColor::math);
-
- if (type == LM_TC_TEX)
- f.setColor(LColor::latex);
-}
-
-
-bool math_font_available(MathTextCodes type)
-{
- if (!font_available_initialized[type]) {
- font_available_initialized[type] = true;
- font_available[type] = fontloader.available(whichFontBaseIntern(type));
- if (!font_available[type])
- lyxerr[Debug::FONT] << "Math font " << type << " not available.\n";
- }
- return font_available[type];
-}
-
namespace {
};
+double const ring[] = {
+ 2, 5,
+ 0.5, 0.8, 0.8, 0.5, 0.5, 0.2, 0.2, 0.5, 0.5, 0.8,
+ 0
+};
+
+
double const vert[] = {
1, 0.5, 0.05, 0.5, 0.95,
0
};
-double const ring[] = {
- 2, 5,
- 0.5, 0.8, 0.8, 0.5, 0.5, 0.2, 0.2, 0.5, 0.5, 0.8,
- 0
-};
-
-
double const tilde[] = {
2, 4,
0.05, 0.8, 0.25, 0.2, 0.75, 0.8, 0.95, 0.2,
named_deco_struct deco_table[] = {
// Decorations
- {"widehat", angle, 3 },
- {"widetilde", tilde, 0 },
- {"underbar", hline, 0 },
- {"underline", hline, 0 },
- {"overline", hline, 0 },
- {"underbrace", brace, 1 },
- {"overbrace", brace, 3 },
- {"overleftarrow", arrow, 1 },
- {"overrightarrow", arrow, 3 },
- {"overleftrightarrow", udarrow, 1 },
- {"xleftarrow", arrow, 1 },
- {"xrightarrow", arrow, 3 },
- {"underleftarrow", arrow, 1 },
- {"underrightarrow", arrow, 3 },
- {"underleftrightarrow",udarrow, 1 },
+ {"widehat", angle, 3 },
+ {"widetilde", tilde, 0 },
+ {"underbar", hline, 0 },
+ {"underline", hline, 0 },
+ {"overline", hline, 0 },
+ {"underbrace", brace, 1 },
+ {"overbrace", brace, 3 },
+ {"overleftarrow", arrow, 1 },
+ {"overrightarrow", arrow, 3 },
+ {"overleftrightarrow", udarrow, 1 },
+ {"xleftarrow", arrow, 1 },
+ {"xrightarrow", arrow, 3 },
+ {"underleftarrow", arrow, 1 },
+ {"underrightarrow", arrow, 3 },
+ {"underleftrightarrow", udarrow, 1 },
// Delimiters
{"(", parenth, 0 },
-void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
+void mathed_draw_deco(MathPainterInfo & pain, int x, int y, int w, int h,
const string & name)
{
if (name == ".") {
- pain.line(x + w/2, y, x + w/2, y + h,
+ pain.pain.line(x + w/2, y, x + w/2, y + h,
LColor::mathcursor, Painter::line_onoffdash);
return;
}
else
mt.transform(xx, yy);
mt.transform(x2, y2);
- pain.line(x + int(xx), y + int(yy), x + int(x2), y + int(y2),
+ pain.pain.line(x + int(xx), y + int(yy), x + int(x2), y + int(y2),
LColor::math);
} else {
int xp[32];
yp[j] = y + int(yy);
// lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]";
}
- pain.lines(xp, yp, n, LColor::math);
+ pain.pain.lines(xp, yp, n, LColor::math);
}
}
}
-void mathed_draw_framebox(Painter & pain, int x, int y, MathInset const * p)
+void mathed_draw_framebox(MathPainterInfo & pain, int x, int y, MathInset const * p)
{
if (mathcursor && mathcursor->isInside(p))
- pain.rectangle(x, y - p->ascent(), p->width(), p->height(),
+ pain.pain.rectangle(x, y - p->ascent(), p->width(), p->height(),
LColor::mathframe);
}
// In the future maybe we use a better fonts renderer
-void drawStr(Painter & pain, LyXFont const & font,
+void drawStr(MathPainterInfo & pain, LyXFont const & font,
int x, int y, string const & str)
{
- pain.text(x, y, str, font);
+ pain.pain.text(x, y, str, font);
}
-void drawChar(Painter & pain, LyXFont const & font, int x, int y, char c)
+void drawStrRed(MathPainterInfo & pi, int x, int y, string const & str)
{
- pain.text(x, y, c, font);
+ LyXFont f = pi.base.font;
+ f.setColor(LColor::latex);
+ pi.pain.text(x, y, str, f);
}
-// decrease math size for super- and subscripts
-void smallerStyleScript(MathMetricsInfo & st)
+void drawStrBlack(MathPainterInfo & pi, int x, int y, string const & str)
{
- switch (st.style) {
- case LM_ST_DISPLAY:
- case LM_ST_TEXT: st.style = LM_ST_SCRIPT; break;
- default: st.style = LM_ST_SCRIPTSCRIPT;
- }
+ LyXFont f = pi.base.font;
+ f.setColor(LColor::black);
+ pi.pain.text(x, y, str, f);
}
-// decrease math size for fractions
-void smallerStyleFrac(MathMetricsInfo & st)
+void drawChar(MathPainterInfo & pi, LyXFont const & font, int x, int y, char c)
{
- switch (st.style) {
- case LM_ST_DISPLAY: st.style = LM_ST_TEXT; break;
- case LM_ST_TEXT: st.style = LM_ST_SCRIPT; break;
- default: st.style = LM_ST_SCRIPTSCRIPT;
- }
+ pi.pain.text(x, y, c, font);
}
}
-char const * math_font_name(MathTextCodes code)
-{
- static char const * theFontNames[] = {
- "mathrm",
- "mathcal",
- "mathfrak",
- "mathbf",
- "mathbb",
- "mathsf",
- "mathtt",
- "mathit",
- "textrm"
- };
-
- if (code >= LM_TC_RM && code <= LM_TC_TEXTRM)
- return theFontNames[code - LM_TC_RM];
- return 0;
-}
-
string convertDelimToLatexName(string const & name)
{
if (name == "(")
return name;
return "\\" + name + " ";
}
+
+
+
+
+struct fontinfo {
+ string cmd_;
+ LyXFont::FONT_FAMILY family_;
+ LyXFont::FONT_SERIES series_;
+ LyXFont::FONT_SHAPE shape_;
+ LColor::color color_;
+};
+
+
+LyXFont::FONT_FAMILY const def_family = LyXFont::INHERIT_FAMILY;
+LyXFont::FONT_SERIES const def_series = LyXFont::INHERIT_SERIES;
+LyXFont::FONT_SHAPE const def_shape = LyXFont::INHERIT_SHAPE;
+
+
+
+fontinfo fontinfos[] = {
+ {"cmex", LyXFont::CMEX_FAMILY, def_series, def_shape, LColor::math},
+ {"cmm", LyXFont::CMM_FAMILY, def_series, def_shape, LColor::math},
+ {"cmr", LyXFont::CMR_FAMILY, def_series, def_shape, LColor::math},
+ {"cmsy", LyXFont::CMSY_FAMILY, def_series, def_shape, LColor::math},
+ {"eufrak", LyXFont::EUFRAK_FAMILY, def_series, def_shape, LColor::math},
+ {"mathbf", def_family, LyXFont::BOLD_SERIES, def_shape, LColor::math},
+ {"mathcal",LyXFont::CMSY_FAMILY, def_series, def_shape, LColor::math},
+ {"mathnormal", def_family,def_series, def_shape, LColor::math},
+ {"mathrm", LyXFont::ROMAN_FAMILY, def_series, def_shape, LColor::math},
+ {"mathsf", LyXFont::SANS_FAMILY, def_series, def_shape, LColor::math},
+ {"msa", LyXFont::MSA_FAMILY, def_series, def_shape, LColor::math},
+ {"msb", LyXFont::MSB_FAMILY, def_series, def_shape, LColor::math},
+ {"textbf", def_family, LyXFont::BOLD_SERIES, def_shape, LColor::black},
+ {"textit", def_family, def_series, LyXFont::ITALIC_SHAPE, LColor::black},
+ {"textmd", def_family, LyXFont::MEDIUM_SERIES, def_shape, LColor::black},
+ {"textnormal", def_family, def_series, def_shape, LColor::black},
+ {"textrm", LyXFont::ROMAN_FAMILY, def_series, def_shape, LColor::black},
+ {"textsc", def_family, def_series, LyXFont::SMALLCAPS_SHAPE, LColor::black},
+ {"textsf", LyXFont::SANS_FAMILY, def_series, def_shape, LColor::black},
+ {"textsl", def_family, def_series, LyXFont::SLANTED_SHAPE, LColor::black},
+ {"texttt", LyXFont::TYPEWRITER_FAMILY, def_series, def_shape, LColor::black},
+ {"textup", def_family, def_series, LyXFont::UP_SHAPE, LColor::black},
+
+ {"lyxtex", def_family, def_series, def_shape, LColor::latex},
+ {"lyxsymbol", LyXFont::SYMBOL_FAMILY, def_series, def_shape, LColor::math},
+ {"lyxitsymbol", LyXFont::SYMBOL_FAMILY, def_series, LyXFont::ITALIC_SHAPE, LColor::math},
+};
+
+
+fontinfo * searchFont(string const & name)
+{
+ int const n = sizeof(fontinfos) / sizeof(fontinfo);
+ //lyxerr << "searching font '" << name << "'\n";
+ for (int i = 0; i < n; ++i)
+ if (fontinfos[i].cmd_ == name) {
+ //lyxerr << "found '" << i << "'\n";
+ return fontinfos + i;
+ }
+ return searchFont("mathnormal");
+}
+
+
+void augmentFont(LyXFont & font, string const & name)
+{
+ static bool initialized = false;
+
+ if (!initialized) {
+ initialized = true;
+
+ LyXFont f1;
+ augmentFont(f1, "msb");
+ if (!fontloader.available(f1)) {
+ lyxerr << "faking msb\n";
+ fontinfo * info = searchFont("msb");
+ info->family_ = LyXFont::TYPEWRITER_FAMILY;
+ info->series_ = LyXFont::BOLD_SERIES;
+ }
+
+ LyXFont f2;
+ augmentFont(f2, "msex");
+ if (!fontloader.available(f2)) {
+ lyxerr << "faking msex\n";
+ fontinfo * info = searchFont("msex");
+ info->family_ = LyXFont::SANS_FAMILY;
+ info->series_ = LyXFont::BOLD_SERIES;
+ info->shape_ = LyXFont::ITALIC_SHAPE;
+ }
+
+ //{"fakebb", LyXFont::TYPEWRITER_FAMILY, LyXFont::BOLD_SERIES,
+ // LyXFont::UP_SHAPE, LColor::math},
+ //{"fakecal", LyXFont::SANS_FAMILY, LyXFont::MEDIUM_SERIES,
+ // LyXFont::ITALIC_SHAPE, LColor::math},
+ //{"fakefrak", LyXFont::SANS_FAMILY, LyXFont::BOLD_SERIES,
+ // LyXFont::ITALIC_SHAPE, LColor::math}
+
+ }
+
+
+ fontinfo * info = searchFont(name);
+ if (info->family_ != def_family)
+ font.setFamily(info->family_);
+
+ if (info->series_ != def_series)
+ font.setSeries(info->series_);
+
+ if (info->shape_ != def_shape)
+ font.setShape(info->shape_);
+
+ if (info->color_ != LColor::none)
+ font.setColor(info->color_);
+}
+
+
+bool math_font_available(string const & /*name*/)
+{
+ return true;
+}
#ifndef MATH_SUPPORT_H
#define MATH_SUPPORT_H
-#include "math_defs.h"
#include "LString.h"
-class Painter;
+class MathPainterInfo;
class TextPainter;
class latexkeys;
class MathMetricsInfo;
int mathed_char_ascent(LyXFont const &, unsigned char c);
int mathed_char_descent(LyXFont const &, unsigned char c);
-void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
+void mathed_draw_deco(MathPainterInfo & pain, int x, int y, int w, int h,
string const & name);
-void mathed_draw_framebox(Painter & pain, int x, int y, MathInset const *);
+void mathed_draw_framebox(MathPainterInfo & pain, int x, int y, MathInset const *);
void mathed_string_dim(LyXFont const &,
string const & s, int & asc, int & des, int & wid);
int mathed_string_ascent(LyXFont const &, string const & s);
int mathed_string_descent(LyXFont const &, string const & s);
-void drawStr(Painter & pain, LyXFont const &, int x, int y, string const & s);
-void drawChar(Painter & pain, LyXFont const & font, int x, int y, char c);
+void drawStr(MathPainterInfo & pain,
+ LyXFont const &, int x, int y, string const & s);
+void drawStrRed(MathPainterInfo & pain, int x, int y, string const & s);
+void drawStrBlack(MathPainterInfo & pain, int x, int y, string const & s);
+void drawChar(MathPainterInfo & pain,
+ LyXFont const & font, int x, int y, char c);
void math_font_max_dim(LyXFont const &, int & asc, int & desc);
-bool math_font_available(MathTextCodes code);
-
-// decrease math size for super- and subscripts
-void smallerStyleScript(MathMetricsInfo &);
-
-// decrease math size for fractions
-void smallerStyleFrac(MathMetricsInfo & st);
-
-char const * math_font_name(MathTextCodes type);
+bool math_font_available(string const & name);
string convertDelimToLatexName(string const & name);
-void whichFont(LyXFont & f, MathTextCodes type, MathMetricsInfo const & size);
+void augmentFont(LyXFont & f, string const & cmd);
+
#endif
}
-MathTextCodes MathSymbolInset::code() const
-{
- switch (sym_->token) {
- case LM_TK_CMR:
- return LM_TC_CMR;
- case LM_TK_CMSY:
- return LM_TC_CMSY;
- case LM_TK_CMM:
- return LM_TC_CMM;
- case LM_TK_CMEX:
- return LM_TC_CMEX;
- case LM_TK_MSA:
- return LM_TC_MSA;
- case LM_TK_MSB:
- return LM_TC_MSB;
- default:
- return LM_TC_SYMB;
- }
-}
-
-
-MathTextCodes MathSymbolInset::code2() const
-{
- if (sym_->token == LM_TK_CMEX)
- return LM_TC_BOLDSYMB;
- else
- return LM_TC_SYMB;
-}
-
-
string MathSymbolInset::name() const
{
return sym_->name;
}
-void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
-{
- LyXFont font;
- mi_ = mi;
- MathTextCodes c = code();
- if (sym_->latex_font_id > 0 && math_font_available(c)) {
- whichFont(font, c, mi_);
- mathed_char_dim(font, char(sym_->latex_font_id), ascent_, descent_, width_);
- if (c == LM_TC_CMEX) {
- h_ = 4 * descent_ / 5;
- ascent_ += h_;
- descent_ -= h_;
- }
- } else {
- if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)) {
- whichFont(font, code2(), mi_);
- mathed_char_dim(font, char(sym_->id), ascent_, descent_, width_);
- } else {
- whichFont(font, LM_TC_TEX, mi_);
- mathed_string_dim(font, sym_->name, ascent_, descent_, width_);
- }
+void MathSymbolInset::metrics(MathMetricsInfo & mi) const
+{
+ //lyxerr << "metrics: symbol: '" << sym_->name
+ // << "' in font: '" << sym_->inset
+ // << "' drawn as: '" << sym_->draw
+ // << "'\n";
+ MathFontSetChanger dummy(mi.base, sym_->inset.c_str());
+ mathed_string_dim(mi.base.font, sym_->draw, ascent_, descent_, width_);
+ if (sym_->inset == "cmex") {
+ h_ = 4 * descent_ / 5;
+ ascent_ += h_;
+ descent_ -= h_;
}
if (isRelOp())
width_ += 6;
+ scriptable_ = (mi.base.style == LM_ST_DISPLAY && sym_->inset == "cmex");
}
-void MathSymbolInset::draw(Painter & pain, int x, int y) const
+void MathSymbolInset::draw(MathPainterInfo & pi, int x, int y) const
{
+ //lyxerr << "metrics: symbol: '" << sym_->name
+ // << "' in font: '" << sym_->inset
+ // << "' drawn as: '" << sym_->draw
+ // << "'\n";
if (isRelOp())
x += 3;
- MathTextCodes Code = code();
- LyXFont font;
- if (sym_->latex_font_id > 0 && math_font_available(Code)) {
- whichFont(font, Code, mi_);
- drawChar(pain, font, x, y - h_, char(sym_->latex_font_id));
- } else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)){
- whichFont(font, code2(), mi_);
- drawChar(pain, font, x, y, char(sym_->id));
- } else {
- whichFont(font, LM_TC_TEX, mi_);
- drawStr(pain, font, x, y, sym_->name);
- }
+ MathFontSetChanger dummy(pi.base, sym_->inset.c_str());
+ drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
}
bool MathSymbolInset::isRelOp() const
{
- return sym_->type == "mathrel";
+ return sym_->extra == "mathrel";
}
bool MathSymbolInset::isScriptable() const
{
- return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
+ return scriptable_;
}
bool MathSymbolInset::takesLimits() const
{
- return sym_->token == LM_TK_CMEX;
+ return sym_->inset == "cmex" || sym_->inset == "lyxboldsymb";
}
+
void MathSymbolInset::validate(LaTeXFeatures & features) const
{
- if (sym_->token == LM_TK_MSA || sym_->token == LM_TK_MSB)
+ if (sym_->inset == "msa" || sym_->inset == "msb")
features.require("amssymb");
}
+
void MathSymbolInset::normalize(NormalStream & os) const
{
os << "[symbol " << name() << "]";
void MathSymbolInset::mathmlize(MathMLStream & os) const
{
- char const * type = MathMLtype(sym_->type);
+ char const * type = MathMLtype(sym_->extra);
os << '<' << type << "> ";
if (sym_->xmlname == "x") // unknown so far
os << name();
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
bool isRelOp() const;
/// do we take scripts?
void infoize(std::ostream & os) const;
private:
- ///
- MathTextCodes code() const;
- ///
- MathTextCodes code2() const;
-
///
latexkeys const * sym_;
///
mutable int h_;
///
- mutable MathMetricsInfo mi_;
+ mutable bool scriptable_;
};
#endif
}
-void MathUndersetInset::metrics(MathMetricsInfo const & mi) const
+void MathUndersetInset::metrics(MathMetricsInfo & mi) const
{
- MathMetricsInfo m = mi;
- smallerStyleFrac(m);
- xcell(0).metrics(m);
xcell(1).metrics(mi);
+ MathFracChanger dummy(mi.base);
+ xcell(0).metrics(mi);
width_ = max(xcell(0).width(), xcell(1).width()) + 4;
ascent_ = xcell(1).ascent();
descent_ = xcell(1).descent() + xcell(0).height() + 4;
}
-void MathUndersetInset::draw(Painter & pain, int x, int y) const
+void MathUndersetInset::draw(MathPainterInfo & pi, int x, int y) const
{
int m = x + width() / 2;
int yo = y + xcell(1).descent() + xcell(0).ascent() + 1;
- xcell(0).draw(pain, m - xcell(0).width() / 2, yo);
- xcell(1).draw(pain, m - xcell(1).width() / 2, y);
+ xcell(1).draw(pi, m - xcell(1).width() / 2, y);
+ MathFracChanger dummy(pi.base);
+ xcell(0).draw(pi, m - xcell(0).width() / 2, yo);
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
#endif
#include "math_unknowninset.h"
-#include "frontends/Painter.h"
#include "math_support.h"
#include "math_mathmlstream.h"
#include "math_streamstr.h"
-extern LyXFont WhichFont(short type, int size);
-
-
-MathUnknownInset::MathUnknownInset(string const & nm)
- : name_(nm)
+MathUnknownInset::MathUnknownInset(string const & nm, bool final, bool black)
+ : name_(nm), final_(final), black_(black)
{}
}
-void MathUnknownInset::setName(string const & n)
+string & MathUnknownInset::name()
{
- name_ = n;
+ return name_;
}
}
-void MathUnknownInset::metrics(MathMetricsInfo const & mi) const
+void MathUnknownInset::metrics(MathMetricsInfo & mi) const
+{
+ mathed_string_dim(mi.base.font, name_, ascent_, descent_, width_);
+}
+
+
+void MathUnknownInset::draw(MathPainterInfo & pi, int x, int y) const
+{
+ if (black_)
+ drawStrBlack(pi, x, y, name_);
+ else
+ drawStrRed(pi, x, y, name_);
+}
+
+
+void MathUnknownInset::finalize()
{
- whichFont(font_, LM_TC_TEX, mi);
- mathed_string_dim(font_, name_, ascent_, descent_, width_);
+ final_ = true;
}
-void MathUnknownInset::draw(Painter & pain, int x, int y) const
+bool MathUnknownInset::final() const
{
- drawStr(pain, font_, x, y, name_);
+ return final_;
}
#define MATH_UNKNOWNINSET_H
#include "math_diminset.h"
-#include "math_defs.h"
#ifdef __GNUG__
#pragma interface
class MathUnknownInset : public MathDimInset {
public:
///
- explicit MathUnknownInset(string const & name);
+ explicit MathUnknownInset(string const & name,
+ bool final = true, bool black = false);
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
+ ///
+ string & name();
///
string const & name() const;
/// identifies UnknownInsets
MathUnknownInset const * asUnknownInset() const { return this; }
- ///
- void setName(string const &);
+ /// identifies UnknownInsets
+ MathUnknownInset * asUnknownInset() { return this; }
///
bool match(MathInset * p) const;
void octavize(OctaveStream &) const;
///
void write(WriteStream &) const;
+ ///
+ void finalize();
+ ///
+ bool final() const;
private:
///
string name_;
+ /// are we finished creating the name?
+ bool final_;
///
- mutable LyXFont font_;
+ bool black_;
};
#endif
}
-void MathXArrowInset::metrics(MathMetricsInfo const & st) const
+void MathXArrowInset::metrics(MathMetricsInfo & mi) const
{
- MathMetricsInfo mi = st;
- smallerStyleScript(mi);
+ //MathMetricsInfo mi = st;
+ //smallerStyleScript(mi);
xcell(0).metrics(mi);
width_ = xcell(0).width() + 10;
ascent_ = xcell(0).height() + 10;
}
-void MathXArrowInset::draw(Painter & pain, int x, int y) const
+void MathXArrowInset::draw(MathPainterInfo & pain, int x, int y) const
{
xcell(0).draw(pain, x + 5, y - 10);
mathed_draw_deco(pain, x + 1, y - 7, width_ - 2, 5, name_);
///
MathInset * clone() const;
///
- void draw(Painter &, int x, int y) const;
+ void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
void normalize(NormalStream & os) const;
}
-void MathXArray::metrics(MathMetricsInfo const & mi) const
+void MathXArray::metrics(MathMetricsInfo & mi) const
{
//if (clean_)
// return;
drawn_ = false;
if (data_.empty()) {
- LyXFont font;
- whichFont(font, LM_TC_VAR, mi);
- mathed_char_dim(font, 'I', ascent_, descent_, width_);
+ mathed_char_dim(mi.base.font, 'I', ascent_, descent_, width_);
return;
}
}
-void MathXArray::draw(Painter & pain, int x, int y) const
+void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
{
//if (drawn_ && x == xo_ && y == yo_)
// return;
if (y + descent_ <= 0) // don't draw above the workarea
return;
- if (y - ascent_ >= pain.paperHeight()) // don't draw below the workarea
+ if (y - ascent_ >= pi.pain.paperHeight()) // don't draw below the workarea
return;
if (x + width_ <= 0) // don't draw left of workarea
return;
- if (x >= pain.paperWidth()) // don't draw right of workarea
+ if (x >= pi.pain.paperWidth()) // don't draw right of workarea
return;
const_iterator it = begin(), et = end();
if (it == et) {
- pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
+ pi.pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
return;
}
MathInset const * p = it->nucleus();
MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
if (q) {
- q->draw(p, pain, x, y);
+ q->draw(p, pi, x, y);
x += q->width2(p);
++it;
} else {
- p->draw(pain, x, y);
+ p->draw(pi, x, y);
x += p->width();
}
}
#pragma interface
#endif
-class Painter;
+class MathPainterInfo;
class TextPainter;
/// constructor
MathXArray();
/// rebuild cached metrics information
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
/// redraw cell using cache metrics information
- void draw(Painter & pain, int x, int y) const;
+ void draw(MathPainterInfo & pain, int x, int y) const;
/// rebuild cached metrics information
void metricsT(TextMetricsInfo const & st) const;
/// redraw cell using cache metrics information
}
-void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const
+void MathXYArrowInset::metrics(MathMetricsInfo & mi) const
{
MathNestInset::metrics(mi);
- mi_ = mi;
- whichFont(font_, LM_TC_TEXTRM, mi);
+ mi_ = mi;
+ MathFontSetChanger dummy(mi.base, "textrm");
target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
if (editing()) {
- int w = mathed_string_width(font_, "target: ");
+ int w = mathed_string_width(mi.base.font, "target: ");
width_ = w + max(xcell(0).width(), xcell(1).width());
ascent_ = xcell(0).ascent();
descent_ = xcell(0).descent() + xcell(1).height() + 10;
}
-void MathXYArrowInset::draw(Painter & pain, int x, int y) const
+void MathXYArrowInset::draw(MathPainterInfo & pi, int x, int y) const
{
metrics(mi_);
+ MathFontSetChanger dummy(pi.base, "textrm");
if (editing()) {
int lasc;
int ldes;
int lwid;
- mathed_string_dim(font_, "target: ", lasc, ldes, lwid);
+ mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
- xcell(0).draw(pain, x + lwid, y);
- drawStr(pain, font_, x + 3, y, "target");
+ xcell(0).draw(pi, x + lwid, y);
+ drawStr(pi, pi.base.font, x + 3, y, "target");
y += max(xcell(0).descent(), ldes) + 5;
y += max(xcell(1).ascent(), lasc) + 5;
- xcell(1).draw(pain, x + lwid, y);
- drawStr(pain, font_, x + 3, y, "label");
+ xcell(1).draw(pi, x + lwid, y);
+ drawStr(pi, pi.base.font, x + 3, y, "label");
} else {
- //drawStr(pain, font_, x, y, "X");
+ //drawStr(pi, font_, x, y, "X");
MathXArray const & s = sourceCell();
MathXArray const & t = targetCell();
- pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
- xcell(1).draw(pain, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
+ pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
+ xcell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
}
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
- void draw(Painter & pain, int x, int y) const;
+ void draw(MathPainterInfo & pain, int x, int y) const;
///
MathXYArrowInset * asXYArrowInset() { return this; }
}
-void MathXYMatrixInset::metrics(MathMetricsInfo const & st) const
+void MathXYMatrixInset::metrics(MathMetricsInfo & st) const
{
MathMetricsInfo mi = st;
- if (mi.style == LM_ST_DISPLAY)
- mi.style = LM_ST_TEXT;
+ if (mi.base.style == LM_ST_DISPLAY)
+ mi.base.style = LM_ST_TEXT;
MathGridInset::metrics(mi);
}
///
MathInset * clone() const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void metrics(MathMetricsInfo & st) const;
///
MathXYMatrixInset const * asXYMatrixInset() const { return this; }
///