7 #include "math_matrixinset.h"
8 #include "math_rowst.h"
9 #include "math_xiter.h"
10 #include "support/LOstream.h"
14 extern int number_of_newlines;
16 MathMatrixInset::MathMatrixInset(int m, int n, short st)
17 : MathParInset(st, "array", LM_OT_MATRIX), nc_(m), nr_(0), ws_(m),
18 v_align_(0), h_align_(nc_, 'c')
23 for (int j = 1; j < n; ++j)
26 if (nr_ == 1 && nc_ > 1) {
27 for (int j = 0; j < nc_ - 1; ++j)
28 it.insert('T', LM_TC_TAB);
38 MathedInset * MathMatrixInset::Clone()
40 return new MathMatrixInset(*this);
44 void MathMatrixInset::SetAlign(char vv, string const & hh)
47 h_align_ = hh.substr(0, nc_); // usr just h_align = hh; perhaps
51 // Check the number of tabs and crs
52 void MathMatrixInset::setData(MathedArray const & a)
56 MathedIter it(&array);
72 it.insert(' ', LM_TC_TAB);
82 // Automatically inserts tabs around bops
83 // DISABLED because it's very easy to insert tabs
87 void MathMatrixInset::draw(Painter & pain, int x, int baseline)
89 MathParInset::draw(pain, x, baseline);
94 void MathMatrixInset::Metrics()
96 // Adjust row structure
103 if (it.col >= it.ncols)
104 it.ncols = it.col + 1;
108 row_.data_.resize(nrows);
111 for (MathedRowContainer::iterator it = row_.begin(); it; ++it)
112 for (int i = 0; i <= nc_; ++i)
116 MathParInset::Metrics();
118 MathedRowContainer::iterator cxrow = row_.begin();
119 if (nc_ <= 1 && cxrow.is_last()) {
120 cxrow->ascent(ascent);
121 cxrow->descent(descent);
124 // Vertical positions of each row
125 MathedRowContainer::iterator cprow = cxrow;
127 for ( ; cxrow; ++cxrow) {
128 for (int i = 0; i < nc_; ++i) {
129 if (cxrow == row_.begin() || ws_[i] < cxrow->getTab(i))
130 ws_[i] = cxrow->getTab(i);
131 if (cxrow.is_last() && ws_[i] == 0)
135 cxrow->setBaseline((cxrow == row_.begin()) ?
137 cxrow->ascent() + cprow->descent()
138 + MATH_ROWSEP + cprow->getBaseline());
139 h += cxrow->ascent() + cxrow->descent() + MATH_ROWSEP;
143 int const hl = Descent();
146 // Compute vertical align
149 ascent = row_.begin()->getBaseline();
155 ascent = (row_.begin().is_last()) ? h / 2 : h - hl;
158 descent = h - ascent + 2;
160 // Increase ws_[i] for 'R' columns (except the first one)
161 for (int i = 1; i < nc_; ++i)
162 if (h_align_[i] == 'R')
163 ws_[i] += 10 * df_width;
164 // Increase ws_[i] for 'C' column
165 if (h_align_[0] == 'C')
166 if (ws_[0] < 7 * workWidth / 8)
167 ws_[0] = 7 * workWidth / 8;
171 for (cxrow = row_.begin(); cxrow; ++cxrow) {
172 int rg = MATH_COLSEP;
174 for (int i = 0; i < nc_; ++i) {
176 if (cxrow->getTab(i) <= 0) {
177 cxrow->setTab(i, df_width);
180 switch (h_align_[i]) {
185 lf = (ws_[i] - cxrow->getTab(i))/2;
189 lf = ws_[i] - cxrow->getTab(i);
192 if (cxrow == row_.begin())
194 else if (cxrow.is_last())
195 lf = ws_[i] - cxrow->getTab(i);
197 lf = (ws_[i] - cxrow->getTab(i))/2;
200 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
201 cxrow->setTab(i, lf + rg);
202 rg = ws_[i] - ww + MATH_COLSEP;
203 if (cxrow == row_.begin())
204 width += ws_[i] + MATH_COLSEP;
206 cxrow->setBaseline(cxrow->getBaseline() - ascent);
211 void MathMatrixInset::Write(ostream & os, bool fragile)
213 if (GetType() == LM_OT_MATRIX) {
219 if (v_align_ == 't' || v_align_ == 'b') {
227 ++number_of_newlines;
229 MathParInset::Write(os, fragile);
230 if (GetType() == LM_OT_MATRIX){
237 ++number_of_newlines;