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);
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::infoize(odocstream & os) const
143 /////////////////////////////////////////////////////////////////////
147 /////////////////////////////////////////////////////////////////////
150 InsetMathMakebox::InsetMathMakebox(Buffer * buf, bool framebox)
151 : InsetMathNest(buf, 3), framebox_(framebox)
155 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
157 FontSetChanger dummy(mi.base, "textnormal");
160 static docstring bracket = from_ascii("[");
161 mathed_string_dim(mi.base.font, bracket, wdim);
167 cell(0).metrics(mi, dim0);
168 cell(1).metrics(mi, dim1);
169 cell(2).metrics(mi, dim2);
171 dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
172 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
173 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
188 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
190 drawMarkers(pi, x, y);
192 FontSetChanger dummy(pi.base, "textnormal");
193 BufferView const & bv = *pi.base.bv;
194 int w = mathed_char_width(pi.base.font, '[');
197 Dimension const dim = dimension(*pi.base.bv);
198 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
199 dim.width() - 2, dim.height() - 2, Color_foreground);
203 drawStrBlack(pi, x, y, from_ascii("["));
205 cell(0).draw(pi, x, y);
206 x += cell(0).dimension(bv).wid;
207 drawStrBlack(pi, x, y, from_ascii("]"));
210 drawStrBlack(pi, x, y, from_ascii("["));
212 cell(1).draw(pi, x, y);
213 x += cell(1).dimension(bv).wid;
214 drawStrBlack(pi, x, y, from_ascii("]"));
217 cell(2).draw(pi, x, y);
221 void InsetMathMakebox::write(WriteStream & os) const
223 ModeSpecifier specifier(os, TEXT_MODE);
224 os << (framebox_ ? "\\framebox" : "\\makebox");
225 if (cell(0).size() || !os.latex()) {
226 os << '[' << cell(0) << ']';
227 if (cell(1).size() || !os.latex())
228 os << '[' << cell(1) << ']';
230 os << '{' << cell(2) << '}';
234 void InsetMathMakebox::normalize(NormalStream & os) const
236 os << (framebox_ ? "[framebox " : "[makebox ")
237 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
241 void InsetMathMakebox::infoize(odocstream & os) const
243 os << (framebox_ ? "Framebox" : "Makebox")
244 << " (width: " << cell(0)
245 << " pos: " << cell(1) << ")";
249 /////////////////////////////////////////////////////////////////////
253 /////////////////////////////////////////////////////////////////////
255 InsetMathBoxed::InsetMathBoxed(Buffer * buf)
256 : InsetMathNest(buf, 1)
260 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
262 cell(0).metrics(mi, dim);
263 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
267 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
269 Dimension const dim = dimension(*pi.base.bv);
270 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
271 dim.width() - 2, dim.height() - 2, Color_foreground);
272 cell(0).draw(pi, x + 3, y);
273 setPosCache(pi, x, y);
277 void InsetMathBoxed::write(WriteStream & os) const
279 ModeSpecifier specifier(os, MATH_MODE);
280 os << "\\boxed{" << cell(0) << '}';
284 void InsetMathBoxed::normalize(NormalStream & os) const
286 os << "[boxed " << cell(0) << ']';
290 void InsetMathBoxed::infoize(odocstream & os) const
296 void InsetMathBoxed::validate(LaTeXFeatures & features) const
298 features.require("amsmath");
299 InsetMathNest::validate(features);