2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
#include "math_arrayinset.h"
|
2001-11-07 13:15:59 +00:00
|
|
|
#include "math_parser.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2003-03-21 14:20:48 +00:00
|
|
|
#include "metricsinfo.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
#include "math_streamstr.h"
|
2001-11-09 08:35:57 +00:00
|
|
|
#include "Lsstream.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
#include <iterator>
|
|
|
|
|
2001-11-08 06:42:20 +00:00
|
|
|
using std::vector;
|
2001-11-09 08:35:57 +00:00
|
|
|
using std::istringstream;
|
2001-11-20 16:05:17 +00:00
|
|
|
using std::getline;
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::istream_iterator;
|
2001-11-08 06:42:20 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
MathArrayInset::MathArrayInset(string const & name, int m, int n)
|
|
|
|
: MathGridInset(m, n), name_(name)
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
MathArrayInset::MathArrayInset(string const & name, int m, int n,
|
|
|
|
char valign, string const & halign)
|
|
|
|
: MathGridInset(m, n, valign, halign), name_(name)
|
2001-10-12 12:02:49 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
MathArrayInset::MathArrayInset(string const & name, char valign,
|
|
|
|
string const & halign)
|
|
|
|
: MathGridInset(valign, halign), name_(name)
|
2001-11-28 13:09:40 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
MathArrayInset::MathArrayInset(string const & name, string const & str)
|
|
|
|
: MathGridInset(1, 1), name_(name)
|
2001-11-07 13:15:59 +00:00
|
|
|
{
|
|
|
|
vector< vector<string> > dat;
|
2003-05-28 13:22:36 +00:00
|
|
|
istringstream is(STRCONV(str));
|
2002-04-26 06:13:30 +00:00
|
|
|
string line;
|
|
|
|
while (getline(is, line)) {
|
2003-05-28 13:22:36 +00:00
|
|
|
istringstream ls(STRCONV(line));
|
2002-02-16 15:59:55 +00:00
|
|
|
typedef istream_iterator<string> iter;
|
2001-11-07 13:15:59 +00:00
|
|
|
vector<string> v = vector<string>(iter(ls), iter());
|
|
|
|
if (v.size())
|
|
|
|
dat.push_back(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (row_type row = 1; row < dat.size(); ++row)
|
|
|
|
addRow(0);
|
|
|
|
for (col_type col = 1; col < dat[0].size(); ++col)
|
|
|
|
addCol(0);
|
|
|
|
for (row_type row = 0; row < dat.size(); ++row)
|
2002-04-25 05:58:55 +00:00
|
|
|
for (col_type col = 0; col < dat[0].size(); ++col)
|
2001-11-07 13:15:59 +00:00
|
|
|
mathed_parse_cell(cell(index(row, col)), dat[row][col]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathArrayInset::clone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return new MathArrayInset(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
Dimension MathArrayInset::metrics(MetricsInfo & mi) const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
ArrayChanger dummy(mi.base);
|
2002-10-02 06:38:49 +00:00
|
|
|
MathGridInset::metrics(mi);
|
2003-05-02 07:42:08 +00:00
|
|
|
metricsMarkers2();
|
2003-05-28 13:22:36 +00:00
|
|
|
return dim_;
|
2002-10-02 06:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
void MathArrayInset::draw(PainterInfo & pi, int x, int y) const
|
2002-10-02 06:38:49 +00:00
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
ArrayChanger dummy(pi.base);
|
2003-05-28 13:22:36 +00:00
|
|
|
MathGridInset::draw(pi, x + 1, y);
|
2003-05-02 07:42:08 +00:00
|
|
|
drawMarkers2(pi, x, y);
|
2001-11-09 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathArrayInset::write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
if (os.fragile())
|
2001-06-25 00:06:33 +00:00
|
|
|
os << "\\protect";
|
2002-11-27 10:30:28 +00:00
|
|
|
os << "\\begin{" << name_ << '}';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
if (v_align_ == 't' || v_align_ == 'b')
|
2001-06-25 00:06:33 +00:00
|
|
|
os << '[' << char(v_align_) << ']';
|
2001-12-05 08:04:20 +00:00
|
|
|
os << '{' << halign() << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
MathGridInset::write(os);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
if (os.fragile())
|
2001-06-25 00:06:33 +00:00
|
|
|
os << "\\protect";
|
2002-11-27 10:30:28 +00:00
|
|
|
os << "\\end{" << name_ << '}';
|
2002-09-25 12:49:55 +00:00
|
|
|
// adding a \n here is bad if the array is the last item
|
|
|
|
// in an \eqnarray...
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-09-10 09:35:12 +00:00
|
|
|
|
|
|
|
|
2003-05-02 07:42:08 +00:00
|
|
|
void MathArrayInset::infoize(std::ostream & os) const
|
|
|
|
{
|
|
|
|
os << "Array";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathArrayInset::normalize(NormalStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '[' << name_ << ' ';
|
2001-11-09 08:35:57 +00:00
|
|
|
MathGridInset::normalize(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
os << ']';
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
void MathArrayInset::maple(MapleStream & os) const
|
2001-09-10 09:35:12 +00:00
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
os << "array(";
|
2003-02-14 14:30:09 +00:00
|
|
|
MathGridInset::maple(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
os << ')';
|
2001-09-10 09:35:12 +00:00
|
|
|
}
|