- remove MathStyles cache from those insets that don't need it

- fix math font sizes in headings etc
- remove unused static member int MathInset::workwidth


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2909 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-10-22 15:37:49 +00:00
parent 0677c7b0c9
commit 40b2b89d4d
47 changed files with 238 additions and 208 deletions

View File

@ -1,4 +1,15 @@
2001-10-17 André Pönitz <poenitz@gmx.net>
* 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 <poenitz@gmx.net> 2001-10-17 André Pönitz <poenitz@gmx.net>
* math_inset.h: * math_inset.h:

View File

@ -49,6 +49,22 @@ using std::endl;
using std::vector; 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() InsetFormula::InsetFormula()
: par_(MathAtom(new MathMatrixInset)) : par_(MathAtom(new MathMatrixInset))
@ -132,10 +148,9 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
int x = int(xx) - 1; int x = int(xx) - 1;
y -= 2; y -= 2;
MathInset::workwidth = bv->workWidth();
Painter & pain = bv->painter(); Painter & pain = bv->painter();
metrics(bv, &font); metrics(bv, font);
int w = par_->width(); int w = par_->width();
int h = par_->height(); int h = par_->height();
int a = par_->ascent(); int a = par_->ascent();
@ -242,7 +257,9 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
case LFUN_MATH_EXTERN: case LFUN_MATH_EXTERN:
bv->lockedInsetStoreUndo(Undo::EDIT); bv->lockedInsetStoreUndo(Undo::EDIT);
handleExtern(arg, bv); handleExtern(arg);
// re-compute inset dimension
metrics(bv);
updateLocal(bv, true); updateLocal(bv, true);
break; 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? // where are we?
if (!mathcursor)
return;
MathArray & ar = mathcursor->cursor().cell(); MathArray & ar = mathcursor->cursor().cell();
// find position of last '=' in the array for handleExtern // parse args
MathArray::size_type pos = ar.size(); string lang;
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) string extra;
if ((*it)->getChar() == '=') istringstream iss(arg.c_str());
pos = it - ar.begin(); iss >> lang >> extra;
if (extra.empty())
extra = "noextra";
// delete everything behind this position // strip last '=' and everything behind
ar.erase(pos, ar.size()); stripFromLastEqualSign(ar);
// create normalized expression // create normalized expression
//string outfile = lyx::tempName("maple.out"); //string outfile = lyx::tempName("maple.out");
string outfile = "/tmp/lyx2" + arg + ".out"; string outfile = "/tmp/lyx2" + lang + ".out";
ostringstream os; ostringstream os;
os << "[" << extra << ' ';
ar.writeNormal(os); ar.writeNormal(os);
os << "]";
string code = os.str().c_str(); string code = os.str().c_str();
// run external sript // run external sript
@ -332,9 +356,6 @@ void InsetFormula::handleExtern(const string & arg, BufferView * bv)
ifstream is(outfile.c_str()); ifstream is(outfile.c_str());
mathed_parse_cell(ar, is); mathed_parse_cell(ar, is);
mathcursor->end(); 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 int InsetFormula::width(BufferView * bv, LyXFont const & font) const
{ {
metrics(bv, &font); metrics(bv, font);
return par_->width(); return par_->width();
} }

View File

@ -71,7 +71,7 @@ public:
/// ///
std::vector<string> const getLabelList() const; std::vector<string> const getLabelList() const;
/// ///
void handleExtern(string const & arg, BufferView * bv); void handleExtern(string const & arg);
/// ///
bool display() const; bool display() const;
/// ///

View File

@ -95,7 +95,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
MathArrayInset * matrixpar(MathInset::idx_type & idx) MathArrayInset * matrixpar(MathInset::idx_type & idx)
{ {
idx = 0; 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() InsetFormulaBase::InsetFormulaBase()
: view_(0), font_(0) : view_(0), font_()
{ {
// This is needed as long the math parser is not re-entrant // This is needed as long the math parser is not re-entrant
MathMacroTable::builtinMacros(); 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) if (bv)
view_ = bv; view_ = bv;
if (f) font_ = f;
font_ = f;
if (f)
lyxerr << "fontsize: " << f->size() << "\n";
MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT); MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
par()->metrics(mi); par()->metrics(mi);
} }

View File

@ -21,6 +21,7 @@
#include <iosfwd> #include <iosfwd>
#include "insets/inset.h" #include "insets/inset.h"
#include "lyxfont.h"
// only for getType(): // only for getType():
#include "math_defs.h" #include "math_defs.h"
@ -89,7 +90,7 @@ public:
/// ///
virtual MathAtom & par() = 0; 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); virtual void updateLocal(BufferView * bv, bool mark_dirty);
private: private:
@ -98,7 +99,7 @@ private:
/// ///
mutable BufferView * view_; mutable BufferView * view_;
/// ///
mutable LyXFont const * font_; mutable LyXFont font_;
}; };
// We don't really mess want around with mathed stuff outside mathed. // We don't really mess want around with mathed stuff outside mathed.

View File

@ -140,7 +140,7 @@ int InsetFormulaMacro::descent(BufferView *, LyXFont const &) const
int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const
{ {
metrics(bv, &f); metrics(bv, f);
return 10 + lyxfont::width(prefix(), f) + par()->width(); return 10 + lyxfont::width(prefix(), f) + par()->width();
} }

View File

@ -46,9 +46,9 @@ void MathArrayInset::write(MathWriteInfo & os) const
void MathArrayInset::metrics(MathMetricsInfo const & st) const void MathArrayInset::metrics(MathMetricsInfo const & st) const
{ {
size_ = st; MathMetricsInfo mi = st;
if (size_.style == LM_ST_DISPLAY) if (mi.style == LM_ST_DISPLAY)
size_.style = LM_ST_TEXT; mi.style = LM_ST_TEXT;
MathGridInset::metrics(size_); MathGridInset::metrics(mi);
} }

View File

@ -30,10 +30,10 @@ int MathBinomInset::dw() const
void MathBinomInset::metrics(MathMetricsInfo const & st) const void MathBinomInset::metrics(MathMetricsInfo const & st) const
{ {
size_ = st; MathMetricsInfo mi = st;
smallerStyleFrac(size_); smallerStyleFrac(mi);
xcell(0).metrics(size_); xcell(0).metrics(mi);
xcell(1).metrics(size_); xcell(1).metrics(mi);
ascent_ = xcell(0).height() + 4 + 5; ascent_ = xcell(0).height() + 4 + 5;
descent_ = xcell(1).height() + 4 - 5; descent_ = xcell(1).height() + 4 - 5;
width_ = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4; width_ = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4;

View File

@ -54,11 +54,11 @@ void MathBoxInset::writeNormal(std::ostream & os) const
void MathBoxInset::metrics(MathMetricsInfo const & st) const void MathBoxInset::metrics(MathMetricsInfo const & st) const
{ {
size_ = st; mi_ = st;
if (text_ && st.view && st.font) { if (text_ && mi_.view) {
ascent_ = text_->ascent(st.view, *st.font) + 2; ascent_ = text_->ascent(mi_.view, mi_.font) + 2;
descent_ = text_->descent(st.view, *st.font) + 2; descent_ = text_->descent(mi_.view, mi_.font) + 2;
width_ = text_->width(st.view, *st.font) + 4; width_ = text_->width(mi_.view, mi_.font) + 4;
} else { } else {
ascent_ = 10; ascent_ = 10;
descent_ = 0; descent_ = 0;
@ -71,8 +71,8 @@ void MathBoxInset::draw(Painter & pain, int x, int y) const
{ {
float fx = x + 2; float fx = x + 2;
if (text_ && size_.view && size_.font) if (text_ && mi_.view)
text_->draw(size_.view, *(size_.font), y, fx, false); text_->draw(mi_.view, mi_.font, y, fx, false);
if (mathcursor && mathcursor->isInside(this)) if (mathcursor && mathcursor->isInside(this))
pain.rectangle(x, y - ascent(), xcell(0).width(), height(), pain.rectangle(x, y - ascent(), xcell(0).width(), height(),
LColor::mathframe); LColor::mathframe);

View File

@ -33,7 +33,7 @@ public:
/// ///
void writeNormal(std::ostream &) const; void writeNormal(std::ostream &) const;
/// ///
void metrics(MathMetricsInfo const & st) const; void metrics(MathMetricsInfo const &) const;
/// identifies BoxInsets /// identifies BoxInsets
MathBoxInset * asBoxInset() { return this; } MathBoxInset * asBoxInset() { return this; }
@ -41,6 +41,8 @@ private:
/// unimplemented /// unimplemented
void operator=(MathBoxInset const &); void operator=(MathBoxInset const &);
///
mutable MathMetricsInfo mi_;
/// ///
string name_; string name_;
/// ///

View File

@ -60,25 +60,25 @@ MathInset * MathCharInset::clone() const
int MathCharInset::ascent() const int MathCharInset::ascent() const
{ {
return mathed_char_ascent(code_, size_, char_); return mathed_char_ascent(code_, mi_, char_);
} }
int MathCharInset::descent() const int MathCharInset::descent() const
{ {
return mathed_char_descent(code_, size_, char_); return mathed_char_descent(code_, mi_, char_);
} }
int MathCharInset::width() const 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); xo(x);
yo(y); yo(y);
//lyxerr << "drawing '" << char_ << "' code: " << code_ << endl; //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
drawChar(pain, code_, size_, x, y, char_); drawChar(pain, code_, mi_, x, y, char_);
} }

View File

@ -58,5 +58,7 @@ private:
char char_; char char_;
/// the font to be used on screen /// the font to be used on screen
MathTextCodes code_; MathTextCodes code_;
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -44,5 +44,7 @@ private:
mutable int dh_; mutable int dh_;
/// vertical offset cache of deco /// vertical offset cache of deco
mutable int dy_; mutable int dy_;
///
mutable MathMetricsInfo size_;
}; };
#endif #endif

View File

@ -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); xcell(0).metrics(mi);
size_ = st;
int a, d, w; 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 h0 = (a + d) / 2;
int a0 = std::max(xcell(0).ascent(), a) - h0; int a0 = std::max(xcell(0).ascent(), a) - h0;
int d0 = std::max(xcell(0).descent(), d) + h0; int d0 = std::max(xcell(0).descent(), d) + h0;

View File

@ -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, mi, 'M', ascent_, descent_, width_);
mathed_char_dim(LM_TC_VAR, size_, 'M', ascent_, descent_, width_);
switch (name_[0]) { switch (name_[0]) {
case 'l': dh_ = 0; break; case 'l': dh_ = 0; break;
case 'c': dh_ = ascent_ / 2; break; case 'c': dh_ = ascent_ / 2; break;

View File

@ -19,12 +19,12 @@ MathInset * MathFracInset::clone() const
} }
void MathFracInset::metrics(MathMetricsInfo const & st) const void MathFracInset::metrics(MathMetricsInfo const & mi) const
{ {
size_ = st; MathMetricsInfo m = mi;
smallerStyleFrac(size_); smallerStyleFrac(m);
xcell(0).metrics(size_); xcell(0).metrics(m);
xcell(1).metrics(size_); xcell(1).metrics(m);
width_ = std::max(xcell(0).width(), xcell(1).width()) + 4; width_ = std::max(xcell(0).width(), xcell(1).width()) + 4;
ascent_ = xcell(0).height() + 4 + 5; ascent_ = xcell(0).height() + 4 + 5;
descent_ = xcell(1).height() + 4 - 5; descent_ = xcell(1).height() + 4 - 5;

View File

@ -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; mi_ = mi;
mathed_string_dim(LM_TC_TEX, size_, name_, ascent_, descent_, width_); 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); xo(x);
yo(y); yo(y);
drawStr(pain, LM_TC_TEX, size_, x, y, name_); drawStr(pain, LM_TC_TEX, mi_, x, y, name_);
} }

View File

@ -34,5 +34,7 @@ public:
private: private:
/// ///
string name_; string name_;
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -19,7 +19,7 @@ MathInset * MathFuncLimInset::clone() const
bool MathFuncLimInset::isScriptable() 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; mi_ = mi;
mathed_string_dim(LM_TC_TEXTRM, size_, sym_->name, mathed_string_dim(LM_TC_TEXTRM, mi_, sym_->name, ascent_, descent_, width_);
ascent_, descent_, width_);
} }
@ -47,5 +46,5 @@ void MathFuncLimInset::draw(Painter & pain, int x, int y) const
{ {
xo(x); xo(x);
yo(y); yo(y);
drawStr(pain, LM_TC_TEXTRM, size_, x, y, sym_->name); drawStr(pain, LM_TC_TEXTRM, mi_, x, y, sym_->name);
} }

View File

@ -29,5 +29,7 @@ public:
private: private:
/// ///
latexkeys const * sym_; latexkeys const * sym_;
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -3,6 +3,7 @@
#endif #endif
#include "math_gridinset.h" #include "math_gridinset.h"
#include "lyxfont.h"
#include "support/LOstream.h" #include "support/LOstream.h"
#include "debug.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 // let the cells adjust themselves
MathNestInset::metrics(st); MathNestInset::metrics(mi);
size_ = st;
// adjust vertical structure // adjust vertical structure
for (row_type row = 0; row < nrows(); ++row) { for (row_type row = 0; row < nrows(); ++row) {

View File

@ -24,9 +24,6 @@
#include "debug.h" #include "debug.h"
int MathInset::workwidth;
MathInset::MathInset() MathInset::MathInset()
: xo_(0), yo_(0) : xo_(0), yo_(0)
{} {}
@ -246,10 +243,9 @@ std::vector<MathInset::idx_type>
} }
void MathInset::metrics(MathMetricsInfo const & st) const void MathInset::metrics(MathMetricsInfo const &) const
{ {
lyxerr << "MathInset::metrics() called directly!\n"; lyxerr << "MathInset::metrics() called directly!\n";
size_ = st;
} }

View File

@ -257,13 +257,6 @@ public:
/// ///
virtual void handleFont(MathTextCodes) {} virtual void handleFont(MathTextCodes) {}
///
static int workwidth;
protected:
/// the used font size
mutable MathMetricsInfo size_;
private: private:
/// the following are used for positioning the cursor with the mouse /// the following are used for positioning the cursor with the mouse
/// cached cursor start position in pixels from the document left /// cached cursor start position in pixels from the document left

View File

@ -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); MathNestInset::metrics(mi);
size_ = st;
ascent_ = xcell(0).ascent() + 2; ascent_ = xcell(0).ascent() + 2;
descent_ = xcell(0).descent() + 2; descent_ = xcell(0).descent() + 2;
width_ = 4; width_ = 4;

View File

@ -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()) { if (defining()) {
size_ = st; mathed_string_dim(LM_TC_TEX, mi_, name(), ascent_, descent_, width_);
mathed_string_dim(LM_TC_TEX, size_, name(), ascent_, descent_, width_);
return; return;
} }
if (editing()) { if (editing()) {
expanded_ = tmplate_->xcell(0); expanded_ = tmplate_->xcell(0);
expanded_.metrics(st); expanded_.metrics(mi_);
size_ = st;
width_ = expanded_.width() + 4; width_ = expanded_.width() + 4;
ascent_ = expanded_.ascent() + 2; ascent_ = expanded_.ascent() + 2;
descent_ = expanded_.descent() + 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 lasc;
int ldes; int ldes;
int lwid; 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) { for (idx_type i = 0; i < nargs(); ++i) {
MathXArray const & c = xcell(i); MathXArray const & c = xcell(i);
c.metrics(st); c.metrics(mi_);
width_ = std::max(width_, c.width() + lwid); width_ = std::max(width_, c.width() + lwid);
descent_ += std::max(c.ascent(), lasc) + 5; descent_ += std::max(c.ascent(), lasc) + 5;
descent_ += std::max(c.descent(), ldes) + 5; descent_ += std::max(c.descent(), ldes) + 5;
@ -104,8 +104,7 @@ void MathMacro::metrics(MathMetricsInfo const & st) const
expanded_ = tmplate_->xcell(0); expanded_ = tmplate_->xcell(0);
expanded_.data_.substitute(*this); expanded_.data_.substitute(*this);
expanded_.metrics(st); expanded_.metrics(mi_);
size_ = st;
width_ = expanded_.width() + 6; width_ = expanded_.width() + 6;
ascent_ = expanded_.ascent() + 3; ascent_ = expanded_.ascent() + 3;
descent_ = expanded_.descent() + 3; descent_ = expanded_.descent() + 3;
@ -117,25 +116,25 @@ void MathMacro::draw(Painter & pain, int x, int y) const
xo(x); xo(x);
yo(y); yo(y);
metrics(size_); metrics(mi_);
if (defining()) { if (defining()) {
drawStr(pain, LM_TC_TEX, size_, x, y, name()); drawStr(pain, LM_TC_TEX, mi_, x, y, name());
return; return;
} }
if (editing()) { if (editing()) {
int h = y - ascent() + 2 + expanded_.ascent(); 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); expanded_.draw(pain, x + w + 12, h);
h += expanded_.descent(); h += expanded_.descent();
int lasc; int lasc;
int ldes; int ldes;
int lwid; 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) { for (idx_type i = 0; i < nargs(); ++i) {
MathXArray const & c = xcell(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); c.draw(pain, x + lwid, h);
char str[] = "#1:"; char str[] = "#1:";
str[1] += static_cast<char>(i); str[1] += static_cast<char>(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; h += std::max(c.descent(), ldes) + 5;
} }
return; return;

View File

@ -82,6 +82,8 @@ private:
MathAtom & tmplate_; MathAtom & tmplate_;
/// ///
mutable MathXArray expanded_; mutable MathXArray expanded_;
///
mutable MathMetricsInfo mi_;
}; };

View File

@ -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_) { if (expanded_) {
xcell(0).metrics(st); xcell(0).metrics(mi_);
width_ = xcell(0).width(); width_ = xcell(0).width();
ascent_ = xcell(0).ascent(); ascent_ = xcell(0).ascent();
descent_ = xcell(0).descent(); descent_ = xcell(0).descent();
} else } 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_) if (expanded_)
xcell(0).draw(pain, x, y); xcell(0).draw(pain, x, y);
else else
drawStr(pain, LM_TC_TEX, size_, x, y, str_); drawStr(pain, LM_TC_TEX, mi_, x, y, str_);
} }

View File

@ -37,6 +37,8 @@ private:
char str_[3]; char str_[3];
/// ///
bool expanded_; bool expanded_;
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -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); xcell(0).metrics(mi);
size_ = st;
width_ = xcell(0).width() + 4; width_ = xcell(0).width() + 4;
ascent_ = xcell(0).ascent() + 2; ascent_ = xcell(0).ascent() + 2;
descent_ = xcell(0).descent() + 2; descent_ = xcell(0).descent() + 2;

View File

@ -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; mi_ = mi;
size_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; mi_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
// let the cells adjust themselves // let the cells adjust themselves
MathGridInset::metrics(size_); MathGridInset::metrics(mi_);
if (display()) { if (display()) {
ascent_ += 12; ascent_ += 12;
@ -156,7 +156,7 @@ void MathMatrixInset::metrics(MathMetricsInfo const & st) const
if (numberedType()) { if (numberedType()) {
int l = 0; int l = 0;
for (row_type row = 0; row < nrows(); ++row) 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) if (l)
width_ += 30 + 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 // make it at least as high as the current font
int asc = 0; int asc = 0;
int des = 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); ascent_ = std::max(ascent_, asc);
descent_ = std::max(descent_, des); 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; int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
for (row_type row = 0; row < nrows(); ++row) { for (row_type row = 0; row < nrows(); ++row) {
int const yy = y + rowinfo_[row].offset_; 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));
} }
} }
} }

View File

@ -101,6 +101,8 @@ private:
std::vector<int> nonum_; std::vector<int> nonum_;
/// ///
std::vector<string> label_; std::vector<string> label_;
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -1,8 +1,9 @@
#ifndef MATH_METRICSINFO #ifndef MATH_METRICSINFO
#define MATH_METRICSINFO #define MATH_METRICSINFO
#include "lyxfont.h"
class BufferView; class BufferView;
class LyXFont;
/// Standard Math Sizes (Math mode styles) /// Standard Math Sizes (Math mode styles)
@ -21,17 +22,17 @@ enum MathStyles {
struct MathMetricsInfo { struct MathMetricsInfo {
/// ///
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) : view(v), font(f), style(s)
{} {}
/// ///
BufferView * view; BufferView * view;
/// ///
LyXFont const * font; LyXFont font;
/// ///
MathStyles style; MathStyles style;
}; };

View File

@ -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) for (idx_type i = 0; i < nargs(); ++i)
xcell(i).metrics(st); xcell(i).metrics(mi);
} }

View File

@ -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)) 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 else
mathed_char_dim(LM_TC_VAR, size_, '/', ascent_, descent_, width_); mathed_char_dim(LM_TC_VAR, mi_, '/', ascent_, descent_, width_);
width_ = 0; width_ = 0;
} }
@ -45,7 +45,7 @@ void MathNotInset::draw(Painter & pain, int x, int y) const
yo(y); yo(y);
if (math_font_available(LM_TC_CMSY)) 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 else
drawChar(pain, LM_TC_VAR, size_, x, y, '/'); drawChar(pain, LM_TC_VAR, mi_, x, y, '/');
} }

View File

@ -20,5 +20,8 @@ public:
void metrics(MathMetricsInfo const & st) const; void metrics(MathMetricsInfo const & st) const;
/// ///
void draw(Painter &, int x, int y) const; void draw(Painter &, int x, int y) const;
private:
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -19,6 +19,7 @@
#include "support/LOstream.h" #include "support/LOstream.h"
#include "Painter.h" #include "Painter.h"
MathRootInset::MathRootInset() MathRootInset::MathRootInset()
: MathNestInset(2) : 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); MathNestInset::metrics(mi);
size_ = st;
ascent_ = std::max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2; ascent_ = std::max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2; descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
width_ = xcell(0).width() + xcell(1).width() + 10; width_ = xcell(0).width() + xcell(1).width() + 10;

View File

@ -100,7 +100,7 @@ int MathScriptInset::dy1(MathInset const * nuc) const
asc += na + 2; asc += na + 2;
else else
asc = std::max(asc, na); 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; return asc;
} }
@ -162,36 +162,36 @@ int MathScriptInset::nwid(MathInset const * nuc) const
{ {
return nuc ? return nuc ?
nuc->width() : nuc->width() :
mathed_char_width(LM_TC_TEX, size_, '.'); mathed_char_width(LM_TC_TEX, mi_, '.');
} }
int MathScriptInset::nasc(MathInset const * nuc) const int MathScriptInset::nasc(MathInset const * nuc) const
{ {
return nuc ? nuc->ascent() 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 int MathScriptInset::ndes(MathInset const * nuc) const
{ {
return nuc ? nuc->descent() 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, void MathScriptInset::metrics(MathInset const * nuc,
MathMetricsInfo const & st) const MathMetricsInfo const & mi) const
{ {
MathNestInset::metrics(st); MathNestInset::metrics(mi);
if (nuc) if (nuc)
nuc->metrics(st); nuc->metrics(mi);
ascent_ = ascent(nuc); ascent_ = ascent(nuc);
descent_ = descent(nuc); descent_ = descent(nuc);
@ -215,7 +215,7 @@ void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
if (nuc) if (nuc)
nuc->draw(pain, x + dxx(nuc), y); nuc->draw(pain, x + dxx(nuc), y);
else else
drawStr(pain, LM_TC_TEX, size_, x + dxx(nuc), y, "."); drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
if (hasUp()) if (hasUp())
up().draw(pain, x + dx1(nuc), y - dy1(nuc)); up().draw(pain, x + dx1(nuc), y - dy1(nuc));

View File

@ -100,6 +100,8 @@ private:
bool script_[2]; bool script_[2];
/// ///
int limits_; int limits_;
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -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; MathMetricsInfo m = mi;
size_.style = MathStyles(key_->id); m.style = MathStyles(key_->id);
xcell(0).metrics(size_); xcell(0).metrics(m);
ascent_ = xcell(0).ascent_; ascent_ = xcell(0).ascent_;
descent_ = xcell(0).descent_; descent_ = xcell(0).descent_;
width_ = xcell(0).width_; width_ = xcell(0).width_;

View File

@ -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 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() void MathSpaceInset::incSpace()
{ {
space_ = (space_ + 1) % 6; space_ = (space_ + 1) % 6;

View File

@ -20,25 +20,25 @@ MathInset * MathSpecialCharInset::clone() const
int MathSpecialCharInset::ascent() 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 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 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); xo(x);
yo(y); yo(y);
drawChar(pain, LM_TC_CONST, size_, x, y, char_); drawChar(pain, LM_TC_CONST, mi_, x, y, char_);
} }

View File

@ -37,5 +37,7 @@ public:
private: private:
/// the character /// the character
char char_; char char_;
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -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); xcell(0).metrics(mi);
size_ = st;
ascent_ = xcell(0).ascent() + 4; ascent_ = xcell(0).ascent() + 4;
descent_ = xcell(0).descent() + 2; descent_ = xcell(0).descent() + 2;
width_ = xcell(0).width() + 12; width_ = xcell(0).width() + 12;

View File

@ -17,12 +17,12 @@ MathInset * MathStackrelInset::clone() const
} }
void MathStackrelInset::metrics(MathMetricsInfo const & st) const void MathStackrelInset::metrics(MathMetricsInfo const & mi) const
{ {
size_ = st; MathMetricsInfo m = mi;
smallerStyleFrac(size_); smallerStyleFrac(m);
xcell(0).metrics(size_); xcell(0).metrics(m);
xcell(1).metrics(st); xcell(1).metrics(mi);
width_ = std::max(xcell(0).width(), xcell(1).width()) + 4; width_ = std::max(xcell(0).width(), xcell(1).width()) + 4;
ascent_ = xcell(1).ascent() + xcell(0).height() + 4; ascent_ = xcell(1).ascent() + xcell(0).height() + 4;
descent_ = xcell(1).descent(); descent_ = xcell(1).descent();

View File

@ -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(); MathTextCodes c = code();
if (sym_->latex_font_id > 0 && math_font_available(c)) { 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) { if (c == LM_TC_CMEX) {
h_ = 4 * descent_ / 5; h_ = 4 * descent_ / 5;
ascent_ += h_; 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)) 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 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); yo(y);
MathTextCodes Code = code(); MathTextCodes Code = code();
if (sym_->latex_font_id > 0 && math_font_available(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)) 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 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 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;
} }

View File

@ -40,5 +40,7 @@ private:
latexkeys const * sym_; latexkeys const * sym_;
/// ///
mutable int h_; mutable int h_;
///
mutable MathMetricsInfo mi_;
}; };
#endif #endif

View File

@ -192,15 +192,8 @@ LyXFont const & whichFontBase(MathTextCodes type)
LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size) LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size)
{ {
LyXFont f = whichFontBase(type); LyXFont f = whichFontBase(type);
if (size.font) { // use actual size
#ifdef WITH_WARNINGS f.setSize(size.font.size());
#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());
}
switch (size.style) { switch (size.style) {
case LM_ST_DISPLAY: case LM_ST_DISPLAY: