diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 550d77e4eb..342be7a290 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,4 +1,15 @@ +2001-10-17 André Pönitz + + * math_*inset.[Ch]: remove MathStyles cache from insets that + don't need it + + * support.C: + formulabase.C: fix math font sizes in headings etc + + * math_inset.[Ch]: + formula.C: remove unused static member int MathInset::workwidth + 2001-10-17 André Pönitz * math_inset.h: diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 400bbaf813..67f37cd7bd 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -49,6 +49,22 @@ using std::endl; using std::vector; +namespace { + + void stripFromLastEqualSign(MathArray & ar) + { + // find position of last '=' in the array + MathArray::size_type pos = ar.size(); + for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) + if ((*it)->getChar() == '=') + pos = it - ar.begin(); + + // delete everything behind this position + ar.erase(pos, ar.size()); + } + +} + InsetFormula::InsetFormula() : par_(MathAtom(new MathMatrixInset)) @@ -132,10 +148,9 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font, int x = int(xx) - 1; y -= 2; - MathInset::workwidth = bv->workWidth(); Painter & pain = bv->painter(); - metrics(bv, &font); + metrics(bv, font); int w = par_->width(); int h = par_->height(); int a = par_->ascent(); @@ -242,7 +257,9 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, case LFUN_MATH_EXTERN: bv->lockedInsetStoreUndo(Undo::EDIT); - handleExtern(arg, bv); + handleExtern(arg); + // re-compute inset dimension + metrics(bv); updateLocal(bv, true); break; @@ -299,25 +316,32 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, } -void InsetFormula::handleExtern(const string & arg, BufferView * bv) +void InsetFormula::handleExtern(const string & arg) { // where are we? + if (!mathcursor) + return; + MathArray & ar = mathcursor->cursor().cell(); - // find position of last '=' in the array for handleExtern - MathArray::size_type pos = ar.size(); - for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) - if ((*it)->getChar() == '=') - pos = it - ar.begin(); + // parse args + string lang; + string extra; + istringstream iss(arg.c_str()); + iss >> lang >> extra; + if (extra.empty()) + extra = "noextra"; - // delete everything behind this position - ar.erase(pos, ar.size()); + // strip last '=' and everything behind + stripFromLastEqualSign(ar); // create normalized expression //string outfile = lyx::tempName("maple.out"); - string outfile = "/tmp/lyx2" + arg + ".out"; + string outfile = "/tmp/lyx2" + lang + ".out"; ostringstream os; + os << "[" << extra << ' '; ar.writeNormal(os); + os << "]"; string code = os.str().c_str(); // run external sript @@ -332,9 +356,6 @@ void InsetFormula::handleExtern(const string & arg, BufferView * bv) ifstream is(outfile.c_str()); mathed_parse_cell(ar, is); mathcursor->end(); - - // re-compute inset dimension - metrics(bv); } @@ -390,7 +411,7 @@ int InsetFormula::descent(BufferView *, LyXFont const &) const int InsetFormula::width(BufferView * bv, LyXFont const & font) const { - metrics(bv, &font); + metrics(bv, font); return par_->width(); } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 659c80a1ca..94c6d602b6 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -71,7 +71,7 @@ public: /// std::vector const getLabelList() const; /// - void handleExtern(string const & arg, BufferView * bv); + void handleExtern(string const & arg); /// bool display() const; /// diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index eb67e308fc..954e0374e0 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -95,7 +95,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset) MathArrayInset * matrixpar(MathInset::idx_type & idx) { idx = 0; - return (mathcursor ? mathcursor->enclosingArray(idx) : 0); + return mathcursor ? mathcursor->enclosingArray(idx) : 0; } @@ -104,7 +104,7 @@ MathArrayInset * matrixpar(MathInset::idx_type & idx) InsetFormulaBase::InsetFormulaBase() - : view_(0), font_(0) + : view_(0), font_() { // This is needed as long the math parser is not re-entrant MathMacroTable::builtinMacros(); @@ -117,14 +117,11 @@ void InsetFormulaBase::validate(LaTeXFeatures &) const {} -void InsetFormulaBase::metrics(BufferView * bv, LyXFont const * f) const +void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const { if (bv) view_ = bv; - if (f) - font_ = f; - if (f) - lyxerr << "fontsize: " << f->size() << "\n"; + font_ = f; MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT); par()->metrics(mi); } diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 3d45a7814f..4d33c9700b 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -21,6 +21,7 @@ #include #include "insets/inset.h" +#include "lyxfont.h" // only for getType(): #include "math_defs.h" @@ -89,7 +90,7 @@ public: /// virtual MathAtom & par() = 0; /// - virtual void metrics(BufferView * bv = 0, LyXFont const * font = 0) const; + virtual void metrics(BufferView * bv = 0, LyXFont const & font = LyXFont()) const; /// virtual void updateLocal(BufferView * bv, bool mark_dirty); private: @@ -98,7 +99,7 @@ private: /// mutable BufferView * view_; /// - mutable LyXFont const * font_; + mutable LyXFont font_; }; // We don't really mess want around with mathed stuff outside mathed. diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index b0188770d3..587155747e 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -140,7 +140,7 @@ int InsetFormulaMacro::descent(BufferView *, LyXFont const &) const int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const { - metrics(bv, &f); + metrics(bv, f); return 10 + lyxfont::width(prefix(), f) + par()->width(); } diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index 0b06d00a59..57eb16832f 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -46,9 +46,9 @@ void MathArrayInset::write(MathWriteInfo & os) const void MathArrayInset::metrics(MathMetricsInfo const & st) const { - size_ = st; - if (size_.style == LM_ST_DISPLAY) - size_.style = LM_ST_TEXT; - MathGridInset::metrics(size_); + MathMetricsInfo mi = st; + if (mi.style == LM_ST_DISPLAY) + mi.style = LM_ST_TEXT; + MathGridInset::metrics(mi); } diff --git a/src/mathed/math_binominset.C b/src/mathed/math_binominset.C index a9f419a492..7ffbd19fee 100644 --- a/src/mathed/math_binominset.C +++ b/src/mathed/math_binominset.C @@ -30,10 +30,10 @@ int MathBinomInset::dw() const void MathBinomInset::metrics(MathMetricsInfo const & st) const { - size_ = st; - smallerStyleFrac(size_); - xcell(0).metrics(size_); - xcell(1).metrics(size_); + MathMetricsInfo mi = st; + smallerStyleFrac(mi); + xcell(0).metrics(mi); + xcell(1).metrics(mi); ascent_ = xcell(0).height() + 4 + 5; descent_ = xcell(1).height() + 4 - 5; width_ = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4; diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C index 8d7642ceb1..2e1c3bacde 100644 --- a/src/mathed/math_boxinset.C +++ b/src/mathed/math_boxinset.C @@ -54,11 +54,11 @@ void MathBoxInset::writeNormal(std::ostream & os) const void MathBoxInset::metrics(MathMetricsInfo const & st) const { - size_ = st; - if (text_ && st.view && st.font) { - ascent_ = text_->ascent(st.view, *st.font) + 2; - descent_ = text_->descent(st.view, *st.font) + 2; - width_ = text_->width(st.view, *st.font) + 4; + mi_ = st; + if (text_ && mi_.view) { + ascent_ = text_->ascent(mi_.view, mi_.font) + 2; + descent_ = text_->descent(mi_.view, mi_.font) + 2; + width_ = text_->width(mi_.view, mi_.font) + 4; } else { ascent_ = 10; descent_ = 0; @@ -71,8 +71,8 @@ void MathBoxInset::draw(Painter & pain, int x, int y) const { float fx = x + 2; - if (text_ && size_.view && size_.font) - text_->draw(size_.view, *(size_.font), y, fx, false); + if (text_ && mi_.view) + text_->draw(mi_.view, mi_.font, y, fx, false); if (mathcursor && mathcursor->isInside(this)) pain.rectangle(x, y - ascent(), xcell(0).width(), height(), LColor::mathframe); diff --git a/src/mathed/math_boxinset.h b/src/mathed/math_boxinset.h index 9b0bd58123..a3d8202c75 100644 --- a/src/mathed/math_boxinset.h +++ b/src/mathed/math_boxinset.h @@ -33,7 +33,7 @@ public: /// void writeNormal(std::ostream &) const; /// - void metrics(MathMetricsInfo const & st) const; + void metrics(MathMetricsInfo const &) const; /// identifies BoxInsets MathBoxInset * asBoxInset() { return this; } @@ -41,6 +41,8 @@ private: /// unimplemented void operator=(MathBoxInset const &); + /// + mutable MathMetricsInfo mi_; /// string name_; /// diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 197f918525..3d1557c402 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -60,25 +60,25 @@ MathInset * MathCharInset::clone() const int MathCharInset::ascent() const { - return mathed_char_ascent(code_, size_, char_); + return mathed_char_ascent(code_, mi_, char_); } int MathCharInset::descent() const { - return mathed_char_descent(code_, size_, char_); + return mathed_char_descent(code_, mi_, char_); } int MathCharInset::width() const { - return mathed_char_width(code_, size_, char_); + return mathed_char_width(code_, mi_, char_); } -void MathCharInset::metrics(MathMetricsInfo const & st) const +void MathCharInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; + mi_ = mi; } @@ -87,7 +87,7 @@ void MathCharInset::draw(Painter & pain, int x, int y) const xo(x); yo(y); //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl; - drawChar(pain, code_, size_, x, y, char_); + drawChar(pain, code_, mi_, x, y, char_); } diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index fc024338fe..3d844729ba 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -58,5 +58,7 @@ private: char char_; /// the font to be used on screen MathTextCodes code_; + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index a7a8effa82..1808b2f474 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -44,5 +44,7 @@ private: mutable int dh_; /// vertical offset cache of deco mutable int dy_; + /// + mutable MathMetricsInfo size_; }; #endif diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index cef56a13cc..40f548695c 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -60,12 +60,11 @@ int MathDelimInset::dw() const } -void MathDelimInset::metrics(MathMetricsInfo const & st) const +void MathDelimInset::metrics(MathMetricsInfo const & mi) const { - xcell(0).metrics(st); - size_ = st; + xcell(0).metrics(mi); int a, d, w; - mathed_char_dim(LM_TC_VAR, size_, 'I', a, d, w); + mathed_char_dim(LM_TC_VAR, mi, 'I', a, d, w); int h0 = (a + d) / 2; int a0 = std::max(xcell(0).ascent(), a) - h0; int d0 = std::max(xcell(0).descent(), d) + h0; diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index 40249eeff1..47a79a7d4a 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -32,10 +32,9 @@ void MathDotsInset::draw(Painter & pain, int x, int y) const } -void MathDotsInset::metrics(MathMetricsInfo const & st) const +void MathDotsInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; - mathed_char_dim(LM_TC_VAR, size_, 'M', ascent_, descent_, width_); + mathed_char_dim(LM_TC_VAR, mi, 'M', ascent_, descent_, width_); switch (name_[0]) { case 'l': dh_ = 0; break; case 'c': dh_ = ascent_ / 2; break; diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index e25adc5c0e..4a4cd0ef64 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -19,12 +19,12 @@ MathInset * MathFracInset::clone() const } -void MathFracInset::metrics(MathMetricsInfo const & st) const +void MathFracInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; - smallerStyleFrac(size_); - xcell(0).metrics(size_); - xcell(1).metrics(size_); + MathMetricsInfo m = mi; + smallerStyleFrac(m); + xcell(0).metrics(m); + xcell(1).metrics(m); width_ = std::max(xcell(0).width(), xcell(1).width()) + 4; ascent_ = xcell(0).height() + 4 + 5; descent_ = xcell(1).height() + 4 - 5; diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C index a255258670..765aa191b9 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -49,10 +49,10 @@ void MathFuncInset::writeNormal(std::ostream & os) const } -void MathFuncInset::metrics(MathMetricsInfo const & st) const +void MathFuncInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; - mathed_string_dim(LM_TC_TEX, size_, name_, ascent_, descent_, width_); + mi_ = mi; + mathed_string_dim(LM_TC_TEX, mi_, name_, ascent_, descent_, width_); } @@ -60,5 +60,5 @@ void MathFuncInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); - drawStr(pain, LM_TC_TEX, size_, x, y, name_); + drawStr(pain, LM_TC_TEX, mi_, x, y, name_); } diff --git a/src/mathed/math_funcinset.h b/src/mathed/math_funcinset.h index b81cc60907..4ec3b0c32a 100644 --- a/src/mathed/math_funcinset.h +++ b/src/mathed/math_funcinset.h @@ -34,5 +34,7 @@ public: private: /// string name_; + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/math_funcliminset.C b/src/mathed/math_funcliminset.C index 2788b42051..9939eaf494 100644 --- a/src/mathed/math_funcliminset.C +++ b/src/mathed/math_funcliminset.C @@ -19,7 +19,7 @@ MathInset * MathFuncLimInset::clone() const bool MathFuncLimInset::isScriptable() const { - return size_.style == LM_ST_DISPLAY; + return mi_.style == LM_ST_DISPLAY; } @@ -35,11 +35,10 @@ void MathFuncLimInset::writeNormal(ostream & os) const } -void MathFuncLimInset::metrics(MathMetricsInfo const & st) const +void MathFuncLimInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; - mathed_string_dim(LM_TC_TEXTRM, size_, sym_->name, - ascent_, descent_, width_); + mi_ = mi; + mathed_string_dim(LM_TC_TEXTRM, mi_, sym_->name, ascent_, descent_, width_); } @@ -47,5 +46,5 @@ void MathFuncLimInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); - drawStr(pain, LM_TC_TEXTRM, size_, x, y, sym_->name); + drawStr(pain, LM_TC_TEXTRM, mi_, x, y, sym_->name); } diff --git a/src/mathed/math_funcliminset.h b/src/mathed/math_funcliminset.h index 70f0e992b8..0d4e8dcc85 100644 --- a/src/mathed/math_funcliminset.h +++ b/src/mathed/math_funcliminset.h @@ -29,5 +29,7 @@ public: private: /// latexkeys const * sym_; + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 4b3c16d606..d583e90ab2 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -3,6 +3,7 @@ #endif #include "math_gridinset.h" +#include "lyxfont.h" #include "support/LOstream.h" #include "debug.h" @@ -132,11 +133,10 @@ LyXLength MathGridInset::vskip(row_type row) const } -void MathGridInset::metrics(MathMetricsInfo const & st) const +void MathGridInset::metrics(MathMetricsInfo const & mi) const { // let the cells adjust themselves - MathNestInset::metrics(st); - size_ = st; + MathNestInset::metrics(mi); // adjust vertical structure for (row_type row = 0; row < nrows(); ++row) { diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 114ab8a482..1656ac28ec 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -24,9 +24,6 @@ #include "debug.h" -int MathInset::workwidth; - - MathInset::MathInset() : xo_(0), yo_(0) {} @@ -246,10 +243,9 @@ std::vector } -void MathInset::metrics(MathMetricsInfo const & st) const +void MathInset::metrics(MathMetricsInfo const &) const { lyxerr << "MathInset::metrics() called directly!\n"; - size_ = st; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index d72bcfa0a5..b70260e692 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -257,13 +257,6 @@ public: /// virtual void handleFont(MathTextCodes) {} - /// - static int workwidth; - -protected: - /// the used font size - mutable MathMetricsInfo size_; - private: /// the following are used for positioning the cursor with the mouse /// cached cursor start position in pixels from the document left diff --git a/src/mathed/math_lefteqninset.C b/src/mathed/math_lefteqninset.C index 9c22c442a4..3f4382d8ea 100644 --- a/src/mathed/math_lefteqninset.C +++ b/src/mathed/math_lefteqninset.C @@ -45,10 +45,9 @@ void MathLefteqnInset::writeNormal(std::ostream & os) const } -void MathLefteqnInset::metrics(MathMetricsInfo const & st) const +void MathLefteqnInset::metrics(MathMetricsInfo const & mi) const { - MathNestInset::metrics(st); - size_ = st; + MathNestInset::metrics(mi); ascent_ = xcell(0).ascent() + 2; descent_ = xcell(0).descent() + 2; width_ = 4; diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index f7a327c3f2..c62f84dac8 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -69,32 +69,32 @@ bool MathMacro::editing() const } -void MathMacro::metrics(MathMetricsInfo const & st) const +void MathMacro::metrics(MathMetricsInfo const & mi) const { + mi_ = mi; + if (defining()) { - size_ = st; - mathed_string_dim(LM_TC_TEX, size_, name(), ascent_, descent_, width_); + mathed_string_dim(LM_TC_TEX, mi_, name(), ascent_, descent_, width_); return; } if (editing()) { expanded_ = tmplate_->xcell(0); - expanded_.metrics(st); - size_ = st; + expanded_.metrics(mi_); width_ = expanded_.width() + 4; ascent_ = expanded_.ascent() + 2; descent_ = expanded_.descent() + 2; - width_ += mathed_string_width(LM_TC_TEXTRM, size_, name()) + 10; + width_ += mathed_string_width(LM_TC_TEXTRM, mi_, name()) + 10; int lasc; int ldes; int lwid; - mathed_string_dim(LM_TC_TEXTRM, size_, "#1: ", lasc, ldes, lwid); + mathed_string_dim(LM_TC_TEXTRM, mi_, "#1: ", lasc, ldes, lwid); for (idx_type i = 0; i < nargs(); ++i) { MathXArray const & c = xcell(i); - c.metrics(st); + c.metrics(mi_); width_ = std::max(width_, c.width() + lwid); descent_ += std::max(c.ascent(), lasc) + 5; descent_ += std::max(c.descent(), ldes) + 5; @@ -104,8 +104,7 @@ void MathMacro::metrics(MathMetricsInfo const & st) const expanded_ = tmplate_->xcell(0); expanded_.data_.substitute(*this); - expanded_.metrics(st); - size_ = st; + expanded_.metrics(mi_); width_ = expanded_.width() + 6; ascent_ = expanded_.ascent() + 3; descent_ = expanded_.descent() + 3; @@ -117,25 +116,25 @@ void MathMacro::draw(Painter & pain, int x, int y) const xo(x); yo(y); - metrics(size_); + metrics(mi_); if (defining()) { - drawStr(pain, LM_TC_TEX, size_, x, y, name()); + drawStr(pain, LM_TC_TEX, mi_, x, y, name()); return; } if (editing()) { int h = y - ascent() + 2 + expanded_.ascent(); - drawStr(pain, LM_TC_TEXTRM, size_, x + 3, h, name()); + drawStr(pain, LM_TC_TEXTRM, mi_, x + 3, h, name()); - int const w = mathed_string_width(LM_TC_TEXTRM, size_, name()); + int const w = mathed_string_width(LM_TC_TEXTRM, mi_, name()); expanded_.draw(pain, x + w + 12, h); h += expanded_.descent(); int lasc; int ldes; int lwid; - mathed_string_dim(LM_TC_TEXTRM, size_, "#1: ", lasc, ldes, lwid); + mathed_string_dim(LM_TC_TEXTRM, mi_, "#1: ", lasc, ldes, lwid); for (idx_type i = 0; i < nargs(); ++i) { MathXArray const & c = xcell(i); @@ -143,7 +142,7 @@ void MathMacro::draw(Painter & pain, int x, int y) const c.draw(pain, x + lwid, h); char str[] = "#1:"; str[1] += static_cast(i); - drawStr(pain, LM_TC_TEX, size_, x + 3, h, str); + drawStr(pain, LM_TC_TEX, mi_, x + 3, h, str); h += std::max(c.descent(), ldes) + 5; } return; diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 4460f0bfd5..39fb630aff 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -82,6 +82,8 @@ private: MathAtom & tmplate_; /// mutable MathXArray expanded_; + /// + mutable MathMetricsInfo mi_; }; diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index 6ed3e3e04a..77c817305f 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -35,15 +35,16 @@ void MathMacroArgument::write(MathWriteInfo & os) const } -void MathMacroArgument::metrics(MathMetricsInfo const & st) const +void MathMacroArgument::metrics(MathMetricsInfo const & mi) const { + mi_ = mi; if (expanded_) { - xcell(0).metrics(st); + xcell(0).metrics(mi_); width_ = xcell(0).width(); ascent_ = xcell(0).ascent(); descent_ = xcell(0).descent(); } else - mathed_string_dim(LM_TC_TEX, size_, str_, ascent_, descent_, width_); + mathed_string_dim(LM_TC_TEX, mi_, str_, ascent_, descent_, width_); } @@ -52,7 +53,7 @@ void MathMacroArgument::draw(Painter & pain, int x, int y) const if (expanded_) xcell(0).draw(pain, x, y); else - drawStr(pain, LM_TC_TEX, size_, x, y, str_); + drawStr(pain, LM_TC_TEX, mi_, x, y, str_); } diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index c8855d9a87..25755677d0 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -37,6 +37,8 @@ private: char str_[3]; /// bool expanded_; + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index c217cd1b57..486e200cc0 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -56,10 +56,9 @@ void MathMacroTemplate::write(MathWriteInfo & os) const } -void MathMacroTemplate::metrics(MathMetricsInfo const & st) const +void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const { - xcell(0).metrics(st); - size_ = st; + xcell(0).metrics(mi); width_ = xcell(0).width() + 4; ascent_ = xcell(0).ascent() + 2; descent_ = xcell(0).descent() + 2; diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 9c289572c6..70c3788326 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -140,13 +140,13 @@ int MathMatrixInset::defaultColSpace(col_type col) } -void MathMatrixInset::metrics(MathMetricsInfo const & st) const +void MathMatrixInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; - size_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; + mi_ = mi; + mi_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; // let the cells adjust themselves - MathGridInset::metrics(size_); + MathGridInset::metrics(mi_); if (display()) { ascent_ += 12; @@ -156,7 +156,7 @@ void MathMatrixInset::metrics(MathMetricsInfo const & st) const if (numberedType()) { int l = 0; for (row_type row = 0; row < nrows(); ++row) - l = std::max(l, mathed_string_width(LM_TC_BF, size_, nicelabel(row))); + l = std::max(l, mathed_string_width(LM_TC_BF, mi_, nicelabel(row))); if (l) width_ += 30 + l; @@ -165,7 +165,7 @@ void MathMatrixInset::metrics(MathMetricsInfo const & st) const // make it at least as high as the current font int asc = 0; int des = 0; - math_font_max_dim(LM_TC_TEXTRM, size_, asc, des); + math_font_max_dim(LM_TC_TEXTRM, mi_, asc, des); ascent_ = std::max(ascent_, asc); descent_ = std::max(descent_, des); } @@ -182,7 +182,7 @@ void MathMatrixInset::draw(Painter & pain, int x, int y) const 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, LM_TC_BF, size_, xx, yy, nicelabel(row)); + drawStr(pain, LM_TC_BF, mi_, xx, yy, nicelabel(row)); } } } diff --git a/src/mathed/math_matrixinset.h b/src/mathed/math_matrixinset.h index c28020b549..c6cdaab385 100644 --- a/src/mathed/math_matrixinset.h +++ b/src/mathed/math_matrixinset.h @@ -101,6 +101,8 @@ private: std::vector nonum_; /// std::vector label_; + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/math_metricsinfo.h b/src/mathed/math_metricsinfo.h index db5a3c2caf..ee67ca7186 100644 --- a/src/mathed/math_metricsinfo.h +++ b/src/mathed/math_metricsinfo.h @@ -1,8 +1,9 @@ #ifndef MATH_METRICSINFO #define MATH_METRICSINFO +#include "lyxfont.h" + class BufferView; -class LyXFont; /// Standard Math Sizes (Math mode styles) @@ -21,17 +22,17 @@ enum MathStyles { struct MathMetricsInfo { /// MathMetricsInfo() - : view(0), font(0), style(LM_ST_TEXT) + : view(0), font(), style(LM_ST_TEXT) {} /// - MathMetricsInfo(BufferView * v, LyXFont const * f, MathStyles s) + MathMetricsInfo(BufferView * v, LyXFont const & f, MathStyles s) : view(v), font(f), style(s) {} /// BufferView * view; /// - LyXFont const * font; + LyXFont font; /// MathStyles style; }; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 9b8a411002..6e051d1744 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -48,11 +48,10 @@ void MathNestInset::substitute(MathMacro const & m) } -void MathNestInset::metrics(MathMetricsInfo const & st) const +void MathNestInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; for (idx_type i = 0; i < nargs(); ++i) - xcell(i).metrics(st); + xcell(i).metrics(mi); } diff --git a/src/mathed/math_notinset.C b/src/mathed/math_notinset.C index 5e72280b84..3c6442c7ba 100644 --- a/src/mathed/math_notinset.C +++ b/src/mathed/math_notinset.C @@ -28,13 +28,13 @@ void MathNotInset::writeNormal(ostream & os) const } -void MathNotInset::metrics(MathMetricsInfo const & st) const +void MathNotInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; + mi_ = mi; if (math_font_available(LM_TC_CMSY)) - mathed_char_dim(LM_TC_CMSY, size_, 54, ascent_, descent_, width_); + mathed_char_dim(LM_TC_CMSY, mi_, 54, ascent_, descent_, width_); else - mathed_char_dim(LM_TC_VAR, size_, '/', ascent_, descent_, width_); + mathed_char_dim(LM_TC_VAR, mi_, '/', ascent_, descent_, width_); width_ = 0; } @@ -45,7 +45,7 @@ void MathNotInset::draw(Painter & pain, int x, int y) const yo(y); if (math_font_available(LM_TC_CMSY)) - drawChar(pain, LM_TC_CMSY, size_, x, y, 54); + drawChar(pain, LM_TC_CMSY, mi_, x, y, 54); else - drawChar(pain, LM_TC_VAR, size_, x, y, '/'); + drawChar(pain, LM_TC_VAR, mi_, x, y, '/'); } diff --git a/src/mathed/math_notinset.h b/src/mathed/math_notinset.h index cc0dca081b..0f94542042 100644 --- a/src/mathed/math_notinset.h +++ b/src/mathed/math_notinset.h @@ -20,5 +20,8 @@ public: void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; +private: + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index c9bd8e6188..d5190cea73 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -19,6 +19,7 @@ #include "support/LOstream.h" #include "Painter.h" + MathRootInset::MathRootInset() : MathNestInset(2) {} @@ -30,10 +31,9 @@ MathInset * MathRootInset::clone() const } -void MathRootInset::metrics(MathMetricsInfo const & st) const +void MathRootInset::metrics(MathMetricsInfo const & mi) const { - MathNestInset::metrics(st); - size_ = st; + MathNestInset::metrics(mi); ascent_ = std::max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2; descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2; width_ = xcell(0).width() + xcell(1).width() + 10; diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index f362245912..b68c70f26f 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -100,7 +100,7 @@ int MathScriptInset::dy1(MathInset const * nuc) const asc += na + 2; else asc = std::max(asc, na); - asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, size_, 'I')); + asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I')); return asc; } @@ -162,36 +162,36 @@ int MathScriptInset::nwid(MathInset const * nuc) const { return nuc ? nuc->width() : - mathed_char_width(LM_TC_TEX, size_, '.'); + mathed_char_width(LM_TC_TEX, mi_, '.'); } int MathScriptInset::nasc(MathInset const * nuc) const { return nuc ? nuc->ascent() - : mathed_char_ascent(LM_TC_VAR, size_, 'I'); + : mathed_char_ascent(LM_TC_VAR, mi_, 'I'); } int MathScriptInset::ndes(MathInset const * nuc) const { return nuc ? nuc->descent() - : mathed_char_descent(LM_TC_VAR, size_, 'I'); + : mathed_char_descent(LM_TC_VAR, mi_, 'I'); } -void MathScriptInset::metrics(MathMetricsInfo const & st) const +void MathScriptInset::metrics(MathMetricsInfo const & mi) const { - metrics(0, st); + metrics(0, mi); } void MathScriptInset::metrics(MathInset const * nuc, - MathMetricsInfo const & st) const + MathMetricsInfo const & mi) const { - MathNestInset::metrics(st); + MathNestInset::metrics(mi); if (nuc) - nuc->metrics(st); + nuc->metrics(mi); ascent_ = ascent(nuc); descent_ = descent(nuc); @@ -215,7 +215,7 @@ void MathScriptInset::draw(MathInset const * nuc, Painter & pain, if (nuc) nuc->draw(pain, x + dxx(nuc), y); else - drawStr(pain, LM_TC_TEX, size_, x + dxx(nuc), y, "."); + drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, "."); if (hasUp()) up().draw(pain, x + dx1(nuc), y - dy1(nuc)); diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 49337fa80a..f7af1546cc 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -100,6 +100,8 @@ private: bool script_[2]; /// int limits_; + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index a7d6221c8c..d7e4c1b530 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -26,11 +26,11 @@ void MathSizeInset::draw(Painter & pain, int x, int y) const } -void MathSizeInset::metrics(MathMetricsInfo const & st) const +void MathSizeInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; - size_.style = MathStyles(key_->id); - xcell(0).metrics(size_); + MathMetricsInfo m = mi; + m.style = MathStyles(key_->id); + xcell(0).metrics(m); ascent_ = xcell(0).ascent_; descent_ = xcell(0).descent_; width_ = xcell(0).width_; diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index 87b752e884..77be8e3a19 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -21,6 +21,32 @@ MathInset * MathSpaceInset::clone() const } +void MathSpaceInset::write(MathWriteInfo & os) const +{ + if (space_ >= 0 && space_ < 6) + os << '\\' << latex_mathspace[space_] << ' '; +} + + +void MathSpaceInset::writeNormal(std::ostream & os) const +{ + os << "[space " << space_ << "] "; +} + + +void MathSpaceInset::metrics(MathMetricsInfo const & mi) const +{ + width_ = space_ ? space_ * 2 : 2; + if (space_ > 3) + width_ *= 2; + if (space_ == 5) + width_ *= 2; + width_ += 4; + ascent_ = 4; + descent_ = 0; +} + + void MathSpaceInset::draw(Painter & pain, int x, int y) const { @@ -40,33 +66,6 @@ void MathSpaceInset::draw(Painter & pain, int x, int y) const } -void MathSpaceInset::write(MathWriteInfo & os) const -{ - if (space_ >= 0 && space_ < 6) - os << '\\' << latex_mathspace[space_] << ' '; -} - - -void MathSpaceInset::writeNormal(std::ostream & os) const -{ - os << "[space " << space_ << "] "; -} - - -void MathSpaceInset::metrics(MathMetricsInfo const & st) const -{ - size_ = st; - width_ = space_ ? space_ * 2 : 2; - if (space_ > 3) - width_ *= 2; - if (space_ == 5) - width_ *= 2; - width_ += 4; - ascent_ = 4; - descent_ = 0; -} - - void MathSpaceInset::incSpace() { space_ = (space_ + 1) % 6; diff --git a/src/mathed/math_specialcharinset.C b/src/mathed/math_specialcharinset.C index 0c9d76fec8..bfd1eaf130 100644 --- a/src/mathed/math_specialcharinset.C +++ b/src/mathed/math_specialcharinset.C @@ -20,25 +20,25 @@ MathInset * MathSpecialCharInset::clone() const int MathSpecialCharInset::ascent() const { - return mathed_char_ascent(LM_TC_CONST, size_, char_); + return mathed_char_ascent(LM_TC_CONST, mi_, char_); } int MathSpecialCharInset::descent() const { - return mathed_char_descent(LM_TC_CONST, size_, char_); + return mathed_char_descent(LM_TC_CONST, mi_, char_); } int MathSpecialCharInset::width() const { - return mathed_char_width(LM_TC_CONST, size_, char_); + return mathed_char_width(LM_TC_CONST, mi_, char_); } -void MathSpecialCharInset::metrics(MathMetricsInfo const & st) const +void MathSpecialCharInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; + mi_ = mi; } @@ -46,7 +46,7 @@ void MathSpecialCharInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); - drawChar(pain, LM_TC_CONST, size_, x, y, char_); + drawChar(pain, LM_TC_CONST, mi_, x, y, char_); } diff --git a/src/mathed/math_specialcharinset.h b/src/mathed/math_specialcharinset.h index 8fcfbb32c9..1fbcc91301 100644 --- a/src/mathed/math_specialcharinset.h +++ b/src/mathed/math_specialcharinset.h @@ -37,5 +37,7 @@ public: private: /// the character char char_; + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index 27cdc56c2c..5bfb8112a6 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -19,10 +19,9 @@ MathInset * MathSqrtInset::clone() const } -void MathSqrtInset::metrics(MathMetricsInfo const & st) const +void MathSqrtInset::metrics(MathMetricsInfo const & mi) const { - xcell(0).metrics(st); - size_ = st; + xcell(0).metrics(mi); ascent_ = xcell(0).ascent() + 4; descent_ = xcell(0).descent() + 2; width_ = xcell(0).width() + 12; diff --git a/src/mathed/math_stackrelinset.C b/src/mathed/math_stackrelinset.C index 3db2779344..1333bc6414 100644 --- a/src/mathed/math_stackrelinset.C +++ b/src/mathed/math_stackrelinset.C @@ -17,12 +17,12 @@ MathInset * MathStackrelInset::clone() const } -void MathStackrelInset::metrics(MathMetricsInfo const & st) const +void MathStackrelInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; - smallerStyleFrac(size_); - xcell(0).metrics(size_); - xcell(1).metrics(st); + MathMetricsInfo m = mi; + smallerStyleFrac(m); + xcell(0).metrics(m); + xcell(1).metrics(mi); width_ = std::max(xcell(0).width(), xcell(1).width()) + 4; ascent_ = xcell(1).ascent() + xcell(0).height() + 4; descent_ = xcell(1).descent(); diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index f9170c1b2d..24e3e9a923 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -58,12 +58,12 @@ MathTextCodes MathSymbolInset::code2() const } -void MathSymbolInset::metrics(MathMetricsInfo const & st) const +void MathSymbolInset::metrics(MathMetricsInfo const & mi) const { - size_ = st; + mi_ = mi; MathTextCodes c = code(); if (sym_->latex_font_id > 0 && math_font_available(c)) { - mathed_char_dim(c, size_, sym_->latex_font_id, ascent_, descent_, width_); + mathed_char_dim(c, mi_, sym_->latex_font_id, ascent_, descent_, width_); if (c == LM_TC_CMEX) { h_ = 4 * descent_ / 5; ascent_ += h_; @@ -73,9 +73,9 @@ void MathSymbolInset::metrics(MathMetricsInfo const & st) const } if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)) - mathed_char_dim(code2(), size_, sym_->id, ascent_, descent_, width_); + mathed_char_dim(code2(), mi_, sym_->id, ascent_, descent_, width_); else - mathed_string_dim(LM_TC_TEX, size_, sym_->name, ascent_, descent_, width_); + mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_); } @@ -85,11 +85,11 @@ void MathSymbolInset::draw(Painter & pain, int x, int y) const yo(y); MathTextCodes Code = code(); if (sym_->latex_font_id > 0 && math_font_available(Code)) - drawChar(pain, Code, size_, x, y - h_, sym_->latex_font_id); + drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id); else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)) - drawChar(pain, code2(), size_, x, y, sym_->id); + drawChar(pain, code2(), mi_, x, y, sym_->id); else - drawStr(pain, LM_TC_TEX, size_, x, y, sym_->name); + drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name); } @@ -101,7 +101,7 @@ bool MathSymbolInset::isRelOp() const bool MathSymbolInset::isScriptable() const { - return size_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX; + return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX; } diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index a42f01ba59..7d73c85fe3 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -40,5 +40,7 @@ private: latexkeys const * sym_; /// mutable int h_; + /// + mutable MathMetricsInfo mi_; }; #endif diff --git a/src/mathed/support.C b/src/mathed/support.C index 513b8f96a1..59274e474e 100644 --- a/src/mathed/support.C +++ b/src/mathed/support.C @@ -192,15 +192,8 @@ LyXFont const & whichFontBase(MathTextCodes type) LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size) { LyXFont f = whichFontBase(type); - if (size.font) { -#ifdef WITH_WARNINGS -#warning Want to fix formula sizes in headings? Look here! -#endif - // unfortunatly, size.font is sometimes nonzero and size.font->size() - // is huge... - //lyxerr << "setting font size to " << size.font->size() << "\n"; - //f.setSize(size.font->size()); - } + // use actual size + f.setSize(size.font.size()); switch (size.style) { case LM_ST_DISPLAY: