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);
59 // Cache the inset dimension.
64 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
66 FontSetChanger dummy(pi.base, "textnormal");
67 cell(0).draw(pi, x, y);
68 drawMarkers(pi, x, y);
72 void InsetMathBox::infoize(odocstream & os) const
74 os << "Box: " << name_;
79 /////////////////////////////////////////////////////////////////////
83 /////////////////////////////////////////////////////////////////////
86 InsetMathFBox::InsetMathFBox()
91 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
93 FontSetChanger dummy(mi.base, "textnormal");
94 cell(0).metrics(mi, dim);
95 metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
96 // Cache the inset dimension.
101 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
103 Dimension const dim = dimension(*pi.base.bv);
104 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
105 dim.width() - 2, dim.height() - 2, Color_foreground);
106 FontSetChanger dummy(pi.base, "textnormal");
107 cell(0).draw(pi, x + 3, y);
108 setPosCache(pi, x, y);
112 void InsetMathFBox::write(WriteStream & os) const
114 os << "\\fbox{" << cell(0) << '}';
118 void InsetMathFBox::normalize(NormalStream & os) const
120 os << "[fbox " << cell(0) << ']';
124 void InsetMathFBox::infoize(odocstream & os) const
130 /////////////////////////////////////////////////////////////////////
134 /////////////////////////////////////////////////////////////////////
137 InsetMathFrameBox::InsetMathFrameBox()
142 void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
144 FontSetChanger dummy(mi.base, "textnormal");
145 w_ = mathed_char_width(mi.base.font, '[');
146 InsetMathNest::metrics(mi);
147 dim = cell(0).dimension(*mi.base.bv);
148 dim += cell(1).dimension(*mi.base.bv);
149 dim += cell(2).dimension(*mi.base.bv);
151 // Cache the inset dimension.
152 setDimCache(mi, dim);
156 void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
158 FontSetChanger dummy(pi.base, "textnormal");
159 Dimension const dim = dimension(*pi.base.bv);
160 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
161 dim.width() - 2, dim.height() - 2, Color_foreground);
163 BufferView const & bv = *pi.base.bv;
165 drawStrBlack(pi, x, y, from_ascii("["));
167 cell(0).draw(pi, x, y);
168 x += cell(0).dimension(bv).wid;
169 drawStrBlack(pi, x, y, from_ascii("]"));
172 drawStrBlack(pi, x, y, from_ascii("["));
174 cell(1).draw(pi, x, y);
175 x += cell(1).dimension(bv).wid;
176 drawStrBlack(pi, x, y, from_ascii("]"));
179 cell(2).draw(pi, x, y);
180 drawMarkers(pi, x, y);
184 void InsetMathFrameBox::write(WriteStream & os) const
187 os << '[' << cell(0) << ']';
189 os << '[' << cell(1) << ']';
190 os << '{' << cell(2) << '}';
194 void InsetMathFrameBox::normalize(NormalStream & os) const
196 os << "[framebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
201 /////////////////////////////////////////////////////////////////////
205 /////////////////////////////////////////////////////////////////////
207 InsetMathBoxed::InsetMathBoxed()
212 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
214 cell(0).metrics(mi, dim);
215 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
216 // Cache the inset dimension.
217 setDimCache(mi, dim);
221 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
223 Dimension const dim = dimension(*pi.base.bv);
224 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
225 dim.width() - 2, dim.height() - 2, Color_foreground);
226 cell(0).draw(pi, x + 3, y);
227 setPosCache(pi, x, y);
231 void InsetMathBoxed::write(WriteStream & os) const
233 os << "\\boxed{" << cell(0) << '}';
237 void InsetMathBoxed::normalize(NormalStream & os) const
239 os << "[boxed " << cell(0) << ']';
243 void InsetMathBoxed::infoize(odocstream & os) const
249 void InsetMathBoxed::validate(LaTeXFeatures & features) const
251 features.require("amsmath");
255 /////////////////////////////////////////////////////////////////////
259 /////////////////////////////////////////////////////////////////////
262 InsetMathMakebox::InsetMathMakebox()
267 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
269 FontSetChanger dummy(mi.base, from_ascii("textnormal"));
270 w_ = mathed_char_width(mi.base.font, '[');
271 InsetMathNest::metrics(mi);
272 dim = cell(0).dimension(*mi.base.bv);
273 dim += cell(1).dimension(*mi.base.bv);
274 dim += cell(2).dimension(*mi.base.bv);
275 dim.wid += 4 * w_ + 4;
277 // Cache the inset dimension.
278 setDimCache(mi, dim);
282 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
284 FontSetChanger dummy(pi.base, from_ascii("textnormal"));
285 drawMarkers(pi, x, y);
287 drawStrBlack(pi, x, y, from_ascii("["));
289 cell(0).draw(pi, x, y);
290 x += cell(0).dimension(*pi.base.bv).width();
291 drawStrBlack(pi, x, y, from_ascii("]"));
294 drawStrBlack(pi, x, y, from_ascii("["));
296 cell(1).draw(pi, x, y);
297 x += cell(1).dimension(*pi.base.bv).wid;
298 drawStrBlack(pi, x, y, from_ascii("]"));
301 cell(2).draw(pi, x, y);
302 setPosCache(pi, x, y);
306 void InsetMathMakebox::write(WriteStream & os) const
309 os << '[' << cell(0) << ']';
311 os << '[' << cell(1) << ']';
312 os << '{' << cell(2) << '}';
316 void InsetMathMakebox::normalize(NormalStream & os) const
318 os << "[makebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
322 void InsetMathMakebox::infoize(odocstream & os) const
324 os << "Makebox (width: " << cell(0)
325 << " pos: " << cell(1) << ")";