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 InsetMathMakebox::InsetMathMakebox(bool framebox)
134 : InsetMathNest(3), framebox_(framebox)
138 void InsetMathMakebox::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 = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
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));
171 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
173 drawMarkers(pi, x, y);
175 FontSetChanger dummy(pi.base, "textnormal");
176 BufferView const & bv = *pi.base.bv;
177 int w = mathed_char_width(pi.base.font, '[');
180 Dimension const dim = dimension(*pi.base.bv);
181 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
182 dim.width() - 2, dim.height() - 2, Color_foreground);
186 drawStrBlack(pi, x, y, from_ascii("["));
188 cell(0).draw(pi, x, y);
189 x += cell(0).dimension(bv).wid;
190 drawStrBlack(pi, x, y, from_ascii("]"));
193 drawStrBlack(pi, x, y, from_ascii("["));
195 cell(1).draw(pi, x, y);
196 x += cell(1).dimension(bv).wid;
197 drawStrBlack(pi, x, y, from_ascii("]"));
200 cell(2).draw(pi, x, y);
204 void InsetMathMakebox::write(WriteStream & os) const
206 os << (framebox_ ? "\\framebox" : "\\makebox");
207 if (cell(0).size() || !os.latex()) {
208 os << '[' << cell(0) << ']';
209 if (cell(1).size() || !os.latex())
210 os << '[' << cell(1) << ']';
212 os << '{' << cell(2) << '}';
216 void InsetMathMakebox::normalize(NormalStream & os) const
218 os << (framebox_ ? "[framebox " : "[makebox ")
219 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
223 void InsetMathMakebox::infoize(odocstream & os) const
225 os << (framebox_ ? "Framebox" : "Makebox")
226 << " (width: " << cell(0)
227 << " pos: " << cell(1) << ")";
231 /////////////////////////////////////////////////////////////////////
235 /////////////////////////////////////////////////////////////////////
237 InsetMathBoxed::InsetMathBoxed()
242 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
244 cell(0).metrics(mi, dim);
245 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
249 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
251 Dimension const dim = dimension(*pi.base.bv);
252 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
253 dim.width() - 2, dim.height() - 2, Color_foreground);
254 cell(0).draw(pi, x + 3, y);
255 setPosCache(pi, x, y);
259 void InsetMathBoxed::write(WriteStream & os) const
261 os << "\\boxed{" << cell(0) << '}';
265 void InsetMathBoxed::normalize(NormalStream & os) const
267 os << "[boxed " << cell(0) << ']';
271 void InsetMathBoxed::infoize(odocstream & os) const
277 void InsetMathBoxed::validate(LaTeXFeatures & features) const
279 features.require("amsmath");