* moved atom_dim_ to coord cache in the buffer view to make it dependent on the buffer view

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22290 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2007-12-24 10:52:58 +00:00
parent 1732e5458b
commit 7150b0caa3
31 changed files with 28 additions and 101 deletions

View File

@ -69,8 +69,6 @@ void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = 6;
dim.asc = int(h + f * h);
dim.des = int(f * h);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -38,8 +38,6 @@ void InsetMathBoldSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
cell(0).metrics(mi, dim);
metricsMarkers(dim);
++dim.wid; // for 'double stroke'
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -56,8 +56,6 @@ void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, "textnormal");
cell(0).metrics(mi, dim);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -93,8 +91,6 @@ void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, "textnormal");
cell(0).metrics(mi, dim);
metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -148,8 +144,6 @@ void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
dim += cell(1).dimension(*mi.base.bv);
dim += cell(2).dimension(*mi.base.bv);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -213,8 +207,6 @@ void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -274,8 +266,6 @@ void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
dim += cell(2).dimension(*mi.base.bv);
dim.wid += 4 * w_ + 4;
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -53,8 +53,6 @@ void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des = max(dim0.des, t.des);
dim.wid = dim0.width() + 2 * t.wid;
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -84,8 +84,6 @@ void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid += 2 * theFontMetrics(font_).width(' ');
lyxerr << "InsetMathChar::metrics: " << dim << endl;
#endif
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -45,8 +45,6 @@ void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -44,8 +44,6 @@ void InsetMathComment::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -119,8 +119,6 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
}
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -87,8 +87,6 @@ void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = dim0.width() + 2 * dw_ + 8;
dim.asc = max(a0, d0) + h0;
dim.des = max(a0, d0) - h0;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -49,8 +49,6 @@ void InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const
}
else if (key_->name == "ddots")
dh_ = dim.asc;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -36,8 +36,6 @@ void InsetMathEnv::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -45,8 +45,6 @@ Inset * InsetMathExFunc::clone() const
void InsetMathExFunc::metrics(MetricsInfo & mi, Dimension & dim) const
{
mathed_string_dim(mi.base.font, name_, dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -49,8 +49,6 @@ void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, key_->name);
cell(0).metrics(mi, dim);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -40,8 +40,6 @@ void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, key_->name.c_str());
cell(0).metrics(mi, dim);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -45,7 +45,7 @@ bool InsetMathFracBase::idxUpDown(Cursor & cur, bool up) const
if (cur.idx() == target)
return false;
cur.idx() = target;
cur.pos() = cell(target).x2pos(cur.x_target());
cur.pos() = cell(target).x2pos(&cur.bv(), cur.x_target());
return true;
}
@ -94,7 +94,7 @@ bool InsetMathFrac::idxForward(Cursor & cur) const
if (cur.idx() == target)
return false;
cur.idx() = target;
cur.pos() = cell(target).x2pos(cur.x_target());
cur.pos() = cell(target).x2pos(&cur.bv(), cur.x_target());
return true;
}
@ -112,7 +112,7 @@ bool InsetMathFrac::idxBackward(Cursor & cur) const
if (cur.idx() == target)
return false;
cur.idx() = target;
cur.pos() = cell(target).x2pos(cur.x_target());
cur.pos() = cell(target).x2pos(&cur.bv(), cur.x_target());
return true;
}
@ -168,8 +168,6 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
}
}
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -373,8 +371,6 @@ void InsetMathDFrac::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = max(dim0.wid, dim1.wid) + 2;
dim.asc = dim0.height() + 2 + 5;
dim.des = dim1.height() + 2 - 5;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -433,8 +429,6 @@ void InsetMathTFrac::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = max(dim0.width(), dim1.width()) + 2;
dim.asc = dim0.height() + 2 + 5;
dim.des = dim1.height() + 2 - 5;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -510,8 +504,6 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des = dim1.height() + 4 - 5;
dim.wid = max(dim0.width(), dim1.wid) + 2 * dw(dim.height()) + 4;
metricsMarkers2(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -584,8 +576,6 @@ void InsetMathDBinom::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des = dim1.height() + 4 - 5;
dim.wid = max(dim0.width(), dim1.wid) + 2 * dw(dim.height()) + 4;
metricsMarkers2(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -654,8 +644,6 @@ void InsetMathTBinom::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des = dim1.height() + 4 - 5;
dim.wid = max(dim0.width(), dim1.wid) + 2 * dw(dim.height()) + 4;
metricsMarkers2(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -813,7 +813,7 @@ bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
return false;
cur.idx() += ncols();
}
cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo(cur.bv()));
cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
return true;
}

View File

@ -35,8 +35,6 @@ void InsetMathLefteqn::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des += 2;
dim.wid = 4;
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -131,7 +131,7 @@ void InsetMathNest::cursorPos(BufferView const & bv,
Point const pt2 = coord_cache.getInsets().xy(this);
//lyxerr << "retrieving position cache for MathData "
// << pt.x_ << ' ' << pt.y_ << endl;
x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
x = pt.x_ - pt2.x_ + ar.pos2x(&bv, sl.pos());
y = pt.y_ - pt2.y_;
// lyxerr << "pt.y_ : " << pt.y_ << " pt2_.y_ : " << pt2.y_
// << " asc: " << ascent() << " des: " << descent()
@ -257,9 +257,9 @@ void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const
if (s1.idx() == s2.idx()) {
MathData const & c = cell(s1.idx());
Geometry const & g = bv.coordCache().getArrays().geometry(&c);
int x1 = g.pos.x_ + c.pos2x(s1.pos());
int x1 = g.pos.x_ + c.pos2x(pi.base.bv, s1.pos());
int y1 = g.pos.y_ - g.dim.ascent();
int x2 = g.pos.x_ + c.pos2x(s2.pos());
int x2 = g.pos.x_ + c.pos2x(pi.base.bv, s2.pos());
int y2 = g.pos.y_ + g.dim.descent();
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_selection);
//lyxerr << "InsetMathNest::drawing selection 3: "
@ -1231,7 +1231,7 @@ Inset * InsetMathNest::editXY(Cursor & cur, int x, int y)
MathData & ar = cell(idx_min);
cur.push(*this);
cur.idx() = idx_min;
cur.pos() = ar.x2pos(x - ar.xo(cur.bv()));
cur.pos() = ar.x2pos(&cur.bv(), x - ar.xo(cur.bv()));
//lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
if (dist_min == 0) {

View File

@ -38,8 +38,6 @@ void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = dim1.asc + dim0.height() + 4;
dim.des = dim1.des;
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -36,8 +36,6 @@ void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -43,8 +43,6 @@ void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des = max(dim0.descent() - 5, dim1.descent()) + 2;
dim.wid = dim0.width() + dim1.width() + 10;
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -340,8 +340,6 @@ void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
} else
dim.des = nd;
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -39,8 +39,6 @@ void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
StyleChanger dummy(mi.base, style_);
cell(0).metrics(mi, dim);
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -37,8 +37,6 @@ void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des += 2;
dim.wid += 12;
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -39,8 +39,6 @@ void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = dim1.ascent() + dim0.height() + 4;
dim.des = dim1.descent();
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -82,9 +82,6 @@ void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
if (sym_->inset == "cmex" || sym_->inset == "esint" ||
sym_->extra == "funclim")
scriptable_ = true;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -38,8 +38,6 @@ void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = dim1.ascent();
dim.des = dim1.descent() + dim0.height() + 4;
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -79,7 +77,7 @@ bool InsetMathUnderset::idxUpDown(Cursor & cur, bool up) const
if (cur.idx() == target)
return false;
cur.idx() = target;
cur.pos() = cur.cell().x2pos(cur.x_target());
cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target());
return true;
}

View File

@ -45,8 +45,6 @@ void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = dim0.height() + 10;
dim.des = dim1.height();
metricsMarkers(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -253,11 +253,11 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = 0;
dim.wid = 0;
Dimension d;
atom_dims_.clear();
CoordCacheBase<Inset> & coords = mi.base.bv->coordCache().insets();
for (size_t i = 0, n = size(); i != n; ++i) {
MathAtom const & at = operator[](i);
at->metrics(mi, d);
atom_dims_.push_back(d);
coords.add(at.nucleus(), d);
dim += d;
if (i == n - 1)
kerning_ = at->kerning(mi.base.bv);
@ -287,12 +287,13 @@ void MathData::draw(PainterInfo & pi, int x, int y) const
|| x >= bv. workWidth())
return;
CoordCacheBase<Inset> & coords = pi.base.bv->coordCache().insets();
for (size_t i = 0, n = size(); i != n; ++i) {
MathAtom const & at = operator[](i);
bv.coordCache().insets().add(at.nucleus(), x, y);
coords.add(at.nucleus(), x, y);
at->drawSelection(pi, x, y);
at->draw(pi, x, y);
x += atom_dims_[i].wid;
x += coords.dim(at.nucleus()).wid;
}
}
@ -733,45 +734,47 @@ void MathData::collectParameters(Cursor * cur,
}
int MathData::pos2x(size_type pos) const
int MathData::pos2x(BufferView const * bv, size_type pos) const
{
return pos2x(pos, 0);
return pos2x(bv, pos, 0);
}
int MathData::pos2x(size_type pos, int glue) const
int MathData::pos2x(BufferView const * bv, size_type pos, int glue) const
{
int x = 0;
size_type target = min(pos, size());
CoordCacheBase<Inset> const & coords = bv->coordCache().getInsets();
for (size_type i = 0; i < target; ++i) {
const_iterator it = begin() + i;
if ((*it)->getChar() == ' ')
x += glue;
//lyxerr << "char: " << (*it)->getChar()
// << "width: " << (*it)->width() << endl;
x += atom_dims_[i].wid;
x += coords.dim((*it).nucleus()).wid;
}
return x;
}
MathData::size_type MathData::x2pos(int targetx) const
MathData::size_type MathData::x2pos(BufferView const * bv, int targetx) const
{
return x2pos(targetx, 0);
return x2pos(bv, targetx, 0);
}
MathData::size_type MathData::x2pos(int targetx, int glue) const
MathData::size_type MathData::x2pos(BufferView const * bv, int targetx, int glue) const
{
const_iterator it = begin();
int lastx = 0;
int currx = 0;
CoordCacheBase<Inset> const & coords = bv->coordCache().getInsets();
// find first position after targetx
for (; currx < targetx && it < end(); ++it) {
lastx = currx;
if ((*it)->getChar() == ' ')
currx += glue;
currx += atom_dims_[it - begin()].wid;
currx += coords.dim((*it).nucleus()).wid;
}
/**

View File

@ -132,13 +132,13 @@ public:
/// write access to coordinate;
void setXY(BufferView & bv, int x, int y) const;
/// returns x coordinate of given position in the array
int pos2x(size_type pos) const;
int pos2x(BufferView const * bv, size_type pos) const;
/// returns position of given x coordinate
int pos2x(size_type pos, int glue) const;
int pos2x(BufferView const * bv, size_type pos, int glue) const;
/// returns position of given x coordinate
size_type x2pos(int pos) const;
size_type x2pos(BufferView const * bv, int pos) const;
/// returns position of given x coordinate fstarting from a certain pos
size_type x2pos(int targetx, int glue) const;
size_type x2pos(BufferView const * bv, int targetx, int glue) const;
/// returns distance of this cell to the point given by x and y
// assumes valid position and size cache
int dist(BufferView const & bv, int x, int y) const;
@ -187,8 +187,6 @@ private:
const size_type numParams, std::vector<MathData> & params,
size_t & pos, MathAtom & scriptToPutAround,
const pos_type macroPos, const int thisPos, const int thisSlice);
///
mutable std::vector<Dimension> atom_dims_;
};
///

View File

@ -137,8 +137,6 @@ void InsetLabelBox::metrics(MetricsInfo & mi, Dimension & dim) const
if (!parent_.premetrics())
dim.des += maxasc + maxdes + 1;
}
setDimCache(mi, dim);
}
@ -221,7 +219,6 @@ void DisplayLabelBox::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = 0;
dim.asc = 0;
dim.des = 0;
setDimCache(mi, dim);
}
}