2 #include "math_parboxinset.h"
3 #include "math_mathmlstream.h"
4 #include "math_streamstr.h"
9 MathParboxInset::MathParboxInset()
10 : MathNestInset(1), lyx_width_(0), tex_width_("0mm"),
13 lyxerr << "constructing MathParboxInset\n";
17 MathInset * MathParboxInset::clone() const
19 return new MathParboxInset(*this);
23 void MathParboxInset::setPosition(string const & p)
25 position_ = p.size() > 0 ? p[0] : 'c';
29 void MathParboxInset::setWidth(string const & w)
32 lyx_width_ = LyXLength(w).inBP();
33 lyxerr << "setting " << w << " to " << lyx_width_ << " pixel\n";
37 void MathParboxInset::metrics(MathMetricsInfo & mi) const
39 MathFontSetChanger dummy(mi.base, "textnormal");
41 // we do our own metrics fiddling
47 dim_ = xcell(0).metrics(mi);
51 xcell(0).metricsExternal(mi, rows_);
54 Dimension safe(0, 0, 0);
55 Dimension curr(0, 0, 0);
58 for (size_type i = 0, n = cell(0).size(); i != n; ++i) {
59 // Special handling of spaces. We reached a safe position for breaking.
60 if (cell(0)[i]->getChar() == ' ') {
65 curr = Dimension(0, 0, 0);
69 // This is a regular item. Go on if we either don't care for
70 // the width limit or have not reached that limit.
72 if (curr.w + safe.w <= lyx_width_)
75 // We passed the limit. Create a row entry.
78 // but we had a space break before this position.
80 row.glue = (lyx_width_ - safe.w) / spaces;
85 // This item is too large and it is the only one.
86 // We have no choice but to produce an overfull box.
87 row.dim = curr; // safe should be 0.
88 row.glue = 0; // does not matter
91 yo += rows_[i].dim.height();
99 row.end = cell(0).size();
100 row.glue = spaces ? (lyx_width_ - row.dim.w) / spaces : 0;
101 yo += row.dim.height();
103 rows_.push_back(row);
106 dim_ = xcell(0).dim();
112 void MathParboxInset::draw(MathPainterInfo & pi, int x, int y) const
114 MathFontSetChanger dummy(pi.base, "textnormal");
116 xcell(0).draw(pi, x + 1, y);
118 xcell(0).drawExternal(pi, x + 1, y, rows_);
120 drawMarkers(pi, x, y);
124 void MathParboxInset::write(WriteStream & os) const
127 if (position_ != 'c')
128 os << '[' << position_ << ']';
129 os << '{' << tex_width_ << "}{" << cell(0) << '}';
133 void MathParboxInset::infoize(std::ostream & os) const
135 os << "Box: Parbox " << tex_width_;