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(Buffer * buf, docstring const & name)
36 : InsetMathNest(buf, 1), name_(name)
40 void InsetMathBox::write(WriteStream & os) const
42 ModeSpecifier specifier(os, TEXT_MODE);
43 os << '\\' << name_ << '{' << cell(0) << '}';
47 void InsetMathBox::normalize(NormalStream & os) const
49 os << '[' << name_ << ' ';
50 //text_->write(buffer(), os);
55 docstring InsetMathBox::mathmlize(MathStream & ms) const
57 // FIXME This doesn't actually work yet. We need to be able to signal
58 // that we are in text mode and then just call ms << cell(0). So we
59 // need something like ModeSpecifier for MathStream.
67 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
69 FontSetChanger dummy(mi.base, "textnormal");
70 cell(0).metrics(mi, dim);
75 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
77 FontSetChanger dummy(pi.base, "textnormal");
78 cell(0).draw(pi, x, y);
79 drawMarkers(pi, x, y);
83 void InsetMathBox::infoize(odocstream & os) const
85 os << "Box: " << name_;
89 void InsetMathBox::validate(LaTeXFeatures & features) const
91 if (name_ == "tag" || name_ == "tag*")
92 features.require("amsmath");
93 cell(0).validate(features);
98 /////////////////////////////////////////////////////////////////////
102 /////////////////////////////////////////////////////////////////////
105 InsetMathFBox::InsetMathFBox(Buffer * buf)
106 : InsetMathNest(buf, 1)
110 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
112 FontSetChanger dummy(mi.base, "textnormal");
113 cell(0).metrics(mi, dim);
114 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
118 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
120 Dimension const dim = dimension(*pi.base.bv);
121 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
122 dim.width() - 2, dim.height() - 2, Color_foreground);
123 FontSetChanger dummy(pi.base, "textnormal");
124 cell(0).draw(pi, x + 3, y);
125 setPosCache(pi, x, y);
129 void InsetMathFBox::write(WriteStream & os) const
131 ModeSpecifier specifier(os, TEXT_MODE);
132 os << "\\fbox{" << cell(0) << '}';
136 void InsetMathFBox::normalize(NormalStream & os) const
138 os << "[fbox " << cell(0) << ']';
142 void InsetMathFBox::infoize(odocstream & os) const
148 /////////////////////////////////////////////////////////////////////
152 /////////////////////////////////////////////////////////////////////
155 InsetMathMakebox::InsetMathMakebox(Buffer * buf, bool framebox)
156 : InsetMathNest(buf, 3), framebox_(framebox)
160 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
162 FontSetChanger dummy(mi.base, "textnormal");
165 static docstring bracket = from_ascii("[");
166 mathed_string_dim(mi.base.font, bracket, wdim);
172 cell(0).metrics(mi, dim0);
173 cell(1).metrics(mi, dim1);
174 cell(2).metrics(mi, dim2);
176 dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
177 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
178 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
193 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
195 drawMarkers(pi, x, y);
197 FontSetChanger dummy(pi.base, "textnormal");
198 BufferView const & bv = *pi.base.bv;
199 int w = mathed_char_width(pi.base.font, '[');
202 Dimension const dim = dimension(*pi.base.bv);
203 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
204 dim.width() - 2, dim.height() - 2, Color_foreground);
208 drawStrBlack(pi, x, y, from_ascii("["));
210 cell(0).draw(pi, x, y);
211 x += cell(0).dimension(bv).wid;
212 drawStrBlack(pi, x, y, from_ascii("]"));
215 drawStrBlack(pi, x, y, from_ascii("["));
217 cell(1).draw(pi, x, y);
218 x += cell(1).dimension(bv).wid;
219 drawStrBlack(pi, x, y, from_ascii("]"));
222 cell(2).draw(pi, x, y);
226 void InsetMathMakebox::write(WriteStream & os) const
228 ModeSpecifier specifier(os, TEXT_MODE);
229 os << (framebox_ ? "\\framebox" : "\\makebox");
230 if (cell(0).size() || !os.latex()) {
231 os << '[' << cell(0) << ']';
232 if (cell(1).size() || !os.latex())
233 os << '[' << cell(1) << ']';
235 os << '{' << cell(2) << '}';
239 void InsetMathMakebox::normalize(NormalStream & os) const
241 os << (framebox_ ? "[framebox " : "[makebox ")
242 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
246 void InsetMathMakebox::infoize(odocstream & os) const
248 os << (framebox_ ? "Framebox" : "Makebox")
249 << " (width: " << cell(0)
250 << " pos: " << cell(1) << ")";
254 /////////////////////////////////////////////////////////////////////
258 /////////////////////////////////////////////////////////////////////
260 InsetMathBoxed::InsetMathBoxed(Buffer * buf)
261 : InsetMathNest(buf, 1)
265 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
267 cell(0).metrics(mi, dim);
268 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
272 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
274 Dimension const dim = dimension(*pi.base.bv);
275 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
276 dim.width() - 2, dim.height() - 2, Color_foreground);
277 cell(0).draw(pi, x + 3, y);
278 setPosCache(pi, x, y);
282 void InsetMathBoxed::write(WriteStream & os) const
284 ModeSpecifier specifier(os, MATH_MODE);
285 os << "\\boxed{" << cell(0) << '}';
289 void InsetMathBoxed::normalize(NormalStream & os) const
291 os << "[boxed " << cell(0) << ']';
295 void InsetMathBoxed::infoize(odocstream & os) const
301 void InsetMathBoxed::validate(LaTeXFeatures & features) const
303 features.require("amsmath");
304 InsetMathNest::validate(features);