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 void 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.
66 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
68 FontSetChanger dummy(mi.base, "textnormal");
69 cell(0).metrics(mi, dim);
74 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
76 FontSetChanger dummy(pi.base, "textnormal");
77 cell(0).draw(pi, x, y);
78 drawMarkers(pi, x, y);
82 void InsetMathBox::infoize(odocstream & os) const
84 os << "Box: " << name_;
88 void InsetMathBox::validate(LaTeXFeatures & features) const
90 if (name_ == "tag" || name_ == "tag*")
91 features.require("amsmath");
92 cell(0).validate(features);
97 /////////////////////////////////////////////////////////////////////
101 /////////////////////////////////////////////////////////////////////
104 InsetMathFBox::InsetMathFBox(Buffer * buf)
105 : InsetMathNest(buf, 1)
109 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
111 FontSetChanger dummy(mi.base, "textnormal");
112 cell(0).metrics(mi, dim);
113 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
117 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
119 Dimension const dim = dimension(*pi.base.bv);
120 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
121 dim.width() - 2, dim.height() - 2, Color_foreground);
122 FontSetChanger dummy(pi.base, "textnormal");
123 cell(0).draw(pi, x + 3, y);
124 setPosCache(pi, x, y);
128 void InsetMathFBox::write(WriteStream & os) const
130 ModeSpecifier specifier(os, TEXT_MODE);
131 os << "\\fbox{" << cell(0) << '}';
135 void InsetMathFBox::normalize(NormalStream & os) const
137 os << "[fbox " << cell(0) << ']';
141 void InsetMathFBox::infoize(odocstream & os) const
147 /////////////////////////////////////////////////////////////////////
151 /////////////////////////////////////////////////////////////////////
154 InsetMathMakebox::InsetMathMakebox(Buffer * buf, bool framebox)
155 : InsetMathNest(buf, 3), framebox_(framebox)
159 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
161 FontSetChanger dummy(mi.base, "textnormal");
164 static docstring bracket = from_ascii("[");
165 mathed_string_dim(mi.base.font, bracket, wdim);
171 cell(0).metrics(mi, dim0);
172 cell(1).metrics(mi, dim1);
173 cell(2).metrics(mi, dim2);
175 dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
176 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
177 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
192 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
194 drawMarkers(pi, x, y);
196 FontSetChanger dummy(pi.base, "textnormal");
197 BufferView const & bv = *pi.base.bv;
198 int w = mathed_char_width(pi.base.font, '[');
201 Dimension const dim = dimension(*pi.base.bv);
202 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
203 dim.width() - 2, dim.height() - 2, Color_foreground);
207 drawStrBlack(pi, x, y, from_ascii("["));
209 cell(0).draw(pi, x, y);
210 x += cell(0).dimension(bv).wid;
211 drawStrBlack(pi, x, y, from_ascii("]"));
214 drawStrBlack(pi, x, y, from_ascii("["));
216 cell(1).draw(pi, x, y);
217 x += cell(1).dimension(bv).wid;
218 drawStrBlack(pi, x, y, from_ascii("]"));
221 cell(2).draw(pi, x, y);
225 void InsetMathMakebox::write(WriteStream & os) const
227 ModeSpecifier specifier(os, TEXT_MODE);
228 os << (framebox_ ? "\\framebox" : "\\makebox");
229 if (cell(0).size() || !os.latex()) {
230 os << '[' << cell(0) << ']';
231 if (cell(1).size() || !os.latex())
232 os << '[' << cell(1) << ']';
234 os << '{' << cell(2) << '}';
238 void InsetMathMakebox::normalize(NormalStream & os) const
240 os << (framebox_ ? "[framebox " : "[makebox ")
241 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
245 void InsetMathMakebox::infoize(odocstream & os) const
247 os << (framebox_ ? "Framebox" : "Makebox")
248 << " (width: " << cell(0)
249 << " pos: " << cell(1) << ")";
253 /////////////////////////////////////////////////////////////////////
257 /////////////////////////////////////////////////////////////////////
259 InsetMathBoxed::InsetMathBoxed(Buffer * buf)
260 : InsetMathNest(buf, 1)
264 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
266 cell(0).metrics(mi, dim);
267 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
271 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
273 Dimension const dim = dimension(*pi.base.bv);
274 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
275 dim.width() - 2, dim.height() - 2, Color_foreground);
276 cell(0).draw(pi, x + 3, y);
277 setPosCache(pi, x, y);
281 void InsetMathBoxed::write(WriteStream & os) const
283 ModeSpecifier specifier(os, MATH_MODE);
284 os << "\\boxed{" << cell(0) << '}';
288 void InsetMathBoxed::normalize(NormalStream & os) const
290 os << "[boxed " << cell(0) << ']';
294 void InsetMathBoxed::infoize(odocstream & os) const
300 void InsetMathBoxed::validate(LaTeXFeatures & features) const
302 features.require("amsmath");
303 InsetMathNest::validate(features);