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 bool textmode = os.textMode();
44 os << '\\' << name_ << '{' << cell(0) << '}';
45 os.textMode(textmode);
49 void InsetMathBox::normalize(NormalStream & os) const
51 os << '[' << name_ << ' ';
52 //text_->write(buffer(), os);
57 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
59 FontSetChanger dummy(mi.base, "textnormal");
60 cell(0).metrics(mi, dim);
65 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
67 FontSetChanger dummy(pi.base, "textnormal");
68 cell(0).draw(pi, x, y);
69 drawMarkers(pi, x, y);
73 void InsetMathBox::infoize(odocstream & os) const
75 os << "Box: " << name_;
79 void InsetMathBox::validate(LaTeXFeatures & features) const
81 if (name_ == "tag" || name_ == "tag*")
82 features.require("amsmath");
83 cell(0).validate(features);
88 /////////////////////////////////////////////////////////////////////
92 /////////////////////////////////////////////////////////////////////
95 InsetMathFBox::InsetMathFBox()
100 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
102 FontSetChanger dummy(mi.base, "textnormal");
103 cell(0).metrics(mi, dim);
104 metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
108 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
110 Dimension const dim = dimension(*pi.base.bv);
111 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
112 dim.width() - 2, dim.height() - 2, Color_foreground);
113 FontSetChanger dummy(pi.base, "textnormal");
114 cell(0).draw(pi, x + 3, y);
115 setPosCache(pi, x, y);
119 void InsetMathFBox::write(WriteStream & os) const
121 bool textmode = os.textMode();
123 os << "\\fbox{" << cell(0) << '}';
124 os.textMode(textmode);
128 void InsetMathFBox::normalize(NormalStream & os) const
130 os << "[fbox " << cell(0) << ']';
134 void InsetMathFBox::infoize(odocstream & os) const
140 /////////////////////////////////////////////////////////////////////
144 /////////////////////////////////////////////////////////////////////
147 InsetMathMakebox::InsetMathMakebox(bool framebox)
148 : InsetMathNest(3), framebox_(framebox)
152 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
154 FontSetChanger dummy(mi.base, "textnormal");
157 static docstring bracket = from_ascii("[");
158 mathed_string_dim(mi.base.font, bracket, wdim);
164 cell(0).metrics(mi, dim0);
165 cell(1).metrics(mi, dim1);
166 cell(2).metrics(mi, dim2);
168 dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
169 dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
170 dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
185 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
187 drawMarkers(pi, x, y);
189 FontSetChanger dummy(pi.base, "textnormal");
190 BufferView const & bv = *pi.base.bv;
191 int w = mathed_char_width(pi.base.font, '[');
194 Dimension const dim = dimension(*pi.base.bv);
195 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
196 dim.width() - 2, dim.height() - 2, Color_foreground);
200 drawStrBlack(pi, x, y, from_ascii("["));
202 cell(0).draw(pi, x, y);
203 x += cell(0).dimension(bv).wid;
204 drawStrBlack(pi, x, y, from_ascii("]"));
207 drawStrBlack(pi, x, y, from_ascii("["));
209 cell(1).draw(pi, x, y);
210 x += cell(1).dimension(bv).wid;
211 drawStrBlack(pi, x, y, from_ascii("]"));
214 cell(2).draw(pi, x, y);
218 void InsetMathMakebox::write(WriteStream & os) const
220 bool textmode = os.textMode();
222 os << (framebox_ ? "\\framebox" : "\\makebox");
223 if (cell(0).size() || !os.latex()) {
224 os << '[' << cell(0) << ']';
225 if (cell(1).size() || !os.latex())
226 os << '[' << cell(1) << ']';
228 os << '{' << cell(2) << '}';
229 os.textMode(textmode);
233 void InsetMathMakebox::normalize(NormalStream & os) const
235 os << (framebox_ ? "[framebox " : "[makebox ")
236 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
240 void InsetMathMakebox::infoize(odocstream & os) const
242 os << (framebox_ ? "Framebox" : "Makebox")
243 << " (width: " << cell(0)
244 << " pos: " << cell(1) << ")";
248 /////////////////////////////////////////////////////////////////////
252 /////////////////////////////////////////////////////////////////////
254 InsetMathBoxed::InsetMathBoxed()
259 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
261 cell(0).metrics(mi, dim);
262 metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
266 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
268 Dimension const dim = dimension(*pi.base.bv);
269 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
270 dim.width() - 2, dim.height() - 2, Color_foreground);
271 cell(0).draw(pi, x + 3, y);
272 setPosCache(pi, x, y);
276 void InsetMathBoxed::write(WriteStream & os) const
278 bool textmode = os.textMode();
280 os << "\\boxed{" << cell(0) << '}';
281 os.textMode(textmode);
285 void InsetMathBoxed::normalize(NormalStream & os) const
287 os << "[boxed " << cell(0) << ']';
291 void InsetMathBoxed::infoize(odocstream & os) const
297 void InsetMathBoxed::validate(LaTeXFeatures & features) const
299 features.require("amsmath");