merge MathArray and MathXArray classes.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4843 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-08-02 14:29:42 +00:00
parent 45d1084a64
commit 00413a7841
46 changed files with 516 additions and 688 deletions

View File

@ -144,8 +144,6 @@ libmathed_la_SOURCES = \
math_undersetinset.h \
math_xarrowinset.C \
math_xarrowinset.h \
math_xdata.C \
math_xdata.h \
math_xyarrowinset.C \
math_xyarrowinset.h \
math_xymatrixinset.C \

View File

@ -20,9 +20,9 @@ void ButtonInset::metrics(MathMetricsInfo & mi) const
MathFontSetChanger dummy(mi.base, "textnormal");
if (editing()) {
MathNestInset::metrics(mi);
dim_.w = xcell(0).width() + xcell(1).width() + 4;
dim_.a = max(xcell(0).ascent(), xcell(1).ascent());
dim_.d = max(xcell(0).descent(), xcell(1).descent());
dim_.w = cell(0).width() + cell(1).width() + 4;
dim_.a = max(cell(0).ascent(), cell(1).ascent());
dim_.d = max(cell(0).descent(), cell(1).descent());
} else {
mathed_string_dim(mi.base.font, screenLabel(), dim_);
dim_.w += 10;
@ -34,8 +34,8 @@ void ButtonInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy(pi.base, "textnormal");
if (editing()) {
xcell(0).draw(pi, x, y);
xcell(1).draw(pi, x + xcell(0).width() + 2, y);
cell(0).draw(pi, x, y);
cell(1).draw(pi, x + cell(0).width() + 2, y);
mathed_draw_framebox(pi, x, y, this);
} else {
pi.pain.buttonText(x + 2, y, screenLabel(), pi.base.font);

View File

@ -34,19 +34,19 @@ int MathBinaryOpInset::opwidth() const
void MathBinaryOpInset::metrics(MathMetricsInfo & mi) const
{
mi_ = mi;
xcell(0).metrics(mi);
xcell(1).metrics(mi);
width_ = xcell(0).width() + xcell(1).width() + opwidth();
ascent_ = max(xcell(0).ascent(), xcell(1).ascent());
descent_ = max(xcell(0).descent(), xcell(1).descent());
cell(0).metrics(mi);
cell(1).metrics(mi);
width_ = cell(0).width() + cell(1).width() + opwidth();
ascent_ = max(cell(0).ascent(), cell(1).ascent());
descent_ = max(cell(0).descent(), cell(1).descent());
}
void MathBinaryOpInset::draw(MathPainterInfo & pain, int x, int y) const
{
xcell(0).draw(pain, x, y);
drawChar(pain, LM_TC_CONST, mi_, x + xcell(0).width() , y, op_);
xcell(1).draw(pain, x + width() - xcell(1).width(), y);
cell(0).draw(pain, x, y);
drawChar(pain, LM_TC_CONST, mi_, x + cell(0).width() , y, op_);
cell(1).draw(pain, x + width() - cell(1).width(), y);
}

View File

@ -38,11 +38,11 @@ int MathBinomInset::dw() const
void MathBinomInset::metrics(MathMetricsInfo & mi) const
{
MathScriptChanger(mi.base);
xcell(0).metrics(mi);
xcell(1).metrics(mi);
dim_.a = xcell(0).height() + 4 + 5;
dim_.d = xcell(1).height() + 4 - 5;
dim_.w = max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4;
cell(0).metrics(mi);
cell(1).metrics(mi);
dim_.a = cell(0).height() + 4 + 5;
dim_.d = cell(1).height() + 4 - 5;
dim_.w = max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
}
@ -50,8 +50,8 @@ void MathBinomInset::draw(MathPainterInfo & pi, int x, int y) const
{
int m = x + width() / 2;
MathScriptChanger(pi.base);
xcell(0).draw(pi, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
xcell(1).draw(pi, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 3 - 5);
mathed_draw_deco(pi, x, y - ascent(), dw(), height(), "(");
mathed_draw_deco(pi, x + width() - dw(), y - ascent(), dw(), height(), ")");
}

View File

@ -39,8 +39,8 @@ void MathBoxInset::normalize(NormalStream & os) const
void MathBoxInset::metrics(MathMetricsInfo & mi) const
{
MathFontSetChanger dummy(mi.base, "textnormal");
xcell(0).metrics(mi);
dim_ = xcell(0).dim();
cell(0).metrics(mi);
dim_ = cell(0).dim();
metricsMarkers2();
}
@ -48,7 +48,7 @@ void MathBoxInset::metrics(MathMetricsInfo & mi) const
void MathBoxInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy(pi.base, "textnormal");
xcell(0).draw(pi, x, y);
cell(0).draw(pi, x, y);
drawMarkers2(pi, x + 1, y);
}

View File

@ -33,13 +33,13 @@ MathInset * MathBraceInset::clone() const
void MathBraceInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
cell(0).metrics(mi);
Dimension t;
mathed_char_dim(mi.base.font, '{', t);
wid_ = t.w;
dim_.a = max(xcell(0).ascent(), t.a);
dim_.d = max(xcell(0).descent(), t.a);
dim_.w = xcell(0).width() + 2 * wid_;
dim_.a = max(cell(0).ascent(), t.a);
dim_.d = max(cell(0).descent(), t.a);
dim_.w = cell(0).width() + 2 * wid_;
}
@ -48,7 +48,7 @@ void MathBraceInset::draw(MathPainterInfo & pi, int x, int y) const
LyXFont font = pi.base.font;
font.setColor(LColor::latex);
drawChar(pi, font, x, y, '{');
xcell(0).draw(pi, x + wid_, y);
cell(0).draw(pi, x + wid_, y);
drawChar(pi, font, x + width() - wid_, y, '}');
}

View File

@ -830,7 +830,7 @@ void MathCursor::touch()
MathIterator::const_iterator it = Cursor_.begin();
MathIterator::const_iterator et = Cursor_.end();
for ( ; it != et; ++it)
it->xcell().touch();
it->cell().touch();
}
@ -951,19 +951,6 @@ MathArray & MathCursor::array() const
}
MathXArray & MathCursor::xarray() const
{
static MathXArray dummy;
if (depth() == 0) {
lyxerr << "############ depth() == 0 not valid\n";
return dummy;
}
return cursor().xcell();
}
void MathCursor::idxNext()
{
par()->idxNext(idx(), pos());

View File

@ -209,8 +209,6 @@ public:
///
MathArray & array() const;
///
MathXArray & xarray() const;
///
bool hasPrevAtom() const;
///
bool hasNextAtom() const;

View File

@ -16,10 +16,24 @@
#include "math_replace.h"
#include "debug.h"
#include "support/LAssert.h"
#include "math_metricsinfo.h"
#include "frontends/Painter.h"
#include "textpainter.h"
using std::max;
using std::min;
using std::abs;
MathArray::MathArray()
: xo_(0), yo_(0), clean_(false), drawn_(false)
{}
MathArray::MathArray(const_iterator from, const_iterator to)
: base_type(from, to)
: base_type(from, to), xo_(0), yo_(0), clean_(false), drawn_(false)
{}
@ -182,3 +196,194 @@ bool MathArray::contains(MathArray const & ar) const
return true;
return false;
}
void MathArray::touch() const
{
clean_ = false;
drawn_ = false;
}
Dimension const & MathArray::metrics(MathMetricsInfo & mi) const
{
//if (clean_)
// return;
clean_ = true;
drawn_ = false;
if (empty()) {
mathed_char_dim(mi.base.font, 'I', dim_);
return dim_;
}
dim_.clear();
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->metrics(mi);
dim_ += (*it)->dimensions();
}
return dim_;
}
void MathArray::draw(MathPainterInfo & pi, int x, int y) const
{
//if (drawn_ && x == xo_ && y == yo_)
// return;
//lyxerr << "MathArray::draw: x: " << x << " y: " << y << endl;
xo_ = x;
yo_ = y;
drawn_ = true;
if (y + descent() <= 0) // don't draw above the workarea
return;
if (y - ascent() >= pi.pain.paperHeight()) // don't draw below the workarea
return;
if (x + width() <= 0) // don't draw left of workarea
return;
if (x >= pi.pain.paperWidth()) // don't draw right of workarea
return;
if (empty()) {
pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline);
return;
}
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->draw(pi, x, y);
x += (*it)->width();
}
}
Dimension const & MathArray::metricsT(TextMetricsInfo const & mi) const
{
//if (clean_)
// return;
dim_.clear();
for (const_iterator it = begin(); it != end(); ++it) {
(*it)->metricsT(mi);
dim_ += (*it)->dimensions();
}
return dim_;
}
void MathArray::drawT(TextPainter & pain, int x, int y) const
{
//if (drawn_ && x == xo_ && y == yo_)
// return;
//lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
xo_ = x;
yo_ = y;
drawn_ = true;
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->drawT(pain, x, y);
x += (*it)->width();
}
}
int MathArray::pos2x(size_type pos) const
{
return pos2x(0, pos, 0);
}
int MathArray::pos2x(size_type pos1, size_type pos2, int glue) const
{
int x = 0;
size_type target = min(pos2, size());
for (size_type i = pos1; i < target; ++i) {
const_iterator it = begin() + i;
MathInset const * p = it->nucleus();
if (p->getChar() == ' ')
x += glue;
x += p->width();
}
return x;
}
MathArray::size_type MathArray::x2pos(int targetx) const
{
return x2pos(0, targetx, 0);
}
MathArray::size_type MathArray::x2pos(size_type startpos, int targetx,
int glue) const
{
const_iterator it = begin() + startpos;
int lastx = 0;
int currx = 0;
for (; currx < targetx && it < end(); ++it) {
lastx = currx;
MathInset const * p = it->nucleus();
if (p->getChar() == ' ')
currx += glue;
currx += p->width();
}
if (abs(lastx - targetx) < abs(currx - targetx) && it != begin() + startpos)
--it;
return it - begin();
}
int MathArray::dist(int x, int y) const
{
int xx = 0;
int yy = 0;
if (x < xo_)
xx = xo_ - x;
else if (x > xo_ + width())
xx = x - xo_ - width();
if (y < yo_ - ascent())
yy = yo_ - ascent() - y;
else if (y > yo_ + descent())
yy = y - yo_ - descent();
return xx + yy;
}
void MathArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
{
x1 = xo_;
x2 = xo_ + width();
y1 = yo_ - ascent();
y2 = yo_ + descent();
}
void MathArray::center(int & x, int & y) const
{
x = xo_ + width() / 2;
y = yo_ + (descent() - ascent()) / 2;
}
void MathArray::towards(int & x, int & y) const
{
int cx = 0;
int cy = 0;
center(cx, cy);
double r = 1.0;
//int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
x = cx + int(r * (x - cx));
y = cy + int(r * (y - cy));
}
/*
std::ostream & operator<<(std::ostream & os, MathArray const & ar)
{
os << ar.data();
}
*/

View File

@ -1,18 +1,17 @@
// -*- C++ -*-
/*
* Purpose: A general purpose resizable array.
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
* Created: January 1996
*
* Dependencies: None (almost)
*
* Copyright: 1996, Alejandro Aguilar Sierra
* 1997 The LyX Team!
*
* You are free to use and modify this code under the terms of
* the GNU General Public Licence version 2 or later.
*/
/** \class MathArray
\brief Low level container for math insets
\author Alejandro Aguilar Sierra
\author André Pönitz
\author Lars Gullik Bjønnes
\version February 2001
*/
#ifndef MATH_DATA_H
#define MATH_DATA_H
@ -20,10 +19,15 @@
#include <vector>
#include "math_atom.h"
#include "dimension.h"
class MathMacro;
class LaTeXFeatures;
class ReplaceData;
class MathMetricsInfo;
class MathPainterInfo;
class TextMetricsInfo;
class TextPainter;
#ifdef __GNUG__
@ -31,15 +35,6 @@ class ReplaceData;
#endif
/** \class MathArray
\brief Low level container for math insets
\author Alejandro Aguilar Sierra
\author André Pönitz
\author Lars Gullik Bjønnes
\version February 2001
*/
class MathArray : private std::vector<MathAtom> {
public:
/// re-use inhertited stuff
@ -64,7 +59,7 @@ public:
public:
///
MathArray() {}
MathArray();
///
MathArray(const_iterator from, const_iterator to);
///
@ -110,9 +105,70 @@ public:
MathAtom & operator[](pos_type);
/// checked read access
MathAtom const & operator[](pos_type) const;
/// rebuild cached metrics information
Dimension const & metrics(MathMetricsInfo & mi) const;
/// redraw cell using cache metrics information
void draw(MathPainterInfo & pi, int x, int y) const;
/// rebuild cached metrics information
Dimension const & metricsT(TextMetricsInfo const & mi) const;
/// redraw cell using cache metrics information
void drawT(TextPainter & pi, int x, int y) const;
/// mark cell for re-drawing
void touch() const;
/// access to cached x coordinate of last drawing
int xo() const { return xo_; }
/// access to cached y coordinate of last drawing
int yo() const { return yo_; }
/// access to cached x coordinate of mid point of last drawing
int xm() const { return xo_ + dim_.w / 2; }
/// access to cached y coordinate of mid point of last drawing
int ym() const { return yo_ + (dim_.d - dim_.a) / 2; }
/// returns x coordinate of given position in the array
int pos2x(size_type pos) const;
/// returns position of given x coordinate
int pos2x(size_type pos1, size_type pos2, int glue) const;
/// returns position of given x coordinate
size_type x2pos(int pos) const;
/// returns position of given x coordinate fstarting from a certain pos
size_type x2pos(size_type startpos, 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(int x, int y) const;
/// ascent of this cell above the baseline
int ascent() const { return dim_.a; }
/// descent of this cell below the baseline
int descent() const { return dim_.d; }
/// height of the cell
int height() const { return dim_.a + dim_.d; }
/// width of this cell
int width() const { return dim_.w; }
/// dimensions of cell
Dimension const & dim() const { return dim_; }
/// dimensions of cell
void setDim(Dimension const & d) const { dim_ = d; }
/// bounding box of this cell
void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
/// gives center coordinates
void center(int & x, int & y) const;
/// adjust (x,y) to point on boundary on a straight line from the center
void towards(int & x, int & y) const;
private:
/// is this an exact match at this position?
bool find1(MathArray const & ar, size_type pos) const;
/// cached dimensions of cell
mutable Dimension dim_;
/// cached x coordinate of last drawing
mutable int xo_;
/// cached y coordinate of last drawing
mutable int yo_;
/// cached cleaness of cell
mutable bool clean_;
/// cached draw status of cell
mutable bool drawn_;
};
///

View File

@ -77,8 +77,8 @@ bool MathDecorationInset::wide() const
void MathDecorationInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
dim_ = xcell(0).dim();
cell(0).metrics(mi);
dim_ = cell(0).dim();
dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
@ -96,7 +96,7 @@ void MathDecorationInset::metrics(MathMetricsInfo & mi) const
void MathDecorationInset::draw(MathPainterInfo & pi, int x, int y) const
{
xcell(0).draw(pi, x + 1, y);
cell(0).draw(pi, x + 1, y);
if (wide())
mathed_draw_deco(pi, x + 1, y + dy_, width(), dh_, key_->name);
else

View File

@ -89,15 +89,15 @@ int MathDelimInset::dw() const
void MathDelimInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
cell(0).metrics(mi);
Dimension t;
mathed_char_dim(mi.base.font, 'I', t);
int h0 = (t.a + t.d) / 2;
int a0 = max(xcell(0).ascent(), t.a) - h0;
int d0 = max(xcell(0).descent(), t.d) + h0;
int a0 = max(cell(0).ascent(), t.a) - h0;
int d0 = max(cell(0).descent(), t.d) + h0;
dim_.a = max(a0, d0) + h0;
dim_.d = max(a0, d0) - h0;
dim_.w = xcell(0).width() + 2 * dw() + 8;
dim_.w = cell(0).width() + 2 * dw() + 8;
}
@ -105,7 +105,7 @@ void MathDelimInset::draw(MathPainterInfo & pi, int x, int y) const
{
int const w = dw();
int const b = y - ascent();
xcell(0).draw(pi, x + w + 4, y);
cell(0).draw(pi, x + w + 4, y);
mathed_draw_deco(pi, x + 4, b, w, height(), left_);
mathed_draw_deco(pi, x + width() - w - 4, b, w, height(), right_);
}

View File

@ -18,8 +18,7 @@ MathInset * MathDiffInset::clone() const
void MathDiffInset::addDer(MathArray const & der)
{
cells_.push_back(MathXArray());
cells_.back().data() = der;
cells_.push_back(der);
}

View File

@ -23,14 +23,14 @@ MathInset * MathEnvInset::clone() const
void MathEnvInset::metrics(MathMetricsInfo & mi) const
{
dim_ = xcell(0).metrics(mi);
dim_ = cell(0).metrics(mi);
metricsMarkers2();
}
void MathEnvInset::draw(MathPainterInfo & pi, int x, int y) const
{
xcell(0).draw(pi, x + 1, y);
cell(0).draw(pi, x + 1, y);
drawMarkers2(pi, x, y);
}

View File

@ -544,8 +544,8 @@ void extractIntegrals(MathArray & ar)
// handle scripts if available
if (!testIntSymbol(it->nucleus())) {
p->cell(2) = it->nucleus()->asScriptInset()->down().data();
p->cell(3) = it->nucleus()->asScriptInset()->up().data();
p->cell(2) = it->nucleus()->asScriptInset()->down();
p->cell(3) = it->nucleus()->asScriptInset()->up();
}
p->cell(0) = MathArray(it + 1, jt);
@ -610,7 +610,7 @@ void extractSums(MathArray & ar)
MathScriptInset * sub = (*it)->asScriptInset();
if (sub && sub->hasDown()) {
// try to figure out the summation index from the subscript
MathArray & ar = sub->down().data();
MathArray & ar = sub->down();
MathArray::iterator xt =
find_if(ar.begin(), ar.end(), &testEqualSign);
if (xt != ar.end()) {
@ -626,7 +626,7 @@ void extractSums(MathArray & ar)
// collect upper bound
if (sub && sub->hasUp())
p->cell(3) = sub->up().data();
p->cell(3) = sub->up();
// use something behind the script as core
MathArray::iterator tt = extractArgument(p->cell(0), it + 1, ar.end());
@ -729,7 +729,7 @@ void extractDiff(MathArray & ar)
if (script && script->hasUp()) {
// things like d.../dx^n
int mult = 1;
if (extractNumber(script->up().data(), mult)) {
if (extractNumber(script->up(), mult)) {
//lyxerr << "mult: " << mult << endl;
for (int i = 0; i < mult; ++i)
diff->addDer(MathArray(dt + 1, st));
@ -785,7 +785,7 @@ void extractLims(MathArray & ar)
continue;
// and it must contain a -> symbol
MathArray & s = sub->down().data();
MathArray & s = sub->down();
MathArray::iterator st = find_if(s.begin(), s.end(), &testRightArrow);
if (st == s.end())
continue;

View File

@ -36,10 +36,10 @@ void MathFboxInset::metrics(MathMetricsInfo & mi) const
{
if (key_->name == "fbox") {
MathFontSetChanger dummy(mi.base, "textnormal");
dim_ = xcell(0).metrics(mi);
dim_ = cell(0).metrics(mi);
metricsMarkers2(5); // 5 pixels margin
} else {
dim_ = xcell(0).metrics(mi);
dim_ = cell(0).metrics(mi);
metricsMarkers2(5); // 5 pixels margin
}
}
@ -51,9 +51,9 @@ void MathFboxInset::draw(MathPainterInfo & pi, int x, int y) const
LColor::black);
if (key_->name == "fbox") {
MathFontSetChanger dummy(pi.base, "textnormal");
xcell(0).draw(pi, x + 5, y);
cell(0).draw(pi, x + 5, y);
} else {
xcell(0).draw(pi, x + 5, y);
cell(0).draw(pi, x + 5, y);
}
}

View File

@ -40,7 +40,7 @@ MathInset::mode_type MathFontInset::currentMode() const
void MathFontInset::metrics(MathMetricsInfo & mi) const
{
MathFontSetChanger dummy(mi.base, key_->name.c_str());
dim_ = xcell(0).metrics(mi);
dim_ = cell(0).metrics(mi);
metricsMarkers();
}
@ -50,21 +50,21 @@ void MathFontInset::draw(MathPainterInfo & pi, int x, int y) const
//lyxerr << "MathFontInset::draw\n";
//MathNestInset::draw(pi, x, y);
MathFontSetChanger dummy(pi.base, key_->name.c_str());
xcell(0).draw(pi, x + 1, y);
cell(0).draw(pi, x + 1, y);
drawMarkers(pi, x, y);
}
void MathFontInset::metricsT(TextMetricsInfo const & mi) const
{
dim_ = xcell(0).metricsT(mi);
dim_ = cell(0).metricsT(mi);
}
void MathFontInset::drawT(TextPainter & pain, int x, int y) const
{
//lyxerr << "drawing font code: " << code_ << '\n';
xcell(0).drawT(pain, x, y);
cell(0).drawT(pain, x, y);
}

View File

@ -31,7 +31,7 @@ MathInset * MathFontOldInset::clone() const
void MathFontOldInset::metrics(MathMetricsInfo & mi) const
{
MathFontSetChanger dummy(mi.base, key_->name.c_str());
dim_ = xcell(0).metrics(mi);
dim_ = cell(0).metrics(mi);
metricsMarkers();
}
@ -39,20 +39,20 @@ void MathFontOldInset::metrics(MathMetricsInfo & mi) const
void MathFontOldInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy(pi.base, key_->name.c_str());
xcell(0).draw(pi, x + 1, y);
cell(0).draw(pi, x + 1, y);
drawMarkers(pi, x, y);
}
void MathFontOldInset::metricsT(TextMetricsInfo const & mi) const
{
dim_ = xcell(0).metricsT(mi);
dim_ = cell(0).metricsT(mi);
}
void MathFontOldInset::drawT(TextPainter & pain, int x, int y) const
{
xcell(0).drawT(pain, x, y);
cell(0).drawT(pain, x, y);
}

View File

@ -30,6 +30,6 @@ bool MathFracbaseInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
if (idx == target)
return false;
idx = target;
pos = xcell(idx).x2pos(targetx);
pos = cell(idx).x2pos(targetx);
return true;
}

View File

@ -32,11 +32,11 @@ MathFracInset * MathFracInset::asFracInset()
void MathFracInset::metrics(MathMetricsInfo & mi) const
{
MathFracChanger dummy(mi.base);
xcell(0).metrics(mi);
xcell(1).metrics(mi);
dim_.w = max(xcell(0).width(), xcell(1).width()) + 2;
dim_.a = xcell(0).height() + 2 + 5;
dim_.d = xcell(1).height() + 2 - 5;
cell(0).metrics(mi);
cell(1).metrics(mi);
dim_.w = max(cell(0).width(), cell(1).width()) + 2;
dim_.a = cell(0).height() + 2 + 5;
dim_.d = cell(1).height() + 2 - 5;
}
@ -44,8 +44,8 @@ void MathFracInset::draw(MathPainterInfo & pi, int x, int y) const
{
int m = x + width() / 2;
MathFracChanger dummy(pi.base);
xcell(0).draw(pi, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
xcell(1).draw(pi, m - xcell(1).width() / 2, y + xcell(1).ascent() + 2 - 5);
cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5);
if (!atop_)
pi.pain.line(x + 1, y - 5, x + width() - 2, y - 5, LColor::math);
}
@ -53,19 +53,19 @@ void MathFracInset::draw(MathPainterInfo & pi, int x, int y) const
void MathFracInset::metricsT(TextMetricsInfo const & mi) const
{
xcell(0).metricsT(mi);
xcell(1).metricsT(mi);
dim_.w = max(xcell(0).width(), xcell(1).width());
dim_.a = xcell(0).height() + 1;
dim_.d = xcell(1).height();
cell(0).metricsT(mi);
cell(1).metricsT(mi);
dim_.w = max(cell(0).width(), cell(1).width());
dim_.a = cell(0).height() + 1;
dim_.d = cell(1).height();
}
void MathFracInset::drawT(TextPainter & pain, int x, int y) const
{
int m = x + width() / 2;
xcell(0).drawT(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 1);
xcell(1).drawT(pain, m - xcell(1).width() / 2, y + xcell(1).ascent());
cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
if (!atop_)
pain.horizontalLine(x, y, width());
}

View File

@ -254,7 +254,7 @@ void MathGridInset::metrics(MathMetricsInfo & mi) const
int asc = 0;
int desc = 0;
for (col_type col = 0; col < ncols(); ++col) {
MathXArray const & c = xcell(index(row, col));
MathArray const & c = cell(index(row, col));
asc = max(asc, c.ascent());
desc = max(desc, c.descent());
}
@ -297,7 +297,7 @@ void MathGridInset::metrics(MathMetricsInfo & mi) const
for (col_type col = 0; col < ncols(); ++col) {
int wid = 0;
for (row_type row = 0; row < nrows(); ++row)
wid = max(wid, xcell(index(row, col)).width());
wid = max(wid, cell(index(row, col)).width());
colinfo_[col].width_ = wid;
}
colinfo_[ncols()].width_ = 0;
@ -386,7 +386,7 @@ void MathGridInset::metrics(MathMetricsInfo & mi) const
void MathGridInset::draw(MathPainterInfo & pi, int x, int y) const
{
for (idx_type idx = 0; idx < nargs(); ++idx)
xcell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
for (row_type row = 0; row <= nrows(); ++row)
for (int i = 0; i < rowinfo_[row].lines_; ++i) {
@ -409,14 +409,14 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
// let the cells adjust themselves
//MathNestInset::metrics(mi);
for (idx_type i = 0; i < nargs(); ++i)
xcell(i).metricsT(mi);
cell(i).metricsT(mi);
// compute absolute sizes of vertical structure
for (row_type row = 0; row < nrows(); ++row) {
int asc = 0;
int desc = 0;
for (col_type col = 0; col < ncols(); ++col) {
MathXArray const & c = xcell(index(row, col));
MathArray const & c = cell(index(row, col));
asc = max(asc, c.ascent());
desc = max(desc, c.descent());
}
@ -459,7 +459,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
for (col_type col = 0; col < ncols(); ++col) {
int wid = 0;
for (row_type row = 0; row < nrows(); ++row)
wid = max(wid, xcell(index(row, col)).width());
wid = max(wid, cell(index(row, col)).width());
colinfo_[col].width_ = wid;
}
colinfo_[ncols()].width_ = 0;
@ -497,7 +497,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
void MathGridInset::drawT(TextPainter & pain, int x, int y) const
{
for (idx_type idx = 0; idx < nargs(); ++idx)
xcell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
}
@ -536,7 +536,7 @@ void MathGridInset::addRow(row_type row)
{
rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
cells_.insert
(cells_.begin() + (row + 1) * ncols(), ncols(), MathXArray());
(cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
cellinfo_.insert
(cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
}
@ -545,7 +545,7 @@ void MathGridInset::addRow(row_type row)
void MathGridInset::appendRow()
{
rowinfo_.push_back(RowInfo());
//cells_.insert(cells_.end(), ncols(), MathXArray());
//cells_.insert(cells_.end(), ncols(), MathArray());
for (col_type col = 0; col < ncols(); ++col) {
cells_.push_back(cells_type::value_type());
cellinfo_.push_back(CellInfo());
@ -617,9 +617,9 @@ int MathGridInset::cellXOffset(idx_type idx) const
int x = colinfo_[c].offset_;
char align = colinfo_[c].align_;
if (align == 'r' || align == 'R')
x += colinfo_[c].width_ - xcell(idx).width();
x += colinfo_[c].width_ - cell(idx).width();
if (align == 'c' || align == 'C')
x += (colinfo_[c].width_ - xcell(idx).width()) / 2;
x += (colinfo_[c].width_ - cell(idx).width()) / 2;
return x;
}
@ -637,13 +637,13 @@ bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
if (idx < ncols())
return false;
idx -= ncols();
pos = xcell(idx).x2pos(targetx - xcell(idx).xo());
pos = cell(idx).x2pos(targetx - cell(idx).xo());
return true;
} else {
if (idx >= ncols() * (nrows() - 1))
return false;
idx += ncols();
pos = xcell(idx).x2pos(targetx - xcell(idx).xo());
pos = cell(idx).x2pos(targetx - cell(idx).xo());
return true;
}
}

View File

@ -76,36 +76,22 @@ Dimension MathInset::dimensions() const
}
MathXArray dummyCell;
MathArray dummyCell;
MathXArray & MathInset::xcell(idx_type)
MathArray & MathInset::cell(idx_type)
{
lyxerr << "I don't have a cell 1\n";
return dummyCell;
}
MathXArray const & MathInset::xcell(idx_type) const
MathArray const & MathInset::cell(idx_type) const
{
lyxerr << "I don't have a cell 2\n";
return dummyCell;
}
MathArray & MathInset::cell(idx_type)
{
lyxerr << "I don't have a cell 3\n";
return dummyCell.data();
}
MathArray const & MathInset::cell(idx_type) const
{
lyxerr << "I don't have a cell 4\n";
return dummyCell.data();
}
MathInset::idx_type MathInset::index(row_type row, col_type col) const
{
if (row != 0)

View File

@ -30,7 +30,7 @@
#include "LString.h"
#include "frontends/mouse_state.h"
#include "math_xdata.h"
#include "math_data.h"
/**
@ -170,10 +170,6 @@ public:
virtual MathArray & cell(idx_type);
/// return cell given its number
virtual MathArray const & cell(idx_type) const;
/// return cell plus drawing cache given its number
virtual MathXArray & xcell(idx_type);
/// return cell plus drawing cache given its number
virtual MathXArray const & xcell(idx_type) const;
/// the number of columns of this inset if it is grid-like
virtual col_type ncols() const { return 1; }

View File

@ -20,16 +20,16 @@ MathInset * MathLefteqnInset::clone() const
void MathLefteqnInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
dim_.a = xcell(0).ascent() + 2;
dim_.d = xcell(0).descent() + 2;
cell(0).metrics(mi);
dim_.a = cell(0).ascent() + 2;
dim_.d = cell(0).descent() + 2;
dim_.w = 4;
}
void MathLefteqnInset::draw(MathPainterInfo & pain, int x, int y) const
{
xcell(0).draw(pain, x + 2, y);
cell(0).draw(pain, x + 2, y);
//mathed_draw_framebox(pain, x, y, this);
}

View File

@ -68,7 +68,7 @@ bool MathMacro::defining() const
void MathMacro::expand() const
{
expanded_ = tmplate_->xcell(tmplate_->cell(1).empty() ? 0 : 1);
expanded_ = tmplate_->cell(tmplate_->cell(1).empty() ? 0 : 1);
}
@ -93,7 +93,7 @@ void MathMacro::metrics(MathMetricsInfo & mi) const
mathed_string_dim(font_, "#1: ", ldim);
for (idx_type i = 0; i < nargs(); ++i) {
MathXArray const & c = xcell(i);
MathArray const & c = cell(i);
c.metrics(mi_);
dim_.w = max(dim_.w, c.width() + ldim.w);
dim_.d += max(c.ascent(), ldim.a) + 5;
@ -103,7 +103,7 @@ void MathMacro::metrics(MathMetricsInfo & mi) const
}
expand();
expanded_.data().substitute(*this);
expanded_.substitute(*this);
expanded_.metrics(mi_);
dim_ = expanded_.dim();
}
@ -133,7 +133,7 @@ void MathMacro::draw(MathPainterInfo & pi, int x, int y) const
mathed_string_dim(font_, "#1: ", ldim);
for (idx_type i = 0; i < nargs(); ++i) {
MathXArray const & c = xcell(i);
MathArray const & c = cell(i);
h += max(c.ascent(), ldim.a) + 5;
c.draw(pi, x + ldim.w, h);
char str[] = "#1:";
@ -166,12 +166,12 @@ bool MathMacro::idxUpDown(idx_type & idx, pos_type &, bool up, int x) const
if (up) {
if (!MathNestInset::idxLeft(idx, pos))
return false;
pos = xcell(idx).x2pos(x);
pos = cell(idx).x2pos(x);
return true;
} else {
if (!MathNestInset::idxRight(idx, pos))
return false;
pos = xcell(idx).x2pos(x);
pos = cell(idx).x2pos(x);
return true;
}
}
@ -200,45 +200,26 @@ void MathMacro::validate(LaTeXFeatures & features) const
void MathMacro::maplize(MapleStream & os) const
{
updateExpansion();
::maplize(expanded_.data(), os);
::maplize(expanded_, os);
}
void MathMacro::mathmlize(MathMLStream & os) const
{
updateExpansion();
::mathmlize(expanded_.data(), os);
::mathmlize(expanded_, os);
}
void MathMacro::octavize(OctaveStream & os) const
{
updateExpansion();
::octavize(expanded_.data(), os);
}
void MathMacro::normalize(NormalStream & os) const
{
os << "[macro " << name() << " ";
for (idx_type i = 0; i < nargs(); ++i)
os << cell(i) << ' ';
os << ']';
}
void MathMacro::write(WriteStream & os) const
{
os << '\\' << name();
for (idx_type i = 0; i < nargs(); ++i)
os << '{' << cell(i) << '}';
if (nargs() == 0)
os << ' ';
::octavize(expanded_, os);
}
void MathMacro::updateExpansion() const
{
expand();
expanded_.data().substitute(*this);
expanded_.substitute(*this);
}

View File

@ -40,9 +40,9 @@ public:
///
MathMacro(MathMacro const &);
///
void draw(MathPainterInfo &, int x, int y) const;
void draw(MathPainterInfo & pi, int x, int y) const;
///
void metrics(MathMetricsInfo & st) const;
void metrics(MathMetricsInfo & mi) const;
///
MathInset * clone() const;
///
@ -62,16 +62,12 @@ public:
///
bool match(MathInset *) const { return false; }
///
void normalize(NormalStream &) const;
///
void maplize(MapleStream &) const;
///
void mathmlize(MathMLStream &) const;
///
void octavize(OctaveStream &) const;
///
void write(WriteStream & os) const;
private:
///
@ -88,7 +84,7 @@ private:
///
MathAtom & tmplate_;
///
mutable MathXArray expanded_;
mutable MathArray expanded_;
///
mutable MathMetricsInfo mi_;
///

View File

@ -40,7 +40,7 @@ void MathMacroArgument::write(WriteStream & os) const
void MathMacroArgument::metrics(MathMetricsInfo & mi) const
{
if (expanded_)
dim_ = xcell(0).metrics(mi);
dim_ = cell(0).metrics(mi);
else
mathed_string_dim(mi.base.font, str_, dim_);
}
@ -49,7 +49,7 @@ void MathMacroArgument::metrics(MathMetricsInfo & mi) const
void MathMacroArgument::draw(MathPainterInfo & pi, int x, int y) const
{
if (expanded_)
xcell(0).draw(pi, x, y);
cell(0).draw(pi, x, y);
else
drawStrRed(pi, x, y, str_);
}

View File

@ -67,22 +67,22 @@ string MathMacroTemplate::name() const
void MathMacroTemplate::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
xcell(1).metrics(mi);
dim_.w = xcell(0).width() + xcell(1).width() + 10;
dim_.a = std::max(xcell(0).ascent(), xcell(1).ascent()) + 2;
dim_.d = std::max(xcell(0).descent(), xcell(1).descent()) + 2;
cell(0).metrics(mi);
cell(1).metrics(mi);
dim_.w = cell(0).width() + cell(1).width() + 10;
dim_.a = std::max(cell(0).ascent(), cell(1).ascent()) + 2;
dim_.d = std::max(cell(0).descent(), cell(1).descent()) + 2;
}
void MathMacroTemplate::draw(MathPainterInfo & pi, int x, int y) const
{
int const w0 = xcell(0).width();
int const w1 = xcell(1).width();
xcell(0).draw(pi, x + 2, y + 1);
int const w0 = cell(0).width();
int const w1 = cell(1).width();
cell(0).draw(pi, x + 2, y + 1);
pi.pain.rectangle(x, y - ascent() + 1, w0 + 4, height(),
LColor::blue);
xcell(1).draw(pi, x + 8 + w0, y + 1);
cell(1).draw(pi, x + 8 + w0, y + 1);
pi.pain.rectangle(x + w0 + 6 , y - ascent() + 1, w1 + 4,
height(), LColor::blue);
}

View File

@ -14,12 +14,14 @@ MathMetricsBase::MathMetricsBase()
MathMetricsInfo::MathMetricsInfo()
: fullredraw(false)
{}
MathPainterInfo::MathPainterInfo(Painter & p)
: pain(p)
{}

View File

@ -23,33 +23,21 @@ MathInset::idx_type MathNestInset::nargs() const
}
MathXArray & MathNestInset::xcell(idx_type i)
{
return cells_[i];
}
MathXArray const & MathNestInset::xcell(idx_type i) const
{
return cells_[i];
}
MathArray & MathNestInset::cell(idx_type i)
{
return cells_[i].data();
return cells_[i];
}
MathArray const & MathNestInset::cell(idx_type i) const
{
return cells_[i].data();
return cells_[i];
}
void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
{
MathXArray const & ar = xcell(idx);
MathArray const & ar = cell(idx);
x = ar.xo() + ar.pos2x(pos);
y = ar.yo();
// move cursor visually into empty cells ("blue rectangles");
@ -68,7 +56,7 @@ void MathNestInset::metrics(MathMetricsInfo const & mi) const
{
MathMetricsInfo m = mi;
for (idx_type i = 0; i < nargs(); ++i)
xcell(i).metrics(m);
cell(i).metrics(m);
}
@ -185,7 +173,7 @@ void MathNestInset::drawSelection(MathPainterInfo & pi,
idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
{
if (idx1 == idx2) {
MathXArray const & c = xcell(idx1);
MathArray const & c = cell(idx1);
int x1 = c.xo() + c.pos2x(pos1);
int y1 = c.yo() - c.ascent();
int x2 = c.xo() + c.pos2x(pos2);
@ -194,7 +182,7 @@ void MathNestInset::drawSelection(MathPainterInfo & pi,
} else {
for (idx_type i = 0; i < nargs(); ++i) {
if (idxBetween(i, idx1, idx2)) {
MathXArray const & c = xcell(i);
MathArray const & c = cell(i);
int x1 = c.xo();
int y1 = c.yo() - c.ascent();
int x2 = c.xo() + c.width();
@ -307,6 +295,8 @@ void MathNestInset::write(WriteStream & os) const
os << '{' << cell(i) << '}';
if (lock_ && !os.latex())
os << "\\lyxlock ";
if (nargs() == 0)
os << ' ';
}

View File

@ -74,10 +74,6 @@ public:
MathArray & cell(idx_type);
/// direct access to the cell
MathArray const & cell(idx_type) const;
/// direct access to the cell including the drawing cache
MathXArray & xcell(idx_type);
/// direct access to the cell including the drawing cache
MathXArray const & xcell(idx_type) const;
/// can we move into this cell (see macroarg.h)
bool isActive() const;
@ -105,7 +101,7 @@ public:
protected:
/// we store the cells in a vector
typedef std::vector<MathXArray> cells_type;
typedef std::vector<MathArray> cells_type;
/// thusly:
cells_type cells_;
/// if the inset is locked, it can't be entered with the cursor

View File

@ -37,20 +37,6 @@ MathArray & MathCursorPos::cell() const
}
MathXArray & MathCursorPos::xcell(MathArray::idx_type idx) const
{
lyx::Assert(par_);
return par_->xcell(idx);
}
MathXArray & MathCursorPos::xcell() const
{
lyx::Assert(par_);
return par_->xcell(idx_);
}
void MathCursorPos::getPos(int & x, int & y) const
{
par_->getPos(idx_, pos_, x, y);

View File

@ -2,7 +2,7 @@
#define MATH_POS_H
#include <iosfwd>
#include "math_xdata.h"
#include "math_data.h"
/// Description of a position
@ -17,10 +17,6 @@ public:
MathArray & cell() const;
/// returns cell corresponding to this position
MathArray & cell(MathArray::idx_type idx) const;
/// returns xcell corresponding to this position
MathXArray & xcell() const;
/// returns xcell corresponding to this position
MathXArray & xcell(MathArray::idx_type idx) const;
/// gets screen position of the thing
void getPos(int & x, int & y) const;

View File

@ -37,20 +37,20 @@ MathInset * MathRootInset::clone() const
void MathRootInset::metrics(MathMetricsInfo & mi) const
{
MathNestInset::metrics(mi);
dim_.a = max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
dim_.d = max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
dim_.w = xcell(0).width() + xcell(1).width() + 10;
dim_.a = max(cell(0).ascent() + 5, cell(1).ascent()) + 2;
dim_.d = max(cell(1).descent() + 5, cell(0).descent()) + 2;
dim_.w = cell(0).width() + cell(1).width() + 10;
metricsMarkers();
}
void MathRootInset::draw(MathPainterInfo & pi, int x, int y) const
{
int const w = xcell(0).width();
int const w = cell(0).width();
// the "exponent"
xcell(0).draw(pi, x, y - 5 - xcell(0).descent());
cell(0).draw(pi, x, y - 5 - cell(0).descent());
// the "base"
xcell(1).draw(pi, x + w + 8, y);
cell(1).draw(pi, x + w + 8, y);
int const a = ascent();
int const d = descent();
int xp[5];

View File

@ -73,27 +73,27 @@ bool MathScriptInset::idxLast(idx_type & idx, pos_type & pos) const
}
MathXArray const & MathScriptInset::down() const
MathArray const & MathScriptInset::down() const
{
return xcell(0);
return cell(0);
}
MathXArray & MathScriptInset::down()
MathArray & MathScriptInset::down()
{
return xcell(0);
return cell(0);
}
MathXArray const & MathScriptInset::up() const
MathArray const & MathScriptInset::up() const
{
return xcell(1);
return cell(1);
}
MathXArray & MathScriptInset::up()
MathArray & MathScriptInset::up()
{
return xcell(1);
return cell(1);
}
@ -103,15 +103,15 @@ void MathScriptInset::ensure(bool up)
}
MathXArray const & MathScriptInset::nuc() const
MathArray const & MathScriptInset::nuc() const
{
return xcell(2);
return cell(2);
}
MathXArray & MathScriptInset::nuc()
MathArray & MathScriptInset::nuc()
{
return xcell(2);
return cell(2);
}
@ -341,7 +341,7 @@ bool MathScriptInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
void MathScriptInset::write(WriteStream & os) const
{
if (nuc().size()) {
os << nuc().data();
os << nuc();
if (nuc().back()->takesLimits()) {
if (limits_ == -1)
os << "\\nolimits ";
@ -356,10 +356,10 @@ void MathScriptInset::write(WriteStream & os) const
}
if (hasDown() && down().size())
os << "_{" << down().data() << '}';
os << "_{" << down() << '}';
if (hasUp() && up().size())
os << "^{" << up().data() << '}';
os << "^{" << up() << '}';
if (lock_ && !os.latex())
os << "\\lyxlock ";
@ -379,27 +379,27 @@ void MathScriptInset::normalize(NormalStream & os) const
os << "[sub ";
if (nuc().size())
os << nuc().data() << ' ';
os << nuc() << ' ';
else
os << "[par]";
if (u && d)
os << down().data() << ' ' << up().data() << ']';
os << down() << ' ' << up() << ']';
else if (d)
os << down().data() << ']';
os << down() << ']';
else if (u)
os << up().data() << ']';
os << up() << ']';
}
void MathScriptInset::maplize(MapleStream & os) const
{
if (nuc().size())
os << nuc().data();
os << nuc();
if (hasDown() && down().size())
os << '[' << down().data() << ']';
os << '[' << down() << ']';
if (hasUp() && up().size())
os << "^(" << up().data() << ')';
os << "^(" << up() << ')';
}
@ -410,17 +410,17 @@ void MathScriptInset::mathematicize(MathematicaStream & os) const
if (nuc().size()) {
if (d)
os << "Subscript[" << nuc().data();
os << "Subscript[" << nuc();
else
os << nuc().data();
os << nuc();
}
if (u)
os << "^(" << up().data() << ")";
os << "^(" << up() << ")";
if (nuc().size())
if (d)
os << "," << down().data() << "]";
os << "," << down() << "]";
}
@ -437,27 +437,27 @@ void MathScriptInset::mathmlize( MathMLStream & os) const
os << MTag("msub");
if (nuc().size())
os << nuc().data();
os << nuc();
else
os << "<mrow/>";
if (u && d)
os << down().data() << up().data() << ETag("msubsup");
os << down() << up() << ETag("msubsup");
else if (u)
os << up().data() << ETag("msup");
os << up() << ETag("msup");
else if (d)
os << down().data() << ETag("msub");
os << down() << ETag("msub");
}
void MathScriptInset::octavize(OctaveStream & os) const
{
if (nuc().size())
os << nuc().data();
os << nuc();
if (hasDown() && down().size())
os << '[' << down().data() << ']';
os << '[' << down() << ']';
if (hasUp() && up().size())
os << "^(" << up().data() << ')';
os << "^(" << up() << ')';
}

View File

@ -66,17 +66,17 @@ public:
/// get limits
int limits() const { return limits_; }
/// returns subscript
MathXArray const & down() const;
MathArray const & down() const;
/// returns subscript
MathXArray & down();
MathArray & down();
/// returns superscript
MathXArray const & up() const;
MathArray const & up() const;
/// returns superscript
MathXArray & up();
MathArray & up();
/// returns nucleus
MathXArray const & nuc() const;
MathArray const & nuc() const;
/// returns nucleus
MathXArray & nuc();
MathArray & nuc();
/// do we have a superscript?
bool hasUp() const;
/// do we have a subscript?

View File

@ -27,7 +27,7 @@ MathInset * MathSizeInset::clone() const
void MathSizeInset::metrics(MathMetricsInfo & mi) const
{
MathStyleChanger dummy(mi.base, style_);
dim_ = xcell(0).metrics(mi);
dim_ = cell(0).metrics(mi);
metricsMarkers2();
}
@ -35,7 +35,7 @@ void MathSizeInset::metrics(MathMetricsInfo & mi) const
void MathSizeInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathStyleChanger dummy(pi.base, style_);
xcell(0).draw(pi, x + 1, y);
cell(0).draw(pi, x + 1, y);
drawMarkers2(pi, x, y);
}

View File

@ -22,17 +22,17 @@ MathInset * MathSqrtInset::clone() const
void MathSqrtInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
dim_.a = xcell(0).ascent() + 4;
dim_.d = xcell(0).descent() + 2;
dim_.w = xcell(0).width() + 12;
cell(0).metrics(mi);
dim_.a = cell(0).ascent() + 4;
dim_.d = cell(0).descent() + 2;
dim_.w = cell(0).width() + 12;
metricsMarkers();
}
void MathSqrtInset::draw(MathPainterInfo & pi, int x, int y) const
{
xcell(0).draw(pi, x + 10, y);
cell(0).draw(pi, x + 10, y);
int const a = ascent();
int const d = descent();
int xp[4];
@ -48,19 +48,19 @@ void MathSqrtInset::draw(MathPainterInfo & pi, int x, int y) const
void MathSqrtInset::metricsT(TextMetricsInfo const & mi) const
{
xcell(0).metricsT(mi);
dim_.a = xcell(0).ascent() + 1;
dim_.d = xcell(0).descent();
dim_.w = xcell(0).width() + 2;
cell(0).metricsT(mi);
dim_.a = cell(0).ascent() + 1;
dim_.d = cell(0).descent();
dim_.w = cell(0).width() + 2;
}
void MathSqrtInset::drawT(TextPainter & pain, int x, int y) const
{
xcell(0).drawT(pain, x + 2, y);
pain.horizontalLine(x + 2, y - xcell(0).ascent(), xcell(0).width(), '_');
pain.verticalLine (x + 1, y - xcell(0).ascent() + 1, xcell(0).height());
pain.draw(x, y + xcell(0).descent(), '\\');
cell(0).drawT(pain, x + 2, y);
pain.horizontalLine(x + 2, y - cell(0).ascent(), cell(0).width(), '_');
pain.verticalLine (x + 1, y - cell(0).ascent() + 1, cell(0).height());
pain.draw(x, y + cell(0).descent(), '\\');
}

View File

@ -22,22 +22,22 @@ MathInset * MathStackrelInset::clone() const
void MathStackrelInset::metrics(MathMetricsInfo & mi) const
{
xcell(1).metrics(mi);
cell(1).metrics(mi);
MathFracChanger dummy(mi.base);
xcell(0).metrics(mi);
dim_.w = max(xcell(0).width(), xcell(1).width()) + 4;
dim_.a = xcell(1).ascent() + xcell(0).height() + 4;
dim_.d = xcell(1).descent();
cell(0).metrics(mi);
dim_.w = max(cell(0).width(), cell(1).width()) + 4;
dim_.a = cell(1).ascent() + cell(0).height() + 4;
dim_.d = cell(1).descent();
}
void MathStackrelInset::draw(MathPainterInfo & pi, int x, int y) const
{
int m = x + width() / 2;
int yo = y - xcell(1).ascent() - xcell(0).descent() - 1;
xcell(1).draw(pi, m - xcell(1).width() / 2, y);
int yo = y - cell(1).ascent() - cell(0).descent() - 1;
cell(1).draw(pi, m - cell(1).width() / 2, y);
MathFracChanger dummy(pi.base);
xcell(0).draw(pi, m - xcell(0).width() / 2, yo);
cell(0).draw(pi, m - cell(0).width() / 2, yo);
}

View File

@ -34,7 +34,7 @@ void MathTextInset::getPos(idx_type, pos_type pos, int & x, int & y) const
bool MathTextInset::idxUpDown(idx_type &, pos_type & pos, bool up,
int targetx) const
int /*targetx*/) const
{
// try to move only one screen row up or down if possible
idx_type i = pos2row(pos);
@ -50,14 +50,14 @@ bool MathTextInset::idxUpDown(idx_type &, pos_type & pos, bool up,
return false;
}
MathGridInset::CellInfo const & cell2 = cache_.cellinfo_[i];
pos = xcell(0).x2pos(cell2.begin_, x, cell2.glue_);
pos = cell(0).x2pos(cell2.begin_, x, cell2.glue_);
return true;
}
void MathTextInset::metrics(MathMetricsInfo & mi) const
{
xcell(0).metrics(mi);
cell(0).metrics(mi);
// we do our own metrics fiddling
// delete old cache
@ -104,7 +104,7 @@ void MathTextInset::metrics(MathMetricsInfo & mi) const
// We passed the limit. Create a row entry.
//lyxerr << "passed limit\n";
cache_.appendRow();
MathXArray & ar = cache_.xcell(cache_.nargs() - 1);
MathArray & ar = cache_.cell(cache_.nargs() - 1);
MathGridInset::CellInfo & row = cache_.cellinfo_.back();
if (c == '\n') {
// we are here because we hit a hard newline
@ -129,8 +129,7 @@ void MathTextInset::metrics(MathMetricsInfo & mi) const
row.end_ = i + 1;
begin = i + 1;
}
ar.data() =
MathArray(cell(0).begin() + row.begin_, cell(0).begin() + row.end_);
ar = MathArray(cell(0).begin() + row.begin_, cell(0).begin() + row.end_);
//lyxerr << "line: " << ar << "\n";
// in any case, start the new row with empty boxes
curr = 0;
@ -138,12 +137,11 @@ void MathTextInset::metrics(MathMetricsInfo & mi) const
}
// last row: put in everything else
cache_.appendRow();
MathXArray & ar = cache_.xcell(cache_.nargs() - 1);
MathArray & ar = cache_.cell(cache_.nargs() - 1);
MathGridInset::CellInfo & row = cache_.cellinfo_.back();
row.begin_ = begin;
row.end_ = cell(0).size();
ar.data() =
MathArray(cell(0).begin() + row.begin_, cell(0).begin() + row.end_);
ar = MathArray(cell(0).begin() + row.begin_, cell(0).begin() + row.end_);
//lyxerr << "last line: " << ar.data() << "\n";
// what to report?

View File

@ -22,22 +22,22 @@ MathInset * MathUndersetInset::clone() const
void MathUndersetInset::metrics(MathMetricsInfo & mi) const
{
xcell(1).metrics(mi);
cell(1).metrics(mi);
MathFracChanger dummy(mi.base);
xcell(0).metrics(mi);
dim_.w = max(xcell(0).width(), xcell(1).width()) + 4;
dim_.a = xcell(1).ascent();
dim_.d = xcell(1).descent() + xcell(0).height() + 4;
cell(0).metrics(mi);
dim_.w = max(cell(0).width(), cell(1).width()) + 4;
dim_.a = cell(1).ascent();
dim_.d = cell(1).descent() + cell(0).height() + 4;
}
void MathUndersetInset::draw(MathPainterInfo & pi, int x, int y) const
{
int m = x + width() / 2;
int yo = y + xcell(1).descent() + xcell(0).ascent() + 1;
xcell(1).draw(pi, m - xcell(1).width() / 2, y);
int yo = y + cell(1).descent() + cell(0).ascent() + 1;
cell(1).draw(pi, m - cell(1).width() / 2, y);
MathFracChanger dummy(pi.base);
xcell(0).draw(pi, m - xcell(0).width() / 2, yo);
cell(0).draw(pi, m - cell(0).width() / 2, yo);
}

View File

@ -26,16 +26,16 @@ void MathXArrowInset::metrics(MathMetricsInfo & mi) const
{
//MathMetricsInfo mi = st;
//smallerStyleScript(mi);
xcell(0).metrics(mi);
dim_.w = xcell(0).width() + 10;
dim_.a = xcell(0).height() + 10;
cell(0).metrics(mi);
dim_.w = cell(0).width() + 10;
dim_.a = cell(0).height() + 10;
dim_.d = 0;
}
void MathXArrowInset::draw(MathPainterInfo & pain, int x, int y) const
{
xcell(0).draw(pain, x + 5, y - 10);
cell(0).draw(pain, x + 5, y - 10);
mathed_draw_deco(pain, x + 1, y - 7, width() - 2, 5, name_);
}

View File

@ -1,230 +0,0 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_xdata.h"
#include "math_metricsinfo.h"
#include "math_support.h"
#include "math_inset.h"
#include "frontends/Painter.h"
#include "textpainter.h"
#include "debug.h"
using std::max;
using std::min;
using std::abs;
MathXArray::MathXArray()
: xo_(0), yo_(0), clean_(false), drawn_(false)
{}
void MathXArray::touch() const
{
clean_ = false;
drawn_ = false;
}
Dimension const & MathXArray::metrics(MathMetricsInfo & mi) const
{
//if (clean_)
// return;
clean_ = true;
drawn_ = false;
if (empty()) {
mathed_char_dim(mi.base.font, 'I', dim_);
return dim_;
}
dim_.clear();
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->metrics(mi);
dim_ += (*it)->dimensions();
}
return dim_;
}
void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
{
//if (drawn_ && x == xo_ && y == yo_)
// return;
//lyxerr << "MathXArray::draw: x: " << x << " y: " << y << endl;
xo_ = x;
yo_ = y;
drawn_ = true;
if (y + descent() <= 0) // don't draw above the workarea
return;
if (y - ascent() >= pi.pain.paperHeight()) // don't draw below the workarea
return;
if (x + width() <= 0) // don't draw left of workarea
return;
if (x >= pi.pain.paperWidth()) // don't draw right of workarea
return;
if (empty()) {
pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline);
return;
}
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->draw(pi, x, y);
x += (*it)->width();
}
}
Dimension const & MathXArray::metricsT(TextMetricsInfo const & mi) const
{
//if (clean_)
// return;
dim_.clear();
for (const_iterator it = begin(); it != end(); ++it) {
(*it)->metricsT(mi);
dim_ += (*it)->dimensions();
}
return dim_;
}
void MathXArray::drawT(TextPainter & pain, int x, int y) const
{
//if (drawn_ && x == xo_ && y == yo_)
// return;
//lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
xo_ = x;
yo_ = y;
drawn_ = true;
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->drawT(pain, x, y);
x += (*it)->width();
}
}
int MathXArray::pos2x(size_type pos) const
{
return pos2x(0, pos, 0);
}
int MathXArray::pos2x(size_type pos1, size_type pos2, int glue) const
{
int x = 0;
size_type target = min(pos2, size());
for (size_type i = pos1; i < target; ++i) {
const_iterator it = begin() + i;
MathInset const * p = it->nucleus();
if (p->getChar() == ' ')
x += glue;
x += p->width();
}
return x;
}
MathArray::size_type MathXArray::x2pos(int targetx) const
{
return x2pos(0, targetx, 0);
}
MathArray::size_type MathXArray::x2pos(size_type startpos, int targetx,
int glue) const
{
const_iterator it = begin() + startpos;
int lastx = 0;
int currx = 0;
for (; currx < targetx && it < end(); ++it) {
lastx = currx;
MathInset const * p = it->nucleus();
if (p->getChar() == ' ')
currx += glue;
currx += p->width();
}
if (abs(lastx - targetx) < abs(currx - targetx) && it != begin() + startpos)
--it;
return it - begin();
}
int MathXArray::dist(int x, int y) const
{
int xx = 0;
int yy = 0;
if (x < xo_)
xx = xo_ - x;
else if (x > xo_ + width())
xx = x - xo_ - width();
if (y < yo_ - ascent())
yy = yo_ - ascent() - y;
else if (y > yo_ + descent())
yy = y - yo_ - descent();
return xx + yy;
}
void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
{
x1 = xo_;
x2 = xo_ + width();
y1 = yo_ - ascent();
y2 = yo_ + descent();
}
/*
void MathXArray::findPos(MathPosFinder & f) const
{
double x = xo_;
double y = yo_;
for (const_iterator it = begin(); it < end(); ++it) {
// check this position in the cell first
f.visit(x, y);
f.nextPos();
// check inset
MathInset const * p = it->nucleus();
p->findPos(f);
x += p->width();
}
}
*/
void MathXArray::center(int & x, int & y) const
{
x = xo_ + width() / 2;
y = yo_ + (descent() - ascent()) / 2;
}
void MathXArray::towards(int & x, int & y) const
{
int cx = 0;
int cy = 0;
center(cx, cy);
double r = 1.0;
//int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
x = cx + int(r * (x - cx));
y = cy + int(r * (y - cy));
}
std::ostream & operator<<(std::ostream & os, MathXArray const & ar)
{
os << ar.data();
}

View File

@ -1,112 +0,0 @@
// -*- C++ -*-
#ifndef MATHEDXARRAY_H
#define MATHEDXARRAY_H
#include <iosfwd>
#include "math_data.h"
//#include "math_metricsinfo.h"
#include "dimension.h"
#ifdef __GNUG__
#pragma interface
#endif
class MathMetricsInfo;
class MathPainterInfo;
class TextMetricsInfo;
class TextPainter;
/** This class extends a MathArray by drawing routines and caches for
* metric information.
*/
class MathXArray : private MathArray
{
public:
// re-use inherited stuff
using MathArray::size_type;
using MathArray::const_iterator;
using MathArray::begin;
using MathArray::end;
using MathArray::operator[];
using MathArray::clear;
using MathArray::size;
using MathArray::empty;
using MathArray::back;
MathArray & data() { return *this; }
MathArray const & data() const { return *this; }
/// constructor
MathXArray();
/// rebuild cached metrics information
Dimension const & metrics(MathMetricsInfo & mi) const;
/// redraw cell using cache metrics information
void draw(MathPainterInfo & pi, int x, int y) const;
/// rebuild cached metrics information
Dimension const & metricsT(TextMetricsInfo const & mi) const;
/// redraw cell using cache metrics information
void drawT(TextPainter & pi, int x, int y) const;
/// mark cell for re-drawing
void touch() const;
/// access to cached x coordinate of last drawing
int xo() const { return xo_; }
/// access to cached y coordinate of last drawing
int yo() const { return yo_; }
/// access to cached x coordinate of mid point of last drawing
int xm() const { return xo_ + dim_.w / 2; }
/// access to cached y coordinate of mid point of last drawing
int ym() const { return yo_ + (dim_.d - dim_.a) / 2; }
/// returns x coordinate of given position in the array
int pos2x(size_type pos) const;
/// returns position of given x coordinate
int pos2x(size_type pos1, size_type pos2, int glue) const;
/// returns position of given x coordinate
size_type x2pos(int pos) const;
/// returns position of given x coordinate fstarting from a certain pos
size_type x2pos(size_type startpos, 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(int x, int y) const;
/// ascent of this cell above the baseline
int ascent() const { return dim_.a; }
/// descent of this cell below the baseline
int descent() const { return dim_.d; }
/// height of the cell
int height() const { return dim_.a + dim_.d; }
/// width of this cell
int width() const { return dim_.w; }
/// dimensions of cell
Dimension const & dim() const { return dim_; }
/// dimensions of cell
void setDim(Dimension const & d) const { dim_ = d; }
/// bounding box of this cell
void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
/// find best position to do things
//void findPos(PosFinder &) const;
/// gives center coordinates
void center(int & x, int & y) const;
/// adjust (x,y) to point on boundary on a straight line from the center
void towards(int & x, int & y) const;
private:
/// cached dimensions of cell
mutable Dimension dim_;
/// cached x coordinate of last drawing
mutable int xo_;
/// cached y coordinate of last drawing
mutable int yo_;
/// cached cleaness of cell
mutable bool clean_;
/// cached draw status of cell
mutable bool drawn_;
};
/// output cell on a stream
std::ostream & operator<<(std::ostream & os, MathXArray const & ar);
#endif

View File

@ -33,7 +33,7 @@ MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
}
MathXArray const & MathXYArrowInset::targetCell() const
MathArray const & MathXYArrowInset::targetCell() const
{
#if 0
MathXYMatrixInset const * p = targetMatrix();
@ -55,20 +55,20 @@ MathXArray const & MathXYArrowInset::targetCell() const
lyxerr << "target: n: " << n << " out of range\n";
n = 0;
}
return p->xcell(n);
return p->cell(n);
#else
static MathXArray dummy;
static MathArray dummy;
return dummy;
#endif
}
MathXArray const & MathXYArrowInset::sourceCell() const
MathArray const & MathXYArrowInset::sourceCell() const
{
#if 0
return targetMatrix()->xcell(mi_.idx);
return targetMatrix()->cell(mi_.idx);
#else
static MathXArray dummy;
static MathArray dummy;
return dummy;
#endif
}
@ -84,9 +84,9 @@ void MathXYArrowInset::metrics(MathMetricsInfo & mi) const
if (editing()) {
int w = mathed_string_width(mi.base.font, "target: ");
width_ = w + max(xcell(0).width(), xcell(1).width());
ascent_ = xcell(0).ascent();
descent_ = xcell(0).descent() + xcell(1).height() + 10;
width_ = w + max(cell(0).width(), cell(1).width());
ascent_ = cell(0).ascent();
descent_ = cell(0).descent() + cell(1).height() + 10;
} else {
width_ = 0;
ascent_ = 0;
@ -111,12 +111,12 @@ void MathXYArrowInset::draw(MathPainterInfo & pi, int x, int y) const
int lwid;
mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
xcell(0).draw(pi, x + lwid, y);
cell(0).draw(pi, x + lwid, y);
drawStr(pi, pi.base.font, x + 3, y, "target");
y += max(xcell(0).descent(), ldes) + 5;
y += max(cell(0).descent(), ldes) + 5;
y += max(xcell(1).ascent(), lasc) + 5;
xcell(1).draw(pi, x + lwid, y);
y += max(cell(1).ascent(), lasc) + 5;
cell(1).draw(pi, x + lwid, y);
drawStr(pi, pi.base.font, x + 3, y, "label");
#endif
@ -124,10 +124,10 @@ void MathXYArrowInset::draw(MathPainterInfo & pi, int x, int y) const
} else {
drawStr(pi, font_, x, y, "X");
MathXArray const & s = sourceCell();
MathXArray const & t = targetCell();
MathArray const & s = sourceCell();
MathArray const & t = targetCell();
pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
xcell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
}
}

View File

@ -37,9 +37,9 @@ public:
///
MathXYMatrixInset const * targetMatrix() const;
///
MathXArray const & targetCell() const;
MathArray const & targetCell() const;
///
MathXArray const & sourceCell() const;
MathArray const & sourceCell() const;
///
bool up_;