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"
27 /////////////////////////////////////////////////////////////////////
31 /////////////////////////////////////////////////////////////////////
33 InsetMathBox::InsetMathBox(docstring const & name)
34 : InsetMathNest(1), name_(name)
38 void InsetMathBox::write(WriteStream & os) const
40 os << '\\' << name_ << '{' << cell(0) << '}';
44 void InsetMathBox::normalize(NormalStream & os) const
46 os << '[' << name_ << ' ';
47 //text_->write(buffer(), os);
52 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
54 FontSetChanger dummy(mi.base, "textnormal");
55 cell(0).metrics(mi, dim);
60 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
62 FontSetChanger dummy(pi.base, "textnormal");
63 cell(0).draw(pi, x, y);
64 drawMarkers(pi, x, y);
68 void InsetMathBox::infoize(odocstream & os) const
70 os << "Box: " << name_;
74 void InsetMathBox::validate(LaTeXFeatures & features) const
76 if (name_ == "tag" || name_ == "tag*")
77 features.require("amsmath");
78 cell(0).validate(features);
83 /////////////////////////////////////////////////////////////////////
87 /////////////////////////////////////////////////////////////////////
90 InsetMathFBox::InsetMathFBox()
95 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
97 FontSetChanger dummy(mi.base, "textnormal");
98 cell(0).metrics(mi, dim);
99 metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
103 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
105 Dimension const dim = dimension(*pi.base.bv);
106 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
107 dim.width() - 2, dim.height() - 2, Color_foreground);
108 FontSetChanger dummy(pi.base, "textnormal");
109 cell(0).draw(pi, x + 3, y);
110 setPosCache(pi, x, y);
114 void InsetMathFBox::write(WriteStream & os) const
116 os << "\\fbox{" << cell(0) << '}';
120 void InsetMathFBox::normalize(NormalStream & os) const
122 os << "[fbox " << cell(0) << ']';
126 void InsetMathFBox::infoize(odocstream & os) const
132 /////////////////////////////////////////////////////////////////////
136 /////////////////////////////////////////////////////////////////////
139 InsetMathMakebox::InsetMathMakebox(bool framebox)
140 : InsetMathNest(3), framebox_(framebox)
144 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
146 FontSetChanger dummy(mi.base, "textnormal");
149 static docstring bracket = from_ascii("[");
150 mathed_string_dim(mi.base.font, bracket, wdim);
156 cell(0).metrics(mi, dim0);
157 cell(1).metrics(mi, dim1);
158 cell(2).metrics(mi, dim2);
160 dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
161 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
162 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
177 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
179 drawMarkers(pi, x, y);
181 FontSetChanger dummy(pi.base, "textnormal");
182 BufferView const & bv = *pi.base.bv;
183 int w = mathed_char_width(pi.base.font, '[');
186 Dimension const dim = dimension(*pi.base.bv);
187 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
188 dim.width() - 2, dim.height() - 2, Color_foreground);
192 drawStrBlack(pi, x, y, from_ascii("["));
194 cell(0).draw(pi, x, y);
195 x += cell(0).dimension(bv).wid;
196 drawStrBlack(pi, x, y, from_ascii("]"));
199 drawStrBlack(pi, x, y, from_ascii("["));
201 cell(1).draw(pi, x, y);
202 x += cell(1).dimension(bv).wid;
203 drawStrBlack(pi, x, y, from_ascii("]"));
206 cell(2).draw(pi, x, y);
210 void InsetMathMakebox::write(WriteStream & os) const
212 os << (framebox_ ? "\\framebox" : "\\makebox");
213 if (cell(0).size() || !os.latex()) {
214 os << '[' << cell(0) << ']';
215 if (cell(1).size() || !os.latex())
216 os << '[' << cell(1) << ']';
218 os << '{' << cell(2) << '}';
222 void InsetMathMakebox::normalize(NormalStream & os) const
224 os << (framebox_ ? "[framebox " : "[makebox ")
225 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
229 void InsetMathMakebox::infoize(odocstream & os) const
231 os << (framebox_ ? "Framebox" : "Makebox")
232 << " (width: " << cell(0)
233 << " pos: " << cell(1) << ")";
237 /////////////////////////////////////////////////////////////////////
241 /////////////////////////////////////////////////////////////////////
243 InsetMathBoxed::InsetMathBoxed()
248 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
250 cell(0).metrics(mi, dim);
251 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
255 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
257 Dimension const dim = dimension(*pi.base.bv);
258 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
259 dim.width() - 2, dim.height() - 2, Color_foreground);
260 cell(0).draw(pi, x + 3, y);
261 setPosCache(pi, x, y);
265 void InsetMathBoxed::write(WriteStream & os) const
267 os << "\\boxed{" << cell(0) << '}';
271 void InsetMathBoxed::normalize(NormalStream & os) const
273 os << "[boxed " << cell(0) << ']';
277 void InsetMathBoxed::infoize(odocstream & os) const
283 void InsetMathBoxed::validate(LaTeXFeatures & features) const
285 features.require("amsmath");