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");
143 static docstring bracket = from_ascii("[");
144 mathed_string_dim(mi.base.font, bracket, wdim);
150 cell(0).metrics(mi, dim0);
151 cell(1).metrics(mi, dim1);
152 cell(2).metrics(mi, dim2);
154 dim.wid = 5 + w + dim0.wid + w + 4 + w + dim1.wid + w + 4 + dim2.wid + 5;
155 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
156 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
164 void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
166 drawMarkers(pi, x, y);
168 FontSetChanger dummy(pi.base, "textnormal");
169 Dimension const dim = dimension(*pi.base.bv);
170 int w = mathed_char_width(pi.base.font, '[');
172 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
173 dim.width() - 2, dim.height() - 2, Color_foreground);
176 BufferView const & bv = *pi.base.bv;
178 drawStrBlack(pi, x, y, from_ascii("["));
180 cell(0).draw(pi, x, y);
181 x += cell(0).dimension(bv).wid;
182 drawStrBlack(pi, x, y, from_ascii("]"));
185 drawStrBlack(pi, x, y, from_ascii("["));
187 cell(1).draw(pi, x, y);
188 x += cell(1).dimension(bv).wid;
189 drawStrBlack(pi, x, y, from_ascii("]"));
192 cell(2).draw(pi, x, y);
196 void InsetMathFrameBox::write(WriteStream & os) const
199 os << '[' << cell(0) << ']';
201 os << '[' << cell(1) << ']';
202 os << '{' << cell(2) << '}';
206 void InsetMathFrameBox::normalize(NormalStream & os) const
208 os << "[framebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
213 /////////////////////////////////////////////////////////////////////
217 /////////////////////////////////////////////////////////////////////
219 InsetMathBoxed::InsetMathBoxed()
224 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
226 cell(0).metrics(mi, dim);
227 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
231 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
233 Dimension const dim = dimension(*pi.base.bv);
234 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
235 dim.width() - 2, dim.height() - 2, Color_foreground);
236 cell(0).draw(pi, x + 3, y);
237 setPosCache(pi, x, y);
241 void InsetMathBoxed::write(WriteStream & os) const
243 os << "\\boxed{" << cell(0) << '}';
247 void InsetMathBoxed::normalize(NormalStream & os) const
249 os << "[boxed " << cell(0) << ']';
253 void InsetMathBoxed::infoize(odocstream & os) const
259 void InsetMathBoxed::validate(LaTeXFeatures & features) const
261 features.require("amsmath");
265 /////////////////////////////////////////////////////////////////////
269 /////////////////////////////////////////////////////////////////////
272 InsetMathMakebox::InsetMathMakebox()
277 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
279 FontSetChanger dummy(mi.base, from_ascii("textnormal"));
280 w_ = mathed_char_width(mi.base.font, '[');
281 InsetMathNest::metrics(mi);
282 dim = cell(0).dimension(*mi.base.bv);
283 dim += cell(1).dimension(*mi.base.bv);
284 dim += cell(2).dimension(*mi.base.bv);
285 dim.wid += 4 * w_ + 4;
290 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
292 FontSetChanger dummy(pi.base, from_ascii("textnormal"));
293 drawMarkers(pi, x, y);
295 drawStrBlack(pi, x, y, from_ascii("["));
297 cell(0).draw(pi, x, y);
298 x += cell(0).dimension(*pi.base.bv).width();
299 drawStrBlack(pi, x, y, from_ascii("]"));
302 drawStrBlack(pi, x, y, from_ascii("["));
304 cell(1).draw(pi, x, y);
305 x += cell(1).dimension(*pi.base.bv).wid;
306 drawStrBlack(pi, x, y, from_ascii("]"));
309 cell(2).draw(pi, x, y);
310 setPosCache(pi, x, y);
314 void InsetMathMakebox::write(WriteStream & os) const
317 os << '[' << cell(0) << ']';
319 os << '[' << cell(1) << ']';
320 os << '{' << cell(2) << '}';
324 void InsetMathMakebox::normalize(NormalStream & os) const
326 os << "[makebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
330 void InsetMathMakebox::infoize(odocstream & os) const
332 os << "Makebox (width: " << cell(0)
333 << " pos: " << cell(1) << ")";