- 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>
* math_inset.h:

View File

@ -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();
}

View File

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

View File

@ -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";
MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
par()->metrics(mi);
}

View File

@ -21,6 +21,7 @@
#include <iosfwd>
#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.

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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_;
///

View File

@ -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_);
}

View File

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

View File

@ -44,5 +44,7 @@ private:
mutable int dh_;
/// vertical offset cache of deco
mutable int dy_;
///
mutable MathMetricsInfo size_;
};
#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);
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;

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, 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;

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;
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;

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;
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_);
}

View File

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

View File

@ -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);
}

View File

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

View File

@ -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) {

View File

@ -24,9 +24,6 @@
#include "debug.h"
int MathInset::workwidth;
MathInset::MathInset()
: 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";
size_ = st;
}

View File

@ -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

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

View File

@ -82,6 +82,8 @@ private:
MathAtom & tmplate_;
///
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_) {
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_);
}

View File

@ -37,6 +37,8 @@ private:
char str_[3];
///
bool expanded_;
///
mutable MathMetricsInfo mi_;
};
#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);
size_ = st;
xcell(0).metrics(mi);
width_ = xcell(0).width() + 4;
ascent_ = xcell(0).ascent() + 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;
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));
}
}
}

View File

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

View File

@ -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;
};

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)
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))
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, '/');
}

View File

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

View File

@ -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;

View File

@ -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));

View File

@ -100,6 +100,8 @@ private:
bool script_[2];
///
int limits_;
///
mutable MathMetricsInfo mi_;
};
#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;
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_;

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
{
@ -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;

View File

@ -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_);
}

View File

@ -37,5 +37,7 @@ public:
private:
/// the character
char char_;
///
mutable MathMetricsInfo mi_;
};
#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);
size_ = st;
xcell(0).metrics(mi);
ascent_ = xcell(0).ascent() + 4;
descent_ = xcell(0).descent() + 2;
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;
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();

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();
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;
}

View File

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

View File

@ -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: