use a single function dimension() instead of three.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4554 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-07-08 16:20:53 +00:00
parent b27dffb7af
commit ec27454801
9 changed files with 57 additions and 45 deletions

View File

@ -61,3 +61,9 @@ void MathCasesInset::maplize(MapleStream & os) const
MathGridInset::maplize(os);
os << ")";
}
void MathCasesInset::infoize(std::ostream & os) const
{
os << "Cases ";
}

View File

@ -20,6 +20,8 @@ public:
///
void draw(MathPainterInfo & pain, int x, int y) const;
///
void infoize(std::ostream & os) const;
///
void normalize(NormalStream &) const;
///

View File

@ -3,6 +3,14 @@
#include "textpainter.h"
void MathDimInset::dimensions(int & w, int & a, int & d) const
{
w = width_;
a = ascent_;
d = descent_;
}
void MathDimInset::metricsT(TextMetricsInfo const &) const
{
std::ostringstream os;

View File

@ -16,6 +16,8 @@ public:
int descent() const { return descent_; }
/// read width
int width() const { return width_; }
///
void dimensions(int & w, int & a, int & d) const;
///
void metricsT(TextMetricsInfo const &) const;
///

View File

@ -68,6 +68,14 @@ MathInset::size_type MathInset::nargs() const
}
void MathInset::dimensions(int & w, int & a, int & d) const
{
w = width();
a = ascent();
d = descent();
}
MathXArray dummyCell;
MathXArray & MathInset::xcell(idx_type)

View File

@ -128,6 +128,8 @@ public:
virtual int descent() const { return 1; }
/// total width
virtual int width() const { return 2; }
/// all in one batch
virtual void dimensions(int & w, int & a, int & d) const;
/// total height (== ascent + descent)
virtual int height() const;

View File

@ -127,35 +127,32 @@ int MathScriptInset::dxx(MathInset const * nuc) const
}
int MathScriptInset::ascent2(MathInset const * nuc) const
void MathScriptInset::dimensions2
(MathInset const * nuc, int & w, int & a, int & d) const
{
return dy1(nuc) + (hasUp() ? up().ascent() : 0);
}
int MathScriptInset::descent2(MathInset const * nuc) const
{
return dy0(nuc) + (hasDown() ? down().descent() : 0);
a = dy1(nuc) + (hasUp() ? up().ascent() : 0);
d = dy0(nuc) + (hasDown() ? down().descent() : 0);
w = width2(nuc);
}
int MathScriptInset::width2(MathInset const * nuc) const
{
int wid = 0;
int w = 0;
if (hasLimits(nuc)) {
wid = nwid(nuc);
w = nwid(nuc);
if (hasUp())
wid = max(wid, up().width());
w = max(w, up().width());
if (hasDown())
wid = max(wid, down().width());
w = max(w, down().width());
} else {
if (hasUp())
wid = max(wid, up().width());
w = max(w, up().width());
if (hasDown())
wid = max(wid, down().width());
wid += nwid(nuc);
w = max(w, down().width());
w += nwid(nuc);
}
return wid;
return w;
}
@ -189,9 +186,7 @@ void MathScriptInset::metrics(MathInset const * nuc, MathMetricsInfo & mi) const
nuc->metrics(mi);
MathNestInset::metrics(mi);
MathScriptChanger dummy(mi.base);
ascent_ = ascent2(nuc);
descent_ = descent2(nuc);
width_ = width2(nuc);
dimensions2(nuc, width_, ascent_, descent_);
}

View File

@ -41,11 +41,9 @@ public:
void metricsT(MathInset const * nuc, TextMetricsInfo const & st) const;
///
void drawT(MathInset const * nuc, TextPainter &, int x, int y) const;
///
int ascent2(MathInset const * nuc) const;
///
int descent2(MathInset const * nuc) const;
///
/// helper
void dimensions2(MathInset const * nuc, int & w, int & a, int & d) const;
/// only the width
int width2(MathInset const * nuc) const;
///

View File

@ -47,32 +47,24 @@ void MathXArray::metrics(MathMetricsInfo & mi) const
}
width_ = 0;
int a = 0;
int d = 0;
ascent_ = 0;
descent_ = 0;
for (const_iterator it = begin(); it != end(); ++it) {
MathInset const * p = it->nucleus();
MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
int w = 0;
int ww, aa, dd;
if (q) {
q->metrics(p, mi);
a = max(a, q->ascent2(p));
d = max(d, q->descent2(p));
w = q->width2(p);
q->dimensions2(p, ww, aa, dd);
++it;
} else {
p->metrics(mi);
a = max(a, p->ascent());
d = max(d, p->descent());
w = p->width();
}
width_ += w;
ascent_ = max(ascent_, aa);
descent_ = max(descent_, dd);
width_ += ww;
}
ascent_ = a;
descent_ = d;
//width_ = 0;
//lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
// << descent_ << " " << width_ << "'\n";
@ -147,18 +139,17 @@ void MathXArray::metricsT(TextMetricsInfo const & mi) const
for (const_iterator it = begin(); it != end(); ++it) {
MathInset const * p = it->nucleus();
MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
int ww, aa, dd;
if (q) {
q->metricsT(p, mi);
ascent_ = max(ascent_, q->ascent2(p));
descent_ = max(descent_, q->descent2(p));
width_ += q->width2(p);
q->dimensions(ww, aa, dd);
++it;
} else {
p->metricsT(mi);
ascent_ = max(ascent_, p->ascent());
descent_ = max(descent_, p->descent());
width_ += p->width();
}
ascent_ = max(ascent_, aa);
descent_ = max(descent_, dd);
width_ += ww;
}
}