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(docstring const & name)
36 : InsetMathNest(1), name_(name)
40 void InsetMathBox::write(WriteStream & os) const
42 os << '\\' << name_ << '{' << cell(0) << '}';
46 void InsetMathBox::normalize(NormalStream & os) const
48 os << '[' << name_ << ' ';
49 //text_->write(buffer(), os);
54 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
56 FontSetChanger dummy(mi.base, "textnormal");
57 cell(0).metrics(mi, dim);
62 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
64 FontSetChanger dummy(pi.base, "textnormal");
65 cell(0).draw(pi, x, y);
66 drawMarkers(pi, x, y);
70 void InsetMathBox::infoize(odocstream & os) const
72 os << "Box: " << name_;
76 void InsetMathBox::validate(LaTeXFeatures & features) const
78 if (name_ == "tag" || name_ == "tag*")
79 features.require("amsmath");
80 cell(0).validate(features);
85 /////////////////////////////////////////////////////////////////////
89 /////////////////////////////////////////////////////////////////////
92 InsetMathFBox::InsetMathFBox()
97 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
99 FontSetChanger dummy(mi.base, "textnormal");
100 cell(0).metrics(mi, dim);
101 metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
105 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
107 Dimension const dim = dimension(*pi.base.bv);
108 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
109 dim.width() - 2, dim.height() - 2, Color_foreground);
110 FontSetChanger dummy(pi.base, "textnormal");
111 cell(0).draw(pi, x + 3, y);
112 setPosCache(pi, x, y);
116 void InsetMathFBox::write(WriteStream & os) const
118 os << "\\fbox{" << cell(0) << '}';
122 void InsetMathFBox::normalize(NormalStream & os) const
124 os << "[fbox " << cell(0) << ']';
128 void InsetMathFBox::infoize(odocstream & os) const
134 /////////////////////////////////////////////////////////////////////
138 /////////////////////////////////////////////////////////////////////
141 InsetMathMakebox::InsetMathMakebox(bool framebox)
142 : InsetMathNest(3), framebox_(framebox)
146 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
148 FontSetChanger dummy(mi.base, "textnormal");
151 static docstring bracket = from_ascii("[");
152 mathed_string_dim(mi.base.font, bracket, wdim);
158 cell(0).metrics(mi, dim0);
159 cell(1).metrics(mi, dim1);
160 cell(2).metrics(mi, dim2);
162 dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
163 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
164 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
179 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
181 drawMarkers(pi, x, y);
183 FontSetChanger dummy(pi.base, "textnormal");
184 BufferView const & bv = *pi.base.bv;
185 int w = mathed_char_width(pi.base.font, '[');
188 Dimension const dim = dimension(*pi.base.bv);
189 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
190 dim.width() - 2, dim.height() - 2, Color_foreground);
194 drawStrBlack(pi, x, y, from_ascii("["));
196 cell(0).draw(pi, x, y);
197 x += cell(0).dimension(bv).wid;
198 drawStrBlack(pi, x, y, from_ascii("]"));
201 drawStrBlack(pi, x, y, from_ascii("["));
203 cell(1).draw(pi, x, y);
204 x += cell(1).dimension(bv).wid;
205 drawStrBlack(pi, x, y, from_ascii("]"));
208 cell(2).draw(pi, x, y);
212 void InsetMathMakebox::write(WriteStream & os) const
214 os << (framebox_ ? "\\framebox" : "\\makebox");
215 if (cell(0).size() || !os.latex()) {
216 os << '[' << cell(0) << ']';
217 if (cell(1).size() || !os.latex())
218 os << '[' << cell(1) << ']';
220 os << '{' << cell(2) << '}';
224 void InsetMathMakebox::normalize(NormalStream & os) const
226 os << (framebox_ ? "[framebox " : "[makebox ")
227 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
231 void InsetMathMakebox::infoize(odocstream & os) const
233 os << (framebox_ ? "Framebox" : "Makebox")
234 << " (width: " << cell(0)
235 << " pos: " << cell(1) << ")";
239 /////////////////////////////////////////////////////////////////////
243 /////////////////////////////////////////////////////////////////////
245 InsetMathBoxed::InsetMathBoxed()
250 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
252 cell(0).metrics(mi, dim);
253 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
257 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
259 Dimension const dim = dimension(*pi.base.bv);
260 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
261 dim.width() - 2, dim.height() - 2, Color_foreground);
262 cell(0).draw(pi, x + 3, y);
263 setPosCache(pi, x, y);
267 void InsetMathBoxed::write(WriteStream & os) const
269 os << "\\boxed{" << cell(0) << '}';
273 void InsetMathBoxed::normalize(NormalStream & os) const
275 os << "[boxed " << cell(0) << ']';
279 void InsetMathBoxed::infoize(odocstream & os) const
285 void InsetMathBoxed::validate(LaTeXFeatures & features) const
287 features.require("amsmath");