2 * \file InsetMathBox.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Ling Li (InsetMathMakebox)
9 * Full author contact details are available in file CREDITS.
14 #include "InsetMathBox.h"
16 #include "LaTeXFeatures.h"
18 #include "MathStream.h"
19 #include "MathSupport.h"
20 #include "MetricsInfo.h"
22 #include "frontends/Painter.h"
29 /////////////////////////////////////////////////////////////////////
33 /////////////////////////////////////////////////////////////////////
35 InsetMathBox::InsetMathBox(docstring const & name)
36 : InsetMathNest(1), name_(name)
40 void InsetMathBox::write(WriteStream & os) const
42 os << '\\' << name_ << '{' << cell(0) << '}';
46 void InsetMathBox::normalize(NormalStream & os) const
48 os << '[' << name_ << ' ';
49 //text_->write(buffer(), os);
54 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
56 FontSetChanger dummy(mi.base, "textnormal");
57 cell(0).metrics(mi, dim);
62 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
64 FontSetChanger dummy(pi.base, "textnormal");
65 cell(0).draw(pi, x, y);
66 drawMarkers(pi, x, y);
70 void InsetMathBox::infoize(odocstream & os) const
72 os << "Box: " << name_;
77 /////////////////////////////////////////////////////////////////////
81 /////////////////////////////////////////////////////////////////////
84 InsetMathFBox::InsetMathFBox()
89 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
91 FontSetChanger dummy(mi.base, "textnormal");
92 cell(0).metrics(mi, dim);
93 metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
97 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
99 Dimension const dim = dimension(*pi.base.bv);
100 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
101 dim.width() - 2, dim.height() - 2, Color_foreground);
102 FontSetChanger dummy(pi.base, "textnormal");
103 cell(0).draw(pi, x + 3, y);
104 setPosCache(pi, x, y);
108 void InsetMathFBox::write(WriteStream & os) const
110 os << "\\fbox{" << cell(0) << '}';
114 void InsetMathFBox::normalize(NormalStream & os) const
116 os << "[fbox " << cell(0) << ']';
120 void InsetMathFBox::infoize(odocstream & os) const
126 /////////////////////////////////////////////////////////////////////
130 /////////////////////////////////////////////////////////////////////
133 InsetMathFrameBox::InsetMathFrameBox()
138 void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
140 FontSetChanger dummy(mi.base, "textnormal");
141 w_ = mathed_char_width(mi.base.font, '[');
142 InsetMathNest::metrics(mi);
143 dim = cell(0).dimension(*mi.base.bv);
144 dim += cell(1).dimension(*mi.base.bv);
145 dim += cell(2).dimension(*mi.base.bv);
150 void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
152 FontSetChanger dummy(pi.base, "textnormal");
153 Dimension const dim = dimension(*pi.base.bv);
154 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
155 dim.width() - 2, dim.height() - 2, Color_foreground);
157 BufferView const & bv = *pi.base.bv;
159 drawStrBlack(pi, x, y, from_ascii("["));
161 cell(0).draw(pi, x, y);
162 x += cell(0).dimension(bv).wid;
163 drawStrBlack(pi, x, y, from_ascii("]"));
166 drawStrBlack(pi, x, y, from_ascii("["));
168 cell(1).draw(pi, x, y);
169 x += cell(1).dimension(bv).wid;
170 drawStrBlack(pi, x, y, from_ascii("]"));
173 cell(2).draw(pi, x, y);
174 drawMarkers(pi, x, y);
178 void InsetMathFrameBox::write(WriteStream & os) const
181 os << '[' << cell(0) << ']';
183 os << '[' << cell(1) << ']';
184 os << '{' << cell(2) << '}';
188 void InsetMathFrameBox::normalize(NormalStream & os) const
190 os << "[framebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
195 /////////////////////////////////////////////////////////////////////
199 /////////////////////////////////////////////////////////////////////
201 InsetMathBoxed::InsetMathBoxed()
206 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
208 cell(0).metrics(mi, dim);
209 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
213 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
215 Dimension const dim = dimension(*pi.base.bv);
216 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
217 dim.width() - 2, dim.height() - 2, Color_foreground);
218 cell(0).draw(pi, x + 3, y);
219 setPosCache(pi, x, y);
223 void InsetMathBoxed::write(WriteStream & os) const
225 os << "\\boxed{" << cell(0) << '}';
229 void InsetMathBoxed::normalize(NormalStream & os) const
231 os << "[boxed " << cell(0) << ']';
235 void InsetMathBoxed::infoize(odocstream & os) const
241 void InsetMathBoxed::validate(LaTeXFeatures & features) const
243 features.require("amsmath");
247 /////////////////////////////////////////////////////////////////////
251 /////////////////////////////////////////////////////////////////////
254 InsetMathMakebox::InsetMathMakebox()
259 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
261 FontSetChanger dummy(mi.base, from_ascii("textnormal"));
262 w_ = mathed_char_width(mi.base.font, '[');
263 InsetMathNest::metrics(mi);
264 dim = cell(0).dimension(*mi.base.bv);
265 dim += cell(1).dimension(*mi.base.bv);
266 dim += cell(2).dimension(*mi.base.bv);
267 dim.wid += 4 * w_ + 4;
272 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
274 FontSetChanger dummy(pi.base, from_ascii("textnormal"));
275 drawMarkers(pi, x, y);
277 drawStrBlack(pi, x, y, from_ascii("["));
279 cell(0).draw(pi, x, y);
280 x += cell(0).dimension(*pi.base.bv).width();
281 drawStrBlack(pi, x, y, from_ascii("]"));
284 drawStrBlack(pi, x, y, from_ascii("["));
286 cell(1).draw(pi, x, y);
287 x += cell(1).dimension(*pi.base.bv).wid;
288 drawStrBlack(pi, x, y, from_ascii("]"));
291 cell(2).draw(pi, x, y);
292 setPosCache(pi, x, y);
296 void InsetMathMakebox::write(WriteStream & os) const
299 os << '[' << cell(0) << ']';
301 os << '[' << cell(1) << ']';
302 os << '{' << cell(2) << '}';
306 void InsetMathMakebox::normalize(NormalStream & os) const
308 os << "[makebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
312 void InsetMathMakebox::infoize(odocstream & os) const
314 os << "Makebox (width: " << cell(0)
315 << " pos: " << cell(1) << ")";