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::metrics(MetricsInfo
& mi
, Dimension
& dim
) const
57 FontSetChanger
dummy(mi
.base
, "textnormal");
58 cell(0).metrics(mi
, dim
);
63 void InsetMathBox::draw(PainterInfo
& pi
, int x
, int y
) const
65 FontSetChanger
dummy(pi
.base
, "textnormal");
66 cell(0).draw(pi
, x
, y
);
67 drawMarkers(pi
, x
, y
);
71 void InsetMathBox::infoize(odocstream
& os
) const
73 os
<< "Box: " << name_
;
77 void InsetMathBox::validate(LaTeXFeatures
& features
) const
79 if (name_
== "tag" || name_
== "tag*")
80 features
.require("amsmath");
81 cell(0).validate(features
);
86 /////////////////////////////////////////////////////////////////////
90 /////////////////////////////////////////////////////////////////////
93 InsetMathFBox::InsetMathFBox(Buffer
* buf
)
94 : InsetMathNest(buf
, 1)
98 void InsetMathFBox::metrics(MetricsInfo
& mi
, Dimension
& dim
) const
100 FontSetChanger
dummy(mi
.base
, "textnormal");
101 cell(0).metrics(mi
, dim
);
102 metricsMarkers2(dim
, 3); // 1 pixel space, 1 frame, 1 space
106 void InsetMathFBox::draw(PainterInfo
& pi
, int x
, int y
) const
108 Dimension
const dim
= dimension(*pi
.base
.bv
);
109 pi
.pain
.rectangle(x
+ 1, y
- dim
.ascent() + 1,
110 dim
.width() - 2, dim
.height() - 2, Color_foreground
);
111 FontSetChanger
dummy(pi
.base
, "textnormal");
112 cell(0).draw(pi
, x
+ 3, y
);
113 setPosCache(pi
, x
, y
);
117 void InsetMathFBox::write(WriteStream
& os
) const
119 ModeSpecifier
specifier(os
, TEXT_MODE
);
120 os
<< "\\fbox{" << cell(0) << '}';
124 void InsetMathFBox::normalize(NormalStream
& os
) const
126 os
<< "[fbox " << cell(0) << ']';
130 void InsetMathFBox::infoize(odocstream
& os
) const
136 /////////////////////////////////////////////////////////////////////
140 /////////////////////////////////////////////////////////////////////
143 InsetMathMakebox::InsetMathMakebox(Buffer
* buf
, bool framebox
)
144 : InsetMathNest(buf
, 3), framebox_(framebox
)
148 void InsetMathMakebox::metrics(MetricsInfo
& mi
, Dimension
& dim
) const
150 FontSetChanger
dummy(mi
.base
, "textnormal");
153 static docstring bracket
= from_ascii("[");
154 mathed_string_dim(mi
.base
.font
, bracket
, wdim
);
160 cell(0).metrics(mi
, dim0
);
161 cell(1).metrics(mi
, dim1
);
162 cell(2).metrics(mi
, dim2
);
164 dim
.wid
= w
+ dim0
.wid
+ w
+ w
+ dim1
.wid
+ w
+ 2 + dim2
.wid
;
165 dim
.asc
= std::max(std::max(wdim
.asc
, dim0
.asc
), std::max(dim1
.asc
, dim2
.asc
));
166 dim
.des
= std::max(std::max(wdim
.des
, dim0
.des
), std::max(dim1
.des
, dim2
.des
));
181 void InsetMathMakebox::draw(PainterInfo
& pi
, int x
, int y
) const
183 drawMarkers(pi
, x
, y
);
185 FontSetChanger
dummy(pi
.base
, "textnormal");
186 BufferView
const & bv
= *pi
.base
.bv
;
187 int w
= mathed_char_width(pi
.base
.font
, '[');
190 Dimension
const dim
= dimension(*pi
.base
.bv
);
191 pi
.pain
.rectangle(x
+ 1, y
- dim
.ascent() + 1,
192 dim
.width() - 2, dim
.height() - 2, Color_foreground
);
196 drawStrBlack(pi
, x
, y
, from_ascii("["));
198 cell(0).draw(pi
, x
, y
);
199 x
+= cell(0).dimension(bv
).wid
;
200 drawStrBlack(pi
, x
, y
, from_ascii("]"));
203 drawStrBlack(pi
, x
, y
, from_ascii("["));
205 cell(1).draw(pi
, x
, y
);
206 x
+= cell(1).dimension(bv
).wid
;
207 drawStrBlack(pi
, x
, y
, from_ascii("]"));
210 cell(2).draw(pi
, x
, y
);
214 void InsetMathMakebox::write(WriteStream
& os
) const
216 ModeSpecifier
specifier(os
, TEXT_MODE
);
217 os
<< (framebox_
? "\\framebox" : "\\makebox");
218 if (cell(0).size() || !os
.latex()) {
219 os
<< '[' << cell(0) << ']';
220 if (cell(1).size() || !os
.latex())
221 os
<< '[' << cell(1) << ']';
223 os
<< '{' << cell(2) << '}';
227 void InsetMathMakebox::normalize(NormalStream
& os
) const
229 os
<< (framebox_
? "[framebox " : "[makebox ")
230 << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
234 void InsetMathMakebox::infoize(odocstream
& os
) const
236 os
<< (framebox_
? "Framebox" : "Makebox")
237 << " (width: " << cell(0)
238 << " pos: " << cell(1) << ")";
242 /////////////////////////////////////////////////////////////////////
246 /////////////////////////////////////////////////////////////////////
248 InsetMathBoxed::InsetMathBoxed(Buffer
* buf
)
249 : InsetMathNest(buf
, 1)
253 void InsetMathBoxed::metrics(MetricsInfo
& mi
, Dimension
& dim
) const
255 cell(0).metrics(mi
, dim
);
256 metricsMarkers2(dim
, 3); // 1 pixel space, 1 frame, 1 space
260 void InsetMathBoxed::draw(PainterInfo
& pi
, int x
, int y
) const
262 Dimension
const dim
= dimension(*pi
.base
.bv
);
263 pi
.pain
.rectangle(x
+ 1, y
- dim
.ascent() + 1,
264 dim
.width() - 2, dim
.height() - 2, Color_foreground
);
265 cell(0).draw(pi
, x
+ 3, y
);
266 setPosCache(pi
, x
, y
);
270 void InsetMathBoxed::write(WriteStream
& os
) const
272 ModeSpecifier
specifier(os
, MATH_MODE
);
273 os
<< "\\boxed{" << cell(0) << '}';
277 void InsetMathBoxed::normalize(NormalStream
& os
) const
279 os
<< "[boxed " << cell(0) << ']';
283 void InsetMathBoxed::infoize(odocstream
& os
) const
289 void InsetMathBoxed::validate(LaTeXFeatures
& features
) const
291 features
.require("amsmath");
292 InsetMathNest::validate(features
);