From fe87869cb763c613c4dc36294efbd8edff175d54 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 30 May 2002 07:09:54 +0000 Subject: [PATCH] fonts as insets git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4289 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 5 + src/mathed/Makefile.am | 5 +- src/mathed/formula.C | 16 +- src/mathed/formulabase.C | 76 +++-- src/mathed/formulabase.h | 5 +- src/mathed/formulamacro.C | 8 +- src/mathed/math_amsarrayinset.C | 18 +- src/mathed/math_amsarrayinset.h | 4 +- src/mathed/math_arrayinset.C | 10 +- src/mathed/math_arrayinset.h | 2 +- src/mathed/math_biginset.C | 10 +- src/mathed/math_biginset.h | 4 +- src/mathed/math_binaryopinset.C | 6 +- src/mathed/math_binaryopinset.h | 4 +- src/mathed/math_binominset.C | 16 +- src/mathed/math_binominset.h | 4 +- src/mathed/math_boxinset.C | 2 +- src/mathed/math_boxinset.h | 2 +- src/mathed/math_braceinset.C | 15 +- src/mathed/math_braceinset.h | 6 +- src/mathed/math_casesinset.C | 5 +- src/mathed/math_casesinset.h | 4 +- src/mathed/math_charinset.C | 105 +++---- src/mathed/math_charinset.h | 24 +- src/mathed/math_cursor.C | 140 ++++----- src/mathed/math_cursor.h | 23 +- src/mathed/math_decorationinset.C | 4 +- src/mathed/math_decorationinset.h | 4 +- src/mathed/math_defs.h | 61 +--- src/mathed/math_deliminset.C | 14 +- src/mathed/math_deliminset.h | 4 +- src/mathed/math_diffinset.C | 4 +- src/mathed/math_diffinset.h | 4 +- src/mathed/math_dotsinset.C | 8 +- src/mathed/math_dotsinset.h | 4 +- src/mathed/math_exfuncinset.C | 9 +- src/mathed/math_exfuncinset.h | 6 +- src/mathed/math_exintinset.C | 4 +- src/mathed/math_exintinset.h | 4 +- src/mathed/math_extern.C | 26 +- src/mathed/math_factory.C | 349 +++++++++++++++++++---- src/mathed/math_factory.h | 1 - src/mathed/math_fontinset.C | 89 ++++++ src/mathed/math_fontinset.h | 46 +++ src/mathed/math_fracinset.C | 18 +- src/mathed/math_fracinset.h | 4 +- src/mathed/math_funcinset.C | 7 +- src/mathed/math_funcinset.h | 3 +- src/mathed/math_funcliminset.C | 13 +- src/mathed/math_funcliminset.h | 6 +- src/mathed/math_gridinset.C | 8 +- src/mathed/math_gridinset.h | 4 +- src/mathed/math_hash.C | 244 ---------------- src/mathed/math_hullinset.C | 35 ++- src/mathed/math_hullinset.h | 6 +- src/mathed/math_inset.C | 4 +- src/mathed/math_inset.h | 17 +- src/mathed/math_kerninset.C | 4 +- src/mathed/math_kerninset.h | 4 +- src/mathed/math_lefteqninset.C | 4 +- src/mathed/math_lefteqninset.h | 4 +- src/mathed/math_limitopinset.C | 4 +- src/mathed/math_limitopinset.h | 4 +- src/mathed/math_macro.C | 9 +- src/mathed/math_macro.h | 4 +- src/mathed/math_macroarg.C | 27 +- src/mathed/math_macroarg.h | 10 +- src/mathed/math_macrotable.C | 20 +- src/mathed/math_macrotemplate.C | 8 +- src/mathed/math_macrotemplate.h | 4 +- src/mathed/math_matrixinset.h | 2 +- src/mathed/math_metricsinfo.C | 149 ++++++++++ src/mathed/math_metricsinfo.h | 111 ++++++-- src/mathed/math_nestinset.C | 20 +- src/mathed/math_nestinset.h | 8 +- src/mathed/math_notinset.C | 24 +- src/mathed/math_notinset.h | 6 +- src/mathed/math_parser.C | 74 +++-- src/mathed/math_parser.h | 97 +------ src/mathed/math_rootinset.C | 6 +- src/mathed/math_rootinset.h | 4 +- src/mathed/math_scriptinset.C | 29 +- src/mathed/math_scriptinset.h | 8 +- src/mathed/math_sizeinset.C | 20 +- src/mathed/math_sizeinset.h | 5 +- src/mathed/math_spaceinset.C | 6 +- src/mathed/math_spaceinset.h | 5 +- src/mathed/math_specialcharinset.C | 28 +- src/mathed/math_specialcharinset.h | 16 +- src/mathed/math_sqrtinset.C | 6 +- src/mathed/math_sqrtinset.h | 4 +- src/mathed/math_stackrelinset.C | 14 +- src/mathed/math_stackrelinset.h | 4 +- src/mathed/math_stringinset.C | 54 +--- src/mathed/math_stringinset.h | 22 +- src/mathed/math_substackinset.C | 12 +- src/mathed/math_substackinset.h | 2 +- src/mathed/math_support.C | 437 +++++++++++------------------ src/mathed/math_support.h | 28 +- src/mathed/math_symbolinset.C | 96 ++----- src/mathed/math_symbolinset.h | 11 +- src/mathed/math_undersetinset.C | 14 +- src/mathed/math_undersetinset.h | 4 +- src/mathed/math_unknowninset.C | 36 ++- src/mathed/math_unknowninset.h | 22 +- src/mathed/math_xarrowinset.C | 8 +- src/mathed/math_xarrowinset.h | 4 +- src/mathed/math_xdata.C | 18 +- src/mathed/math_xdata.h | 6 +- src/mathed/math_xyarrowinset.C | 27 +- src/mathed/math_xyarrowinset.h | 4 +- src/mathed/math_xymatrixinset.C | 6 +- src/mathed/math_xymatrixinset.h | 2 +- 113 files changed, 1513 insertions(+), 1581 deletions(-) create mode 100644 src/mathed/math_fontinset.C create mode 100644 src/mathed/math_fontinset.h delete mode 100644 src/mathed/math_hash.C diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index cd5999f8a7..d9a7e65872 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,8 @@ + +2002-05-30 André Pönitz + + * *.[Ch]: "fonts as inset" + 2002-05-29 Lars Gullik Bjønnes * switch from SigC signals to boost::signals. diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 15659663aa..29ceacc6c7 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -58,17 +58,16 @@ libmathed_la_SOURCES = \ 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 \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index f79bc5f3a5..e0928cc642 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -353,19 +353,23 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font, 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(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 @@ -556,7 +560,7 @@ void InsetFormula::handleExtern(const string & arg) mathcursor->last(); mathcursor->stripFromLastEqualSign(); ar = mathcursor->cursor().cell(); - mathcursor->insert(MathAtom(new MathCharInset('=', LM_TC_VAR))); + mathcursor->insert('='); //lyxerr << "use whole cell: " << ar << "\n"; } diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 7b9a9e2c1c..2258fa55ae 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -41,6 +41,7 @@ #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" @@ -68,6 +69,7 @@ int first_x; int first_y; + bool openNewInset(BufferView * bv, UpdatableInset * new_inset) { if (!bv->insertInset(new_inset)) { @@ -91,6 +93,7 @@ InsetFormulaBase::InsetFormulaBase() //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n"; //lyxerr << "sizeof(MathMetricsInfo): " << sizeof(MathMetricsInfo) << "\n"; //lyxerr << "sizeof(MathCharInset): " << sizeof(MathCharInset) << "\n"; + //lyxerr << "sizeof(LyXFont): " << sizeof(LyXFont) << "\n"; } @@ -116,6 +119,21 @@ void InsetFormulaBase::mutateToText() } +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 {} @@ -132,7 +150,12 @@ void InsetFormulaBase::metrics(BufferView * bv) 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); } @@ -170,20 +193,6 @@ void InsetFormulaBase::edit(BufferView * bv, bool front) } -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) { @@ -564,27 +573,27 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, 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 @@ -724,6 +733,10 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, result = UNDISPATCHED; break; + case LFUN_INSET_TOGGLE: + mathcursor->insetToggle(); + break; + default: result = UNDISPATCHED; } @@ -748,10 +761,12 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, } -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 @@ -899,8 +914,9 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display) // 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; diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 1f3f215792..a91eed0b38 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -19,7 +19,6 @@ #pragma interface #endif -#include #include "insets/inset.h" #include "frontends/mouse_state.h" #include "lyxfont.h" @@ -27,6 +26,8 @@ // only for getType(): #include "math_defs.h" +#include + class Buffer; class BufferView; class MathAtom; @@ -134,7 +135,7 @@ protected: /// 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_; diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index 8eb819d6ba..7e0493644d 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -167,7 +167,7 @@ MathInsetTypes InsetFormulaMacro::getType() const 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 @@ -179,14 +179,14 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f, 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(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); diff --git a/src/mathed/math_amsarrayinset.C b/src/mathed/math_amsarrayinset.C index 367c44669d..f221f419f0 100644 --- a/src/mathed/math_amsarrayinset.C +++ b/src/mathed/math_amsarrayinset.C @@ -56,22 +56,22 @@ char const * MathAMSArrayInset::name_right() const } -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()); } diff --git a/src/mathed/math_amsarrayinset.h b/src/mathed/math_amsarrayinset.h index 6f9d39809f..eb24eff9fe 100644 --- a/src/mathed/math_amsarrayinset.h +++ b/src/mathed/math_amsarrayinset.h @@ -18,9 +18,9 @@ public: /// 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; } diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index b9e442d8fd..d785b4cede 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -65,12 +65,12 @@ MathInset * MathArrayInset::clone() const } -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); } diff --git a/src/mathed/math_arrayinset.h b/src/mathed/math_arrayinset.h index 8a715370d2..64c7d6f169 100644 --- a/src/mathed/math_arrayinset.h +++ b/src/mathed/math_arrayinset.h @@ -23,7 +23,7 @@ public: /// MathInset * clone() const; /// - void metrics(MathMetricsInfo const & st) const; + void metrics(MathMetricsInfo & st) const; /// MathArrayInset * asArrayInset() { return this; } diff --git a/src/mathed/math_biginset.C b/src/mathed/math_biginset.C index cff9a7d239..71e13e0723 100644 --- a/src/mathed/math_biginset.C +++ b/src/mathed/math_biginset.C @@ -40,11 +40,9 @@ double MathBigInset::increase() const } -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); @@ -52,9 +50,9 @@ void MathBigInset::metrics(MathMetricsInfo const & mi) const } -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_); } diff --git a/src/mathed/math_biginset.h b/src/mathed/math_biginset.h index daf0078db0..2d16590c87 100644 --- a/src/mathed/math_biginset.h +++ b/src/mathed/math_biginset.h @@ -20,11 +20,11 @@ public: /// 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; diff --git a/src/mathed/math_binaryopinset.C b/src/mathed/math_binaryopinset.C index 9a447379ad..aaac72a186 100644 --- a/src/mathed/math_binaryopinset.C +++ b/src/mathed/math_binaryopinset.C @@ -5,7 +5,7 @@ #endif #include "math_binaryopinset.h" -#include "frontends/Painter.h" +#include "MathPainterInfo.h" #include "support/LOstream.h" #include "math_support.h" #include "math_mathmlstream.h" @@ -31,7 +31,7 @@ int MathBinaryOpInset::opwidth() const } -void MathBinaryOpInset::metrics(MathMetricsInfo const & mi) const +void MathBinaryOpInset::metrics(MathMetricsInfo & mi) const { mi_ = mi; xcell(0).metrics(mi); @@ -42,7 +42,7 @@ void MathBinaryOpInset::metrics(MathMetricsInfo const & mi) const } -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_); diff --git a/src/mathed/math_binaryopinset.h b/src/mathed/math_binaryopinset.h index cdd4db1573..24cf79f4c5 100644 --- a/src/mathed/math_binaryopinset.h +++ b/src/mathed/math_binaryopinset.h @@ -19,13 +19,13 @@ public: /// 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; diff --git a/src/mathed/math_binominset.C b/src/mathed/math_binominset.C index 20732e7cca..cfdb835ca0 100644 --- a/src/mathed/math_binominset.C +++ b/src/mathed/math_binominset.C @@ -34,10 +34,9 @@ int MathBinomInset::dw() 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; @@ -46,13 +45,14 @@ void MathBinomInset::metrics(MathMetricsInfo const & st) const } -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(), ")"); } diff --git a/src/mathed/math_binominset.h b/src/mathed/math_binominset.h index 3bac831efe..a9c55dda61 100644 --- a/src/mathed/math_binominset.h +++ b/src/mathed/math_binominset.h @@ -22,9 +22,9 @@ public: /// 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; diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C index 8065cd136d..eeb4005c55 100644 --- a/src/mathed/math_boxinset.C +++ b/src/mathed/math_boxinset.C @@ -41,7 +41,7 @@ void MathBoxInset::rebreak() } -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); diff --git a/src/mathed/math_boxinset.h b/src/mathed/math_boxinset.h index c2f4364daa..0dfc8e4476 100644 --- a/src/mathed/math_boxinset.h +++ b/src/mathed/math_boxinset.h @@ -30,7 +30,7 @@ public: /// void normalize(NormalStream &) const; /// - void draw(Painter &, int x, int y) const; + void draw(MathPainterInfo &, int x, int y) const; private: /// diff --git a/src/mathed/math_braceinset.C b/src/mathed/math_braceinset.C index 9e73f78293..1d27ce03cb 100644 --- a/src/mathed/math_braceinset.C +++ b/src/mathed/math_braceinset.C @@ -24,23 +24,24 @@ MathInset * MathBraceInset::clone() const } -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, '}'); } diff --git a/src/mathed/math_braceinset.h b/src/mathed/math_braceinset.h index adebc05bb0..d53af2dc35 100644 --- a/src/mathed/math_braceinset.h +++ b/src/mathed/math_braceinset.h @@ -22,19 +22,17 @@ public: /// 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 diff --git a/src/mathed/math_casesinset.C b/src/mathed/math_casesinset.C index 01acf76812..94c83c0df7 100644 --- a/src/mathed/math_casesinset.C +++ b/src/mathed/math_casesinset.C @@ -8,7 +8,6 @@ #include "math_parser.h" #include "math_mathmlstream.h" #include "math_support.h" -#include "frontends/Painter.h" MathCasesInset::MathCasesInset(row_type n) @@ -22,14 +21,14 @@ MathInset * MathCasesInset::clone() const } -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); diff --git a/src/mathed/math_casesinset.h b/src/mathed/math_casesinset.h index 07a83a2de6..a7a3fc5026 100644 --- a/src/mathed/math_casesinset.h +++ b/src/mathed/math_casesinset.h @@ -16,9 +16,9 @@ public: /// 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; diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 38b4871e19..2d6ea5e726 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -28,33 +28,27 @@ using std::isalpha; #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 @@ -63,21 +57,41 @@ 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 } @@ -96,31 +110,9 @@ void MathCharInset::drawT(TextPainter & pain, int x, int y) const } -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_; } @@ -136,23 +128,8 @@ bool MathCharInset::isRelOp() const } -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_; } diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index 645c56a2cc..da50061c49 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -17,15 +17,11 @@ public: /// 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; /// @@ -33,26 +29,14 @@ public: /// 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; } @@ -60,9 +44,5 @@ public: private: /// the character char char_; - /// the font to be used on screen - MathTextCodes code_; - /// - mutable LyXFont font_; }; #endif diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index ae212ae06b..a941eadec0 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -48,6 +48,7 @@ #include "math_spaceinset.h" #include "math_specialcharinset.h" #include "math_support.h" +#include "math_unknowninset.h" #include #include @@ -185,8 +186,7 @@ Selection theSelection; 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(); } @@ -306,11 +306,9 @@ bool MathCursor::left(bool sel) autocorrect_ = false; if (inMacroMode()) { macroModeClose(); - lastcode_ = LM_TC_MIN; return true; } selHandle(sel); - lastcode_ = LM_TC_MIN; if (hasPrevAtom() && openable(prevAtom(), sel)) { pushRight(prevAtom()); @@ -327,11 +325,9 @@ bool MathCursor::right(bool sel) autocorrect_ = false; if (inMacroMode()) { macroModeClose(); - lastcode_ = LM_TC_MIN; return true; } selHandle(sel); - lastcode_ = LM_TC_MIN; if (hasNextAtom() && openable(nextAtom(), sel)) { pushLeft(nextAtom()); @@ -395,7 +391,6 @@ void MathCursor::home(bool sel) autocorrect_ = false; selHandle(sel); macroModeClose(); - lastcode_ = LM_TC_MIN; if (!par()->idxHome(idx(), pos())) popLeft(); dump("home 2"); @@ -408,7 +403,6 @@ void MathCursor::end(bool sel) autocorrect_ = false; selHandle(sel); macroModeClose(); - lastcode_ = LM_TC_MIN; if (!par()->idxEnd(idx(), pos())) popRight(); dump("end 2"); @@ -424,7 +418,7 @@ void MathCursor::plainErase() void MathCursor::markInsert() { //lyxerr << "inserting mark\n"; - array().insert(pos(), MathAtom(new MathCharInset(0, lastcode_))); + array().insert(pos(), MathAtom(new MathCharInset(0))); } @@ -442,17 +436,11 @@ void MathCursor::plainInsert(MathAtom const & t) } -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))); } @@ -631,35 +619,21 @@ bool MathCursor::toggleLimits() 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() : ""; } @@ -757,7 +731,7 @@ void MathCursor::selGet(MathArray & ar) -void MathCursor::drawSelection(Painter & pain) const +void MathCursor::drawSelection(MathPainterInfo & pain) const { if (!selection_) return; @@ -772,7 +746,7 @@ void MathCursor::drawSelection(Painter & pain) const 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 indices = i1.par_->idxBetween(i1.idx_, i2.idx_); @@ -782,7 +756,7 @@ void MathCursor::drawSelection(Painter & pain) const 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); } } @@ -800,23 +774,6 @@ void MathCursor::drawSelection(Painter & pain) const } -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)); @@ -883,9 +840,12 @@ MathCursor::pos_type & MathCursor::pos() } -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; } @@ -1397,12 +1357,6 @@ bool MathCursor::interpret(string const & s) return true; } - latexkeys const * l = in_word_set(name); - if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) { - lastcode_ = static_cast(l->id); - return true; - } - // prevent entering of recursive macros if (formula()->lyxCode() == Inset::MATHMACRO_CODE && formula()->getInsetName() == name) @@ -1461,7 +1415,7 @@ bool MathCursor::interpret(char c) 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 @@ -1474,15 +1428,14 @@ bool MathCursor::interpret(char c) 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; } @@ -1517,13 +1470,19 @@ bool MathCursor::interpret(char c) 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 'a' 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; } @@ -1539,13 +1498,13 @@ bool MathCursor::interpret(char c) } 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; } */ @@ -1561,10 +1520,10 @@ bool MathCursor::interpret(char c) 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; @@ -1581,15 +1540,15 @@ bool MathCursor::interpret(char c) //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; } @@ -1637,10 +1596,23 @@ void MathCursor::setSelection(cursor_type const & where, size_type n) } +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 } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 350de76ad9..bdb4f26037 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -21,13 +21,13 @@ #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; /** @@ -127,7 +127,7 @@ public: /// 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; @@ -153,9 +153,7 @@ public: /// 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); /// @@ -167,14 +165,12 @@ public: /// 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; @@ -244,6 +240,8 @@ public: void setSelection(cursor_type const & where, size_type n); /// void insert(char); + /// lock/unlock inset + void insetToggle(); /// hack for reveal codes void markInsert(); @@ -270,8 +268,6 @@ private: 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 @@ -285,12 +281,15 @@ private: 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; diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index 0a70a07924..cccbed2839 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -74,7 +74,7 @@ bool MathDecorationInset::wide() const } -void MathDecorationInset::metrics(MathMetricsInfo const & mi) const +void MathDecorationInset::metrics(MathMetricsInfo & mi) const { xcell(0).metrics(mi); width_ = xcell(0).width(); @@ -94,7 +94,7 @@ void MathDecorationInset::metrics(MathMetricsInfo const & mi) const } -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()) diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index 2c58662566..1c98714183 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -20,11 +20,11 @@ public: /// 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; /// diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index 03c03dd4ca..284d61a411 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -25,61 +25,6 @@ #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 { /// @@ -104,13 +49,9 @@ enum MathInsetTypes { LM_OT_MATRIX, /// A LaTeX macro - LM_OT_UNDEF, - /// - LM_OT_FUNCLIM, - /// LM_OT_MACRO, /// - LM_OT_MAX + LM_OT_NONE }; #endif diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index 84525f9d68..6fa100606c 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -51,13 +51,11 @@ int MathDelimInset::dw() const } -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; @@ -67,13 +65,13 @@ void MathDelimInset::metrics(MathMetricsInfo const & mi) const } -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_); } diff --git a/src/mathed/math_deliminset.h b/src/mathed/math_deliminset.h index c96ffa5924..2f8b7047cb 100644 --- a/src/mathed/math_deliminset.h +++ b/src/mathed/math_deliminset.h @@ -30,9 +30,9 @@ public: /// 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; diff --git a/src/mathed/math_diffinset.C b/src/mathed/math_diffinset.C index 7708364b2d..75d3852d19 100644 --- a/src/mathed/math_diffinset.C +++ b/src/mathed/math_diffinset.C @@ -32,13 +32,13 @@ void MathDiffInset::normalize(NormalStream & 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"; } diff --git a/src/mathed/math_diffinset.h b/src/mathed/math_diffinset.h index 3957a8f21d..284c822a2e 100644 --- a/src/mathed/math_diffinset.h +++ b/src/mathed/math_diffinset.h @@ -16,9 +16,9 @@ public: /// 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; diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index 839af0d360..b6c460acb1 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -21,11 +21,9 @@ MathInset * MathDotsInset::clone() 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" @@ -40,7 +38,7 @@ void MathDotsInset::metrics(MathMetricsInfo const & mi) const } -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") diff --git a/src/mathed/math_dotsinset.h b/src/mathed/math_dotsinset.h index 9ac4f722b9..be37fb641b 100644 --- a/src/mathed/math_dotsinset.h +++ b/src/mathed/math_dotsinset.h @@ -17,13 +17,13 @@ public: /// 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_; diff --git a/src/mathed/math_exfuncinset.C b/src/mathed/math_exfuncinset.C index 84ab2df489..ceb4d621fb 100644 --- a/src/mathed/math_exfuncinset.C +++ b/src/mathed/math_exfuncinset.C @@ -17,16 +17,15 @@ MathInset * MathExFuncInset::clone() const } -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_); } diff --git a/src/mathed/math_exfuncinset.h b/src/mathed/math_exfuncinset.h index a9a7cdf182..08d4a94620 100644 --- a/src/mathed/math_exfuncinset.h +++ b/src/mathed/math_exfuncinset.h @@ -14,9 +14,9 @@ public: /// 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; @@ -32,7 +32,5 @@ public: private: /// string const name_; - /// - mutable LyXFont font_; }; #endif diff --git a/src/mathed/math_exintinset.C b/src/mathed/math_exintinset.C index 212e87eecd..e26a74e6b6 100644 --- a/src/mathed/math_exintinset.C +++ b/src/mathed/math_exintinset.C @@ -49,13 +49,13 @@ void MathExIntInset::normalize(NormalStream & os) const } -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; } diff --git a/src/mathed/math_exintinset.h b/src/mathed/math_exintinset.h index 67bebf3b2d..5ef2642c9d 100644 --- a/src/mathed/math_exintinset.h +++ b/src/mathed/math_exintinset.h @@ -17,9 +17,9 @@ public: /// 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; diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 0e0a528012..502c640e2d 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -10,13 +10,13 @@ #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" @@ -121,16 +121,10 @@ MathScriptInset const * asScript(MathArray::const_iterator it) // 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; } @@ -146,7 +140,7 @@ void extractStrings(MathArray & ar) // 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); @@ -208,8 +202,7 @@ bool extractString(MathInset * p, string & str) 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; @@ -219,8 +212,7 @@ bool extractNumber(MathArray const & ar, int & i) 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; @@ -407,9 +399,9 @@ void extractFunctions(MathArray & ar) 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. diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index ec39ab9636..00acdbb622 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -8,7 +8,7 @@ #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" @@ -33,97 +33,326 @@ #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 +#include + + +namespace { + +// file scope +typedef std::map 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(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)); diff --git a/src/mathed/math_factory.h b/src/mathed/math_factory.h index 56e0e91669..b53efdda64 100644 --- a/src/mathed/math_factory.h +++ b/src/mathed/math_factory.h @@ -8,6 +8,5 @@ class MathInset; class latexkeys; MathAtom createMathInset(string const &); -MathAtom createMathInset(latexkeys const *); #endif diff --git a/src/mathed/math_fontinset.C b/src/mathed/math_fontinset.C new file mode 100644 index 0000000000..380cc73099 --- /dev/null +++ b/src/mathed/math_fontinset.C @@ -0,0 +1,89 @@ +#include + +#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_; +} diff --git a/src/mathed/math_fontinset.h b/src/mathed/math_fontinset.h new file mode 100644 index 0000000000..1c62eb9a7b --- /dev/null +++ b/src/mathed/math_fontinset.h @@ -0,0 +1,46 @@ +// -*- 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 diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index cc7efc8890..119c278774 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -29,25 +29,25 @@ MathFracInset * MathFracInset::asFracInset() } -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); } diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index 771c2e9ece..4f903d7c8b 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -18,9 +18,9 @@ public: /// 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; /// diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C index 59d4e4d7e1..e687e48720 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -38,16 +38,15 @@ void MathFuncInset::setName(string const & n) } -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_); } diff --git a/src/mathed/math_funcinset.h b/src/mathed/math_funcinset.h index 9a92c96af6..8256479c8f 100644 --- a/src/mathed/math_funcinset.h +++ b/src/mathed/math_funcinset.h @@ -3,7 +3,6 @@ #define MATH_FUNCINSET_H #include "math_diminset.h" -#include "math_defs.h" #ifdef __GNUG__ #pragma interface @@ -19,7 +18,7 @@ public: /// MathInset * clone() const; /// - void metrics(MathMetricsInfo const & st) const; + void metrics(MathMetricsInfo & st) const; /// void draw(Painter &, int x, int y) const; /// diff --git a/src/mathed/math_funcliminset.C b/src/mathed/math_funcliminset.C index dba26a2aa9..c2826c6b56 100644 --- a/src/mathed/math_funcliminset.C +++ b/src/mathed/math_funcliminset.C @@ -19,8 +19,7 @@ MathInset * MathFuncLimInset::clone() const bool MathFuncLimInset::isScriptable() const { - //return mi_.style == LM_ST_DISPLAY; - return true; + return scriptable_; } @@ -36,14 +35,14 @@ void MathFuncLimInset::normalize(NormalStream & os) const } -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_); } diff --git a/src/mathed/math_funcliminset.h b/src/mathed/math_funcliminset.h index b54a335d1d..61d2e1fe50 100644 --- a/src/mathed/math_funcliminset.h +++ b/src/mathed/math_funcliminset.h @@ -18,9 +18,9 @@ public: /// 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; @@ -28,6 +28,6 @@ private: /// string const name_; /// - mutable LyXFont font_; + mutable bool scriptable_; }; #endif diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 0b7a7ea3c6..dbcdece874 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -216,7 +216,7 @@ LyXLength MathGridInset::vcrskip(row_type row) const } -void MathGridInset::metrics(MathMetricsInfo const & mi) const +void MathGridInset::metrics(MathMetricsInfo & mi) const { // let the cells adjust themselves MathNestInset::metrics(mi); @@ -355,7 +355,7 @@ void MathGridInset::metrics(MathMetricsInfo const & mi) const } -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)); @@ -364,14 +364,14 @@ void MathGridInset::draw(Painter & pain, int x, int y) const 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); } } diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index b31cafae4f..2a3625aef2 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -70,9 +70,9 @@ public: /// 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; /// diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C deleted file mode 100644 index dbf5d58da4..0000000000 --- a/src/mathed/math_hash.C +++ /dev/null @@ -1,244 +0,0 @@ -#include - -#include "math_parser.h" -#include "math_metricsinfo.h" -#include "lyxlex.h" -#include "debug.h" -#include "support/filetools.h" // LibFileSearch - -#include - -using std::map; - -namespace { - -// file scope -typedef map 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(-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; -} diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 75bc87bf5b..5d1c551f0c 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -57,6 +57,7 @@ namespace { 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; @@ -156,24 +157,24 @@ int MathHullInset::defaultColSpace(col_type col) } -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; @@ -182,21 +183,21 @@ void MathHullInset::metrics(MathMetricsInfo const & mi) const // 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)); } } } @@ -371,6 +372,9 @@ void MathHullInset::header_write(WriteStream & os) const os << "\\begin{gather}\n"; break; + case LM_OT_NONE: + break; + default: os << "\\begin{unknown" << star(n) << "}"; } @@ -421,6 +425,10 @@ void MathHullInset::footer_write(WriteStream & os) const os << "\n\\end{gather}\n"; break; + case LM_OT_NONE: + os << "\n"; + break; + default: os << "\\end{unknown" << star(n) << "}"; } @@ -737,6 +745,11 @@ void MathHullInset::mathmlize(MathMLStream & os) const } +void MathHullInset::infoize(std::ostream & os) const +{ + os << normalName(getType()); +} + void MathHullInset::check() const { lyx::Assert(nonum_.size() == nrows()); diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 8b05af262e..13a61bf2a4 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -27,9 +27,9 @@ public: /// 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; /// @@ -86,6 +86,8 @@ public: void mathmlize(MathMLStream &) const; /// void normalize(NormalStream &) const; + /// + void infoize(std::ostream & os) const; private: /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 3210b3558f..c137de313a 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -190,13 +190,13 @@ vector } -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"; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 65f3d15e6c..379820f7f1 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -28,9 +28,9 @@ #pragma interface #endif +#include "LString.h" #include "frontends/mouse_state.h" #include "math_xdata.h" -#include "math_defs.h" /** @@ -53,6 +53,7 @@ class MathBraceInset; class MathBoxInset; class MathCharInset; class MathDelimInset; +class MathFontInset; class MathFuncInset; class MathGridInset; class MathFracInset; @@ -107,9 +108,9 @@ public: 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; @@ -192,6 +193,7 @@ public: 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; } @@ -205,6 +207,7 @@ public: 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; } @@ -217,8 +220,6 @@ public: /// 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 @@ -230,13 +231,17 @@ public: /// 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; diff --git a/src/mathed/math_kerninset.C b/src/mathed/math_kerninset.C index e2d8b60e52..b7fcd36855 100644 --- a/src/mathed/math_kerninset.C +++ b/src/mathed/math_kerninset.C @@ -32,7 +32,7 @@ MathInset * MathKernInset::clone() 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 @@ -46,7 +46,7 @@ void MathKernInset::metrics(MathMetricsInfo const & /*mi*/) const } -void MathKernInset::draw(Painter &, int, int) const +void MathKernInset::draw(MathPainterInfo &, int, int) const {} diff --git a/src/mathed/math_kerninset.h b/src/mathed/math_kerninset.h index 5af50f4651..37adf09da2 100644 --- a/src/mathed/math_kerninset.h +++ b/src/mathed/math_kerninset.h @@ -25,13 +25,13 @@ public: /// 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_; diff --git a/src/mathed/math_lefteqninset.C b/src/mathed/math_lefteqninset.C index 318a634549..4331a54958 100644 --- a/src/mathed/math_lefteqninset.C +++ b/src/mathed/math_lefteqninset.C @@ -18,7 +18,7 @@ MathInset * MathLefteqnInset::clone() const } -void MathLefteqnInset::metrics(MathMetricsInfo const & mi) const +void MathLefteqnInset::metrics(MathMetricsInfo & mi) const { MathNestInset::metrics(mi); ascent_ = xcell(0).ascent() + 2; @@ -27,7 +27,7 @@ void MathLefteqnInset::metrics(MathMetricsInfo const & mi) const } -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); diff --git a/src/mathed/math_lefteqninset.h b/src/mathed/math_lefteqninset.h index 3c75e612a8..0956310561 100644 --- a/src/mathed/math_lefteqninset.h +++ b/src/mathed/math_lefteqninset.h @@ -17,12 +17,12 @@ public: /// 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 diff --git a/src/mathed/math_limitopinset.C b/src/mathed/math_limitopinset.C index d92e7a69a1..d901f52e15 100644 --- a/src/mathed/math_limitopinset.C +++ b/src/mathed/math_limitopinset.C @@ -31,13 +31,13 @@ void MathLimitOpInset::normalize(NormalStream &) const } -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"; } diff --git a/src/mathed/math_limitopinset.h b/src/mathed/math_limitopinset.h index f5343c2514..5c9e4c01b1 100644 --- a/src/mathed/math_limitopinset.h +++ b/src/mathed/math_limitopinset.h @@ -14,9 +14,9 @@ public: /// 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; /// diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index d80be9f55e..0ee956ed13 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -28,7 +28,6 @@ #include "support/lstrings.h" #include "support/LAssert.h" #include "debug.h" -#include "frontends/Painter.h" #include "LaTeXFeatures.h" @@ -73,9 +72,9 @@ void MathMacro::expand() const } -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()) { @@ -116,12 +115,12 @@ void MathMacro::metrics(MathMetricsInfo const & mi) const } -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()); diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 1de5a90caf..d72483a892 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -42,9 +42,9 @@ public: /// 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; /// diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index 8033d70b84..0430a41d3d 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -4,7 +4,6 @@ #include "math_macroarg.h" #include "math_macro.h" -#include "math_defs.h" #include "math_mathmlstream.h" #include "math_support.h" #include "debug.h" @@ -13,8 +12,8 @@ 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: " @@ -34,32 +33,29 @@ MathInset * MathMacroArgument::clone() const 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_); } @@ -72,8 +68,5 @@ void MathMacroArgument::normalize(NormalStream & os) const 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; } diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index cb45e63100..1c642586a7 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -14,15 +14,15 @@ 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); @@ -38,10 +38,6 @@ private: char str_[3]; /// bool expanded_; - /// - mutable LyXFont font_; - /// - MathTextCodes code_; }; #endif diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 7df45d8163..b7cd35d2d3 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -108,26 +108,26 @@ void MathMacroTable::builtinMacros() 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}"); @@ -145,11 +145,11 @@ void MathMacroTable::builtinMacros() 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{}}"); diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 7d518782d0..04c96f11f8 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -47,7 +47,7 @@ string const & MathMacroTemplate::name() const } -void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const +void MathMacroTemplate::metrics(MathMetricsInfo & mi) const { xcell(0).metrics(mi); xcell(1).metrics(mi); @@ -57,14 +57,14 @@ void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const } -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); } diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index 726874ff84..a8f09a04ad 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -33,9 +33,9 @@ public: /// 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: diff --git a/src/mathed/math_matrixinset.h b/src/mathed/math_matrixinset.h index 57d45d61ea..9c796bfa27 100644 --- a/src/mathed/math_matrixinset.h +++ b/src/mathed/math_matrixinset.h @@ -19,7 +19,7 @@ public: /// MathInset * clone() const; /// - void metrics(MathMetricsInfo const &) const {} + void metrics(MathMetricsInfo &) const {} /// identifies MatrixInsets MathMatrixInset const * asMatrixInset() const { return this; } diff --git a/src/mathed/math_metricsinfo.C b/src/mathed/math_metricsinfo.C index e69de29bb2..81d5dbd75e 100644 --- a/src/mathed/math_metricsinfo.C +++ b/src/mathed/math_metricsinfo.C @@ -0,0 +1,149 @@ + +#include + +#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(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(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(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(mb) +{ + save_ = mb; + changeSize(mb.font, mb.style - style); +} + + +MathStyleChanger::~MathStyleChanger() +{ + orig_ = save_; +} + + + + +MathFontSetChanger::MathFontSetChanger(MathMetricsBase & mb, char const * cmd) + : MathChanger(mb) +{ + save_ = mb; + mb.fontinset = true; + augmentFont(mb.font, cmd); +} + +MathFontSetChanger::~MathFontSetChanger() +{ + orig_ = save_; +} + diff --git a/src/mathed/math_metricsinfo.h b/src/mathed/math_metricsinfo.h index d68f10533b..d607cc4339 100644 --- a/src/mathed/math_metricsinfo.h +++ b/src/mathed/math_metricsinfo.h @@ -2,8 +2,10 @@ #define MATH_METRICSINFO_H #include "lyxfont.h" +#include "math_defs.h" class BufferView; +class Painter; class MathNestInset; @@ -20,26 +22,27 @@ enum MathStyles { }; -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; /// @@ -49,10 +52,84 @@ struct MathMetricsInfo { }; -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 +struct MathChanger { + /// + MathChanger(Struct & orig) : orig_(orig) {} +protected: /// - TextMetricsInfo() - {} + Struct & orig_; + /// + Temp save_; }; + + +struct MathScriptChanger : public MathChanger { + /// + MathScriptChanger(MathMetricsBase & orig); + /// + ~MathScriptChanger(); +}; + + +struct MathFracChanger : public MathChanger { + /// + MathFracChanger(MathMetricsBase & orig); + /// + ~MathFracChanger(); +}; + + + +struct MathFontChanger : public MathChanger { + /// + MathFontChanger(LyXFont & orig, char const * font); + /// + ~MathFontChanger(); +}; + + +struct MathFontSetChanger : public MathChanger { + /// + MathFontSetChanger(MathMetricsBase & mb, char const * font); + /// + ~MathFontSetChanger(); +}; + + +struct MathStyleChanger : public MathChanger { + /// + MathStyleChanger(MathMetricsBase & mb, MathStyles shape); + /// + ~MathStyleChanger(); +}; + + +struct MathShapeChanger : public MathChanger { + /// + MathShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape); + /// + ~MathShapeChanger(); +}; + + #endif diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 6a11a9dbfe..82d6c5fb47 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -9,7 +9,7 @@ MathNestInset::MathNestInset(idx_type nargs) - : MathDimInset(), cells_(nargs) + : MathDimInset(), cells_(nargs), lock_(false) {} @@ -182,3 +182,21 @@ bool MathNestInset::editing() const { 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; +} diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 78175a7506..5ec120e7a4 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -49,6 +49,10 @@ public: /// 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); @@ -60,7 +64,7 @@ public: 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; @@ -81,6 +85,8 @@ protected: typedef std::vector cells_type; /// thusly: cells_type cells_; + /// if the inset is locked, it can't be enter with the cursor + bool lock_; }; #endif diff --git a/src/mathed/math_notinset.C b/src/mathed/math_notinset.C index ce3db3945c..b341a1c6e1 100644 --- a/src/mathed/math_notinset.C +++ b/src/mathed/math_notinset.C @@ -26,24 +26,22 @@ void MathNotInset::normalize(NormalStream & os) const } -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_); } diff --git a/src/mathed/math_notinset.h b/src/mathed/math_notinset.h index 6e56207bb0..c221ec0186 100644 --- a/src/mathed/math_notinset.h +++ b/src/mathed/math_notinset.h @@ -17,11 +17,13 @@ public: /// 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 diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index e6765fa193..c37de8de99 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -57,7 +57,6 @@ point to write some macros: #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" @@ -102,9 +101,9 @@ bool stared(string const & s) } -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))); } @@ -253,7 +252,7 @@ public: /// 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_; } /// @@ -261,9 +260,9 @@ public: 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(); /// @@ -731,9 +730,7 @@ bool Parser::parse_lines2(MathAtom & t, bool braced) return true; } - - - + bool Parser::parse_macro(string & name) { int nargs = 0; @@ -812,7 +809,7 @@ bool Parser::parse_macro(string & name) MathMacroTable::create(name, nargs, ar1, ar2); return true; } - + bool Parser::parse_normal(MathAtom & matrix) { @@ -930,9 +927,9 @@ 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"; @@ -941,7 +938,7 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) } -void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) +void Parser::parse_into1(MathArray & array, unsigned flags) { bool panic = false; int limits = 0; @@ -1001,14 +998,14 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) } 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) { @@ -1044,7 +1041,7 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) 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) { @@ -1066,7 +1063,7 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) return; else if (t.cat() == catOther) - add(array, t.character(), code); + add(array, t.character()); // // control sequences @@ -1171,14 +1168,6 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) 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('{', '}'); } @@ -1186,7 +1175,7 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) 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; } @@ -1245,36 +1234,39 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) 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(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(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; } diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index 0b51edbec1..ffd966549c 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -30,102 +30,17 @@ class MathAtom; 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; }; diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index 98b8423f94..bf3c211f94 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -34,7 +34,7 @@ MathInset * MathRootInset::clone() const } -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; @@ -43,7 +43,7 @@ void MathRootInset::metrics(MathMetricsInfo const & mi) const } -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" @@ -59,7 +59,7 @@ void MathRootInset::draw(Painter & pain, int x, int y) const 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); } diff --git a/src/mathed/math_rootinset.h b/src/mathed/math_rootinset.h index 46034c651f..e03755e017 100644 --- a/src/mathed/math_rootinset.h +++ b/src/mathed/math_rootinset.h @@ -34,9 +34,9 @@ public: /// 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; diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index 0310eeb792..e58b4cbabc 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -177,19 +177,16 @@ int MathScriptInset::ndes(MathInset const * nuc) 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); @@ -198,10 +195,11 @@ void MathScriptInset::metrics(MathInset const * 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); } @@ -226,21 +224,22 @@ void MathScriptInset::metricsT(MathInset const * nuc, } -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"; diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 29049e9e27..6087d537ec 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -25,18 +25,18 @@ public: /// 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; /// diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index 0f4eb4667a..07c9cfdc99 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -22,21 +22,21 @@ MathInset * MathSizeInset::clone() 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); } diff --git a/src/mathed/math_sizeinset.h b/src/mathed/math_sizeinset.h index 048ffd498a..9870777e3d 100644 --- a/src/mathed/math_sizeinset.h +++ b/src/mathed/math_sizeinset.h @@ -3,7 +3,6 @@ #define MATHSIZEINSET_H #include "math_nestinset.h" -#include "math_defs.h" #ifdef __GNUG__ #pragma interface @@ -22,9 +21,9 @@ public: /// 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; } diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index 5fb4367300..c41de6bf80 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -26,7 +26,7 @@ MathInset * MathSpaceInset::clone() const } -void MathSpaceInset::metrics(MathMetricsInfo const &) const +void MathSpaceInset::metrics(MathMetricsInfo &) const { switch (space_) { case 0: width_ = 6; break; @@ -43,7 +43,7 @@ void MathSpaceInset::metrics(MathMetricsInfo const &) const } -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. @@ -59,7 +59,7 @@ void MathSpaceInset::draw(Painter & pain, int x, int y) const 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); } diff --git a/src/mathed/math_spaceinset.h b/src/mathed/math_spaceinset.h index 74c86d8848..84ba58fb8d 100644 --- a/src/mathed/math_spaceinset.h +++ b/src/mathed/math_spaceinset.h @@ -3,7 +3,6 @@ #define MATH_SPACEINSET_H #include "math_diminset.h" -#include "math_defs.h" #ifdef __GNUG__ #pragma interface @@ -23,9 +22,9 @@ public: /// 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; diff --git a/src/mathed/math_specialcharinset.C b/src/mathed/math_specialcharinset.C index b00c832f5b..562fe89d3c 100644 --- a/src/mathed/math_specialcharinset.C +++ b/src/mathed/math_specialcharinset.C @@ -18,33 +18,17 @@ MathInset * MathSpecialCharInset::clone() 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_); } diff --git a/src/mathed/math_specialcharinset.h b/src/mathed/math_specialcharinset.h index 118760ed0c..7d17eab8b7 100644 --- a/src/mathed/math_specialcharinset.h +++ b/src/mathed/math_specialcharinset.h @@ -2,7 +2,7 @@ #ifndef MATH_SPECIALCHARINSET_H #define MATH_SPECIALCHARINSET_H -#include "math_inset.h" +#include "math_diminset.h" #ifdef __GNUG__ #pragma interface @@ -13,31 +13,23 @@ \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 diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index 3b6a330cbd..02c3a780bc 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -20,7 +20,7 @@ MathInset * MathSqrtInset::clone() const } -void MathSqrtInset::metrics(MathMetricsInfo const & mi) const +void MathSqrtInset::metrics(MathMetricsInfo & mi) const { xcell(0).metrics(mi); ascent_ = xcell(0).ascent() + 4; @@ -29,7 +29,7 @@ void MathSqrtInset::metrics(MathMetricsInfo const & mi) const } -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_; @@ -40,7 +40,7 @@ void MathSqrtInset::draw(Painter & pain, int x, int y) const 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); } diff --git a/src/mathed/math_sqrtinset.h b/src/mathed/math_sqrtinset.h index 69ab8d13f9..9ce0c237a5 100644 --- a/src/mathed/math_sqrtinset.h +++ b/src/mathed/math_sqrtinset.h @@ -18,9 +18,9 @@ public: /// 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; /// diff --git a/src/mathed/math_stackrelinset.C b/src/mathed/math_stackrelinset.C index 73500944eb..90ee3638b4 100644 --- a/src/mathed/math_stackrelinset.C +++ b/src/mathed/math_stackrelinset.C @@ -20,24 +20,24 @@ MathInset * MathStackrelInset::clone() 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); } diff --git a/src/mathed/math_stackrelinset.h b/src/mathed/math_stackrelinset.h index 7c2e8cd475..5f6b8fe980 100644 --- a/src/mathed/math_stackrelinset.h +++ b/src/mathed/math_stackrelinset.h @@ -18,9 +18,9 @@ public: /// 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; diff --git a/src/mathed/math_stringinset.C b/src/mathed/math_stringinset.C index 988ac65208..bb381f340c 100644 --- a/src/mathed/math_stringinset.C +++ b/src/mathed/math_stringinset.C @@ -8,21 +8,18 @@ #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 - 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) {} @@ -32,42 +29,16 @@ MathInset * MathStringInset::clone() const } -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_); } @@ -79,7 +50,7 @@ void MathStringInset::normalize(NormalStream & os) const 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; } @@ -93,7 +64,7 @@ void MathStringInset::maplize(MapleStream & os) const 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; } @@ -107,6 +78,7 @@ void MathStringInset::octavize(OctaveStream & os) const void MathStringInset::mathmlize(MathMLStream & os) const { +/* if (code_ == LM_TC_VAR) os << " " << str_ << " "; else if (code_ == LM_TC_CONST) @@ -114,14 +86,12 @@ void MathStringInset::mathmlize(MathMLStream & os) const else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM) os << " " << str_ << " "; 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_; } diff --git a/src/mathed/math_stringinset.h b/src/mathed/math_stringinset.h index 58cfcd3783..54021486bb 100644 --- a/src/mathed/math_stringinset.h +++ b/src/mathed/math_stringinset.h @@ -2,7 +2,7 @@ #ifndef MATH_STRINGINSET_H #define MATH_STRINGINSET_H -#include "math_inset.h" +#include "math_diminset.h" #ifdef __GNUG__ #pragma interface @@ -12,30 +12,22 @@ \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; @@ -51,9 +43,5 @@ public: public: /// the string string str_; - /// the font to be used on screen - MathTextCodes code_; - /// - mutable LyXFont font_; }; #endif diff --git a/src/mathed/math_substackinset.C b/src/mathed/math_substackinset.C index 43395d9937..89635f8b3e 100644 --- a/src/mathed/math_substackinset.C +++ b/src/mathed/math_substackinset.C @@ -20,12 +20,14 @@ MathInset * MathSubstackInset::clone() const } -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); + } } diff --git a/src/mathed/math_substackinset.h b/src/mathed/math_substackinset.h index 4b3115efcf..d0ec7098a7 100644 --- a/src/mathed/math_substackinset.h +++ b/src/mathed/math_substackinset.h @@ -16,7 +16,7 @@ public: /// MathInset * clone() const; /// - void metrics(MathMetricsInfo const & st) const; + void metrics(MathMetricsInfo & st) const; /// MathSubstackInset const * asSubstackInset() const { return this; } diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index 962e0e09c0..2dd4f234f8 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -52,221 +52,6 @@ void Matrix::transform(double & x, double & y) } -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 { @@ -423,6 +208,13 @@ double const hlinesmall[] = { }; +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 @@ -436,13 +228,6 @@ double const Vert[] = { }; -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, @@ -463,21 +248,21 @@ struct named_deco_struct { 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 }, @@ -625,11 +410,11 @@ int mathed_string_descent(LyXFont const & font, string const & s) -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; } @@ -669,7 +454,7 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, 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]; @@ -687,53 +472,47 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, 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); } @@ -744,25 +523,6 @@ void math_font_max_dim(LyXFont const & font, int & asc, int & des) } -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 == "(") @@ -781,3 +541,120 @@ string convertDelimToLatexName(string const & 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; +} diff --git a/src/mathed/math_support.h b/src/mathed/math_support.h index abe0a39e83..b2e104e730 100644 --- a/src/mathed/math_support.h +++ b/src/mathed/math_support.h @@ -3,10 +3,9 @@ #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; @@ -19,10 +18,10 @@ int mathed_char_width(LyXFont const &, unsigned char c); 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); @@ -31,23 +30,20 @@ int mathed_string_width(LyXFont const &, string const & s); 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 diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 952dc816ae..7ff59dc436 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -34,111 +34,69 @@ MathInset * MathSymbolInset::clone() const } -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() << "]"; @@ -171,7 +129,7 @@ bool MathSymbolInset::match(MathInset * p) const 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(); diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index 018fc63b85..22b3f86901 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -20,9 +20,9 @@ public: /// 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? @@ -54,16 +54,11 @@ public: 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 diff --git a/src/mathed/math_undersetinset.C b/src/mathed/math_undersetinset.C index c06fa46dda..7a027299bd 100644 --- a/src/mathed/math_undersetinset.C +++ b/src/mathed/math_undersetinset.C @@ -20,24 +20,24 @@ MathInset * MathUndersetInset::clone() const } -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); } diff --git a/src/mathed/math_undersetinset.h b/src/mathed/math_undersetinset.h index 35ed008fee..a673a74781 100644 --- a/src/mathed/math_undersetinset.h +++ b/src/mathed/math_undersetinset.h @@ -18,9 +18,9 @@ public: /// 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; diff --git a/src/mathed/math_unknowninset.C b/src/mathed/math_unknowninset.C index b58588e1fa..b7256c3d58 100644 --- a/src/mathed/math_unknowninset.C +++ b/src/mathed/math_unknowninset.C @@ -5,17 +5,13 @@ #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) {} @@ -31,9 +27,9 @@ string const & MathUnknownInset::name() const } -void MathUnknownInset::setName(string const & n) +string & MathUnknownInset::name() { - name_ = n; + return name_; } @@ -56,16 +52,30 @@ void MathUnknownInset::normalize(NormalStream & os) const } -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_; } diff --git a/src/mathed/math_unknowninset.h b/src/mathed/math_unknowninset.h index 4389f8aecd..2e9dd5b82b 100644 --- a/src/mathed/math_unknowninset.h +++ b/src/mathed/math_unknowninset.h @@ -3,7 +3,6 @@ #define MATH_UNKNOWNINSET_H #include "math_diminset.h" -#include "math_defs.h" #ifdef __GNUG__ #pragma interface @@ -15,19 +14,22 @@ 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; @@ -41,10 +43,16 @@ public: 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 diff --git a/src/mathed/math_xarrowinset.C b/src/mathed/math_xarrowinset.C index 32959e666e..e95b47745f 100644 --- a/src/mathed/math_xarrowinset.C +++ b/src/mathed/math_xarrowinset.C @@ -22,10 +22,10 @@ MathInset * MathXArrowInset::clone() const } -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; @@ -33,7 +33,7 @@ void MathXArrowInset::metrics(MathMetricsInfo const & st) const } -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_); diff --git a/src/mathed/math_xarrowinset.h b/src/mathed/math_xarrowinset.h index d086145726..40078548cc 100644 --- a/src/mathed/math_xarrowinset.h +++ b/src/mathed/math_xarrowinset.h @@ -20,11 +20,11 @@ public: /// 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; diff --git a/src/mathed/math_xdata.C b/src/mathed/math_xdata.C index 6c9bcbd75a..854ddffc9d 100644 --- a/src/mathed/math_xdata.C +++ b/src/mathed/math_xdata.C @@ -32,7 +32,7 @@ void MathXArray::touch() const } -void MathXArray::metrics(MathMetricsInfo const & mi) const +void MathXArray::metrics(MathMetricsInfo & mi) const { //if (clean_) // return; @@ -42,9 +42,7 @@ void MathXArray::metrics(MathMetricsInfo const & mi) const 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; } @@ -73,7 +71,7 @@ void MathXArray::metrics(MathMetricsInfo const & mi) const } -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; @@ -86,17 +84,17 @@ void MathXArray::draw(Painter & pain, int x, int y) const 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; } @@ -104,11 +102,11 @@ void MathXArray::draw(Painter & pain, int x, int y) const 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(); } } diff --git a/src/mathed/math_xdata.h b/src/mathed/math_xdata.h index 41e4eedaab..b35c062b9a 100644 --- a/src/mathed/math_xdata.h +++ b/src/mathed/math_xdata.h @@ -12,7 +12,7 @@ #pragma interface #endif -class Painter; +class MathPainterInfo; class TextPainter; @@ -30,9 +30,9 @@ public: /// 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 diff --git a/src/mathed/math_xyarrowinset.C b/src/mathed/math_xyarrowinset.C index f2d62fb84a..fe5a886297 100644 --- a/src/mathed/math_xyarrowinset.C +++ b/src/mathed/math_xyarrowinset.C @@ -64,15 +64,15 @@ MathXArray const & MathXYArrowInset::sourceCell() const } -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; @@ -85,32 +85,33 @@ void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const } -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); } } diff --git a/src/mathed/math_xyarrowinset.h b/src/mathed/math_xyarrowinset.h index a6534e23b7..ecdfd3e247 100644 --- a/src/mathed/math_xyarrowinset.h +++ b/src/mathed/math_xyarrowinset.h @@ -19,9 +19,9 @@ public: /// 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; } diff --git a/src/mathed/math_xymatrixinset.C b/src/mathed/math_xymatrixinset.C index c18052a8d9..d9ae049ca2 100644 --- a/src/mathed/math_xymatrixinset.C +++ b/src/mathed/math_xymatrixinset.C @@ -32,11 +32,11 @@ int MathXYMatrixInset::rowsep() const } -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); } diff --git a/src/mathed/math_xymatrixinset.h b/src/mathed/math_xymatrixinset.h index 3cabea91d5..c0c8600859 100644 --- a/src/mathed/math_xymatrixinset.h +++ b/src/mathed/math_xymatrixinset.h @@ -16,7 +16,7 @@ public: /// MathInset * clone() const; /// - void metrics(MathMetricsInfo const & st) const; + void metrics(MathMetricsInfo & st) const; /// MathXYMatrixInset const * asXYMatrixInset() const { return this; } /// -- 2.39.2