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 SetMode textmode(ms, true, from_ascii("class='mathbox'"));
62 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
64 FontSetChanger dummy(mi.base, "textnormal");
65 cell(0).metrics(mi, dim);
70 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
72 FontSetChanger dummy(pi.base, "textnormal");
73 cell(0).draw(pi, x, y);
74 drawMarkers(pi, x, y);
78 void InsetMathBox::infoize(odocstream & os) const
80 os << "Box: " << name_;
84 void InsetMathBox::validate(LaTeXFeatures & features) const
86 if (name_ == "tag" || name_ == "tag*")
87 features.require("amsmath");
88 cell(0).validate(features);
93 /////////////////////////////////////////////////////////////////////
97 /////////////////////////////////////////////////////////////////////
100 InsetMathFBox::InsetMathFBox(Buffer * buf)
101 : InsetMathNest(buf, 1)
105 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
107 FontSetChanger dummy(mi.base, "textnormal");
108 cell(0).metrics(mi, dim);
109 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
113 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
115 Dimension const dim = dimension(*pi.base.bv);
116 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
117 dim.width() - 2, dim.height() - 2, Color_foreground);
118 FontSetChanger dummy(pi.base, "textnormal");
119 cell(0).draw(pi, x + 3, y);
120 setPosCache(pi, x, y);
124 void InsetMathFBox::write(WriteStream & os) const
126 ModeSpecifier specifier(os, TEXT_MODE);
127 os << "\\fbox{" << cell(0) << '}';
131 void InsetMathFBox::normalize(NormalStream & os) const
133 os << "[fbox " << cell(0) << ']';
137 void InsetMathFBox::mathmlize(MathStream & ms) const
139 SetMode textmode(ms, true, from_ascii("class='fbox'"));
144 void InsetMathFBox::infoize(odocstream & os) const
150 void InsetMathFBox::validate(LaTeXFeatures & features) const
153 // It'd be better to be able to get this from an InsetLayout, but at present
154 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
155 if (features.runparams().flavor == OutputParams::HTML)
156 features.addPreambleSnippet("<style type=\"text/css\">\n"
157 "mtext.fbox { border: 1px solid black; }\n"
163 /////////////////////////////////////////////////////////////////////
167 /////////////////////////////////////////////////////////////////////
170 InsetMathMakebox::InsetMathMakebox(Buffer * buf, bool framebox)
171 : InsetMathNest(buf, 3), framebox_(framebox)
175 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
177 FontSetChanger dummy(mi.base, "textnormal");
180 static docstring bracket = from_ascii("[");
181 mathed_string_dim(mi.base.font, bracket, wdim);
187 cell(0).metrics(mi, dim0);
188 cell(1).metrics(mi, dim1);
189 cell(2).metrics(mi, dim2);
191 dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
192 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
193 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
208 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
210 drawMarkers(pi, x, y);
212 FontSetChanger dummy(pi.base, "textnormal");
213 BufferView const & bv = *pi.base.bv;
214 int w = mathed_char_width(pi.base.font, '[');
217 Dimension const dim = dimension(*pi.base.bv);
218 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
219 dim.width() - 2, dim.height() - 2, Color_foreground);
223 drawStrBlack(pi, x, y, from_ascii("["));
225 cell(0).draw(pi, x, y);
226 x += cell(0).dimension(bv).wid;
227 drawStrBlack(pi, x, y, from_ascii("]"));
230 drawStrBlack(pi, x, y, from_ascii("["));
232 cell(1).draw(pi, x, y);
233 x += cell(1).dimension(bv).wid;
234 drawStrBlack(pi, x, y, from_ascii("]"));
237 cell(2).draw(pi, x, y);
241 void InsetMathMakebox::write(WriteStream & os) const
243 ModeSpecifier specifier(os, TEXT_MODE);
244 os << (framebox_ ? "\\framebox" : "\\makebox");
245 if (cell(0).size() || !os.latex()) {
246 os << '[' << cell(0) << ']';
247 if (cell(1).size() || !os.latex())
248 os << '[' << cell(1) << ']';
250 os << '{' << cell(2) << '}';
254 void InsetMathMakebox::normalize(NormalStream & os) const
256 os << (framebox_ ? "[framebox " : "[makebox ")
257 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
261 void InsetMathMakebox::infoize(odocstream & os) const
263 os << (framebox_ ? "Framebox" : "Makebox")
264 << " (width: " << cell(0)
265 << " pos: " << cell(1) << ")";
269 void InsetMathMakebox::mathmlize(MathStream & ms) const
271 // FIXME We could do something with the other arguments.
272 std::string const cssclass = framebox_ ? "framebox" : "makebox";
273 SetMode textmode(ms, true, from_ascii("class='" + cssclass + "'"));
278 void InsetMathMakebox::validate(LaTeXFeatures & features) const
281 // It'd be better to be able to get this from an InsetLayout, but at present
282 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
283 if (features.runparams().flavor == OutputParams::HTML)
284 features.addPreambleSnippet("<style type=\"text/css\">\n"
285 "mtext.framebox { border: 1px solid black; }\n"
291 /////////////////////////////////////////////////////////////////////
295 /////////////////////////////////////////////////////////////////////
297 InsetMathBoxed::InsetMathBoxed(Buffer * buf)
298 : InsetMathNest(buf, 1)
302 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
304 cell(0).metrics(mi, dim);
305 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
309 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
311 Dimension const dim = dimension(*pi.base.bv);
312 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
313 dim.width() - 2, dim.height() - 2, Color_foreground);
314 cell(0).draw(pi, x + 3, y);
315 setPosCache(pi, x, y);
319 void InsetMathBoxed::write(WriteStream & os) const
321 ModeSpecifier specifier(os, MATH_MODE);
322 os << "\\boxed{" << cell(0) << '}';
326 void InsetMathBoxed::normalize(NormalStream & os) const
328 os << "[boxed " << cell(0) << ']';
332 void InsetMathBoxed::infoize(odocstream & os) const
338 void InsetMathBoxed::mathmlize(MathStream & ms) const
340 SetMode mathmode(ms, false, from_ascii("class='boxed'"));
345 void InsetMathBoxed::validate(LaTeXFeatures & features) const
347 features.require("amsmath");
349 // It'd be better to be able to get this from an InsetLayout, but at present
350 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
351 if (features.runparams().flavor == OutputParams::HTML)
352 features.addPreambleSnippet("<style type=\"text/css\">\n"
353 "mstyle.boxed { border: 1px solid black; }\n"
355 InsetMathNest::validate(features);