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::htmlize(HtmlStream & ms) const
64 SetHTMLMode textmode(ms, true);
69 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
71 FontSetChanger dummy(mi.base, "textnormal");
72 cell(0).metrics(mi, dim);
77 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
79 FontSetChanger dummy(pi.base, "textnormal");
80 cell(0).draw(pi, x, y);
81 drawMarkers(pi, x, y);
85 void InsetMathBox::infoize(odocstream & os) const
87 os << "Box: " << name_;
91 void InsetMathBox::validate(LaTeXFeatures & features) const
93 if (name_ == "tag" || name_ == "tag*")
94 features.require("amsmath");
96 cell(0).validate(features);
101 /////////////////////////////////////////////////////////////////////
105 /////////////////////////////////////////////////////////////////////
108 InsetMathFBox::InsetMathFBox(Buffer * buf)
109 : InsetMathNest(buf, 1)
113 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
115 FontSetChanger dummy(mi.base, "textnormal");
116 cell(0).metrics(mi, dim);
117 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
121 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
123 Dimension const dim = dimension(*pi.base.bv);
124 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
125 dim.width() - 2, dim.height() - 2, Color_foreground);
126 FontSetChanger dummy(pi.base, "textnormal");
127 cell(0).draw(pi, x + 3, y);
128 setPosCache(pi, x, y);
132 void InsetMathFBox::write(WriteStream & os) const
134 ModeSpecifier specifier(os, TEXT_MODE);
135 os << "\\fbox{" << cell(0) << '}';
139 void InsetMathFBox::normalize(NormalStream & os) const
141 os << "[fbox " << cell(0) << ']';
145 void InsetMathFBox::mathmlize(MathStream & ms) const
147 SetMode textmode(ms, true, from_ascii("class='fbox'"));
152 void InsetMathFBox::htmlize(HtmlStream & ms) const
154 SetHTMLMode textmode(ms, true, "class='fbox'");
159 void InsetMathFBox::infoize(odocstream & os) const
165 void InsetMathFBox::validate(LaTeXFeatures & features) const
168 // It'd be better to be able to get this from an InsetLayout, but at present
169 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
170 if (features.runparams().flavor == OutputParams::HTML)
171 features.addPreambleSnippet("<style type=\"text/css\">\n"
172 "mtext.fbox { border: 1px solid black; }\n"
173 "span.fbox { border: 1px solid black; }\n"
179 /////////////////////////////////////////////////////////////////////
183 /////////////////////////////////////////////////////////////////////
186 InsetMathMakebox::InsetMathMakebox(Buffer * buf, bool framebox)
187 : InsetMathNest(buf, 3), framebox_(framebox)
191 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
193 FontSetChanger dummy(mi.base, "textnormal");
196 static docstring bracket = from_ascii("[");
197 mathed_string_dim(mi.base.font, bracket, wdim);
203 cell(0).metrics(mi, dim0);
204 cell(1).metrics(mi, dim1);
205 cell(2).metrics(mi, dim2);
207 dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
208 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
209 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
224 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
226 drawMarkers(pi, x, y);
228 FontSetChanger dummy(pi.base, "textnormal");
229 BufferView const & bv = *pi.base.bv;
230 int w = mathed_char_width(pi.base.font, '[');
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);
239 drawStrBlack(pi, x, y, from_ascii("["));
241 cell(0).draw(pi, x, y);
242 x += cell(0).dimension(bv).wid;
243 drawStrBlack(pi, x, y, from_ascii("]"));
246 drawStrBlack(pi, x, y, from_ascii("["));
248 cell(1).draw(pi, x, y);
249 x += cell(1).dimension(bv).wid;
250 drawStrBlack(pi, x, y, from_ascii("]"));
253 cell(2).draw(pi, x, y);
257 void InsetMathMakebox::write(WriteStream & os) const
259 ModeSpecifier specifier(os, TEXT_MODE);
260 os << (framebox_ ? "\\framebox" : "\\makebox");
261 if (cell(0).size() || !os.latex()) {
262 os << '[' << cell(0) << ']';
263 if (cell(1).size() || !os.latex())
264 os << '[' << cell(1) << ']';
266 os << '{' << cell(2) << '}';
270 void InsetMathMakebox::normalize(NormalStream & os) const
272 os << (framebox_ ? "[framebox " : "[makebox ")
273 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
277 void InsetMathMakebox::infoize(odocstream & os) const
279 os << (framebox_ ? "Framebox" : "Makebox")
280 << " (width: " << cell(0)
281 << " pos: " << cell(1) << ")";
285 void InsetMathMakebox::mathmlize(MathStream & ms) const
287 // FIXME We could do something with the other arguments.
288 std::string const cssclass = framebox_ ? "framebox" : "makebox";
289 SetMode textmode(ms, true, from_ascii("class='" + cssclass + "'"));
294 void InsetMathMakebox::htmlize(HtmlStream & ms) const
296 // FIXME We could do something with the other arguments.
297 std::string const cssclass = framebox_ ? "framebox" : "makebox";
298 SetHTMLMode textmode(ms, true, "class='" + cssclass + "'");
303 void InsetMathMakebox::validate(LaTeXFeatures & features) const
306 // It'd be better to be able to get this from an InsetLayout, but at present
307 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
308 if (features.runparams().flavor == OutputParams::HTML)
309 features.addPreambleSnippet("<style type=\"text/css\">\n"
310 "mtext.framebox { border: 1px solid black; }\n"
311 "span.framebox { border: 1px solid black; }\n"
317 /////////////////////////////////////////////////////////////////////
321 /////////////////////////////////////////////////////////////////////
323 InsetMathBoxed::InsetMathBoxed(Buffer * buf)
324 : InsetMathNest(buf, 1)
328 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
330 cell(0).metrics(mi, dim);
331 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
335 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
337 Dimension const dim = dimension(*pi.base.bv);
338 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
339 dim.width() - 2, dim.height() - 2, Color_foreground);
340 cell(0).draw(pi, x + 3, y);
341 setPosCache(pi, x, y);
345 void InsetMathBoxed::write(WriteStream & os) const
347 ModeSpecifier specifier(os, MATH_MODE);
348 os << "\\boxed{" << cell(0) << '}';
352 void InsetMathBoxed::normalize(NormalStream & os) const
354 os << "[boxed " << cell(0) << ']';
358 void InsetMathBoxed::infoize(odocstream & os) const
364 void InsetMathBoxed::mathmlize(MathStream & ms) const
366 SetMode mathmode(ms, false, from_ascii("class='boxed'"));
371 void InsetMathBoxed::htmlize(HtmlStream & ms) const
373 SetHTMLMode mathmode(ms, false, "class='boxed'");
378 void InsetMathBoxed::validate(LaTeXFeatures & features) const
380 features.require("amsmath");
382 // It'd be better to be able to get this from an InsetLayout, but at present
383 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
384 if (features.runparams().flavor == OutputParams::HTML)
385 features.addPreambleSnippet("<style type=\"text/css\">\n"
386 "mstyle.boxed { border: 1px solid black; }\n"
387 "span.boxed { border: 1px solid black; }\n"
389 InsetMathNest::validate(features);