2 * \file InsetMathPhantom.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathPhantom.h"
15 #include "LaTeXFeatures.h"
16 #include "MathStream.h"
18 #include "MetricsInfo.h"
20 #include "frontends/Painter.h"
28 InsetMathPhantom::InsetMathPhantom(Buffer * buf, Kind k)
29 : InsetMathNest(buf, 1), kind_(k)
33 Inset * InsetMathPhantom::clone() const
35 return new InsetMathPhantom(*this);
39 void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
41 cell(0).metrics(mi, dim);
46 void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
48 static int const arrow_size = 4;
50 // We first draw the text and then an arrow
51 ColorCode const origcol = pi.base.font.color();
52 if (visibleContents())
53 pi.base.font.setColor(Color_special);
54 cell(0).draw(pi, x + 1, y);
55 if (visibleContents())
56 pi.base.font.setColor(origcol);
57 Dimension const dim = dimension(*pi.base.bv);
59 if (kind_ == phantom || kind_ == vphantom) {
72 int const x2 = x + dim.wid / 2;
73 int const x1 = x2 - arrow_size;
74 int const x3 = x2 + arrow_size;
76 int const y1 = y - dim.asc;
77 int const y2 = y1 + arrow_size;
78 int const y4 = y + dim.des;
79 int const y3 = y4 - arrow_size;
82 pi.pain.line(x2, y1, x1, y2, Color_added_space);
83 pi.pain.line(x2, y1, x3, y2, Color_added_space);
86 pi.pain.line(x2, y4, x1, y3, Color_added_space);
87 pi.pain.line(x2, y4, x3, y3, Color_added_space);
90 pi.pain.line(x2, y1, x2, y4, Color_added_space);
93 if (kind_ == phantom || kind_ == hphantom) {
96 // y2--- <---------------->
103 int const x2 = x + arrow_size;
104 int const x4 = x + dim.wid;
105 int const x3 = x4 - arrow_size;
107 int const y2 = y + (dim.des - dim.asc) / 2;
108 int const y1 = y2 - arrow_size;
109 int const y3 = y2 + arrow_size;
112 pi.pain.line(x1, y2, x2, y3, Color_added_space);
113 pi.pain.line(x1, y2, x2, y1, Color_added_space);
116 pi.pain.line(x4, y2, x3, y3, Color_added_space);
117 pi.pain.line(x4, y2, x3, y1, Color_added_space);
120 pi.pain.line(x1, y2, x4, y2, Color_added_space);
123 else if (kind_ == mathclap) {
126 // y2--- -------->-<--------
133 int const x5 = x + dim.wid;
134 int const x3 = x + dim.wid / 2;
135 int const x2 = std::max(x1, x3 - arrow_size);
136 int const x4 = std::min(x5, x3 + arrow_size);
138 int const y2 = y + (dim.des - dim.asc) / 2;
139 int const y1 = y2 - arrow_size;
140 int const y3 = y2 + arrow_size;
143 pi.pain.line(x2, y3, x3, y2, Color_added_space);
144 pi.pain.line(x2, y1, x3, y2, Color_added_space);
147 pi.pain.line(x4, y3, x3, y2, Color_added_space);
148 pi.pain.line(x4, y1, x3, y2, Color_added_space);
151 pi.pain.line(x1, y2, x5, y2, Color_added_space);
154 else if (kind_ == mathllap) {
157 // y2--- ------------------>
164 int const x3 = x + dim.wid;
165 int const x2 = std::max(x1, x3 - arrow_size);
167 int const y2 = y + (dim.des - dim.asc) / 2;
168 int const y1 = y2 - arrow_size;
169 int const y3 = y2 + arrow_size;
172 pi.pain.line(x3, y2, x2, y3, Color_added_space);
173 pi.pain.line(x3, y2, x2, y1, Color_added_space);
176 pi.pain.line(x1, y2, x3, y2, Color_added_space);
179 else if (kind_ == mathrlap) {
182 // y2--- <------------------
189 int const x3 = x + dim.wid;
190 int const x2 = std::min(x3, x + arrow_size);
192 int const y2 = y + (dim.des - dim.asc) / 2;
193 int const y1 = y2 - arrow_size;
194 int const y3 = y2 + arrow_size;
197 pi.pain.line(x1, y2, x2, y3, Color_added_space);
198 pi.pain.line(x1, y2, x2, y1, Color_added_space);
201 pi.pain.line(x1, y2, x3, y2, Color_added_space);
204 else if (kind_ == smash || kind_ == smasht || kind_ == smashb) {
218 int const x2 = x + dim.wid / 2;
219 int const x1 = x2 - arrow_size;
220 int const x3 = x2 + arrow_size;
222 int const y1 = y - dim.asc;
223 int const y5 = y + dim.des;
225 int const y2 = std::max(y1, y3 - arrow_size);
226 int const y4 = std::min(y5, y3 + arrow_size);
229 if (kind_ != smashb) {
230 pi.pain.line(x1, y2, x2, y3, Color_added_space);
231 pi.pain.line(x3, y2, x2, y3, Color_added_space);
235 if (kind_ != smasht) {
236 pi.pain.line(x1, y4, x2, y3, Color_added_space);
237 pi.pain.line(x3, y4, x2, y3, Color_added_space);
242 pi.pain.line(x2, y1, x2, y3, Color_added_space);
243 else if (kind_ == smashb)
244 pi.pain.line(x2, y3, x2, y5, Color_added_space);
246 pi.pain.line(x2, y1, x2, y5, Color_added_space);
249 drawMarkers(pi, x, y);
253 void InsetMathPhantom::write(WriteStream & os) const
255 MathEnsurer ensurer(os);
287 os << cell(0) << '}';
291 void InsetMathPhantom::normalize(NormalStream & os) const
322 os << cell(0) << ']';
326 void InsetMathPhantom::infoize(odocstream & os) const
360 void InsetMathPhantom::validate(LaTeXFeatures & features) const
362 InsetMathNest::validate(features);
371 features.require("amsmath");
376 features.require("mathtools");
382 bool InsetMathPhantom::visibleContents() const
384 return kind_ == phantom || kind_ == vphantom || kind_ == hphantom;