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
48 width_ = xcell(0).width();
49 ascent_ = xcell(0).ascent();
50 descent_ = xcell(0).descent();
54 xcell(0).metricsExternal(mi, rows_);
57 Dimension safe(0, 0, 0);
58 Dimension curr(0, 0, 0);
61 for (size_type i = 0, n = cell(0).size(); i != n; ++i) {
62 // Special handling of spaces. We reached a safe position for breaking.
63 if (cell(0)[i]->getChar() == ' ') {
68 curr = Dimension(0, 0, 0);
72 // This is a regular item. Go on if we either don't care for
73 // the width limit or have not reached that limit.
75 if (curr.w + safe.w <= lyx_width_)
78 // We passed the limit. Create a row entry.
81 // but we had a space break before this position.
83 row.glue = (lyx_width_ - safe.w) / spaces;
88 // This item is too large and it is the only one.
89 // We have no choice but to produce an overfull box.
90 row.dim = curr; // safe should be 0.
91 row.glue = 0; // does not matter
94 yo += rows_[i].dim.height();
102 row.end = cell(0).size();
103 row.glue = spaces ? (lyx_width_ - row.dim.w) / spaces : 0;
104 yo += row.dim.height();
106 rows_.push_back(row);
109 ascent_ = xcell(0).ascent();
110 descent_ = xcell(0).descent() + 1;
111 width_ = xcell(0).width() + 2;
116 void MathParboxInset::draw(MathPainterInfo & pi, int x, int y) const
118 MathFontSetChanger dummy(pi.base, "textnormal");
120 xcell(0).draw(pi, x + 1, y);
122 xcell(0).drawExternal(pi, x + 1, y, rows_);
124 drawMarkers(pi, x, y);
128 void MathParboxInset::write(WriteStream & os) const
131 if (position_ != 'c')
132 os << '[' << position_ << ']';
133 os << '{' << tex_width_ << "}{" << cell(0) << '}';
137 void MathParboxInset::infoize(std::ostream & os) const
139 os << "Box: Parbox " << tex_width_ << ' ';