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"
17 #include "frontends/Painter.h"
24 InsetMathPhantom::InsetMathPhantom(Buffer * buf, Kind k)
25 : InsetMathNest(buf, 1), kind_(k)
29 Inset * InsetMathPhantom::clone() const
31 return new InsetMathPhantom(*this);
35 void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
37 cell(0).metrics(mi, dim);
42 void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
44 static int const arrow_size = 4;
46 // We first draw the text and then an arrow
47 ColorCode const origcol = pi.base.font.color();
48 if (visibleContents())
49 pi.base.font.setColor(Color_special);
50 cell(0).draw(pi, x + 1, y);
51 if (visibleContents())
52 pi.base.font.setColor(origcol);
53 Dimension const dim = dimension(*pi.base.bv);
55 if (kind_ == phantom || kind_ == vphantom) {
68 int const x2 = x + dim.wid / 2;
69 int const x1 = x2 - arrow_size;
70 int const x3 = x2 + arrow_size;
72 int const y1 = y - dim.asc;
73 int const y2 = y1 + arrow_size;
74 int const y4 = y + dim.des;
75 int const y3 = y4 - arrow_size;
78 pi.pain.line(x2, y1, x1, y2, Color_added_space);
79 pi.pain.line(x2, y1, x3, y2, Color_added_space);
82 pi.pain.line(x2, y4, x1, y3, Color_added_space);
83 pi.pain.line(x2, y4, x3, y3, Color_added_space);
86 pi.pain.line(x2, y1, x2, y4, Color_added_space);
89 if (kind_ == phantom || kind_ == hphantom) {
92 // y2--- <---------------->
99 int const x2 = x + arrow_size;
100 int const x4 = x + dim.wid;
101 int const x3 = x4 - arrow_size;
103 int const y2 = y + (dim.des - dim.asc) / 2;
104 int const y1 = y2 - arrow_size;
105 int const y3 = y2 + arrow_size;
108 pi.pain.line(x1, y2, x2, y3, Color_added_space);
109 pi.pain.line(x1, y2, x2, y1, Color_added_space);
112 pi.pain.line(x4, y2, x3, y3, Color_added_space);
113 pi.pain.line(x4, y2, x3, y1, Color_added_space);
116 pi.pain.line(x1, y2, x4, y2, Color_added_space);
119 else if (kind_ == mathclap) {
122 // y2--- -------->-<--------
129 int const x5 = x + dim.wid;
130 int const x3 = x + dim.wid / 2;
131 int const x2 = std::max(x1, x3 - arrow_size);
132 int const x4 = std::min(x5, x3 + arrow_size);
134 int const y2 = y + (dim.des - dim.asc) / 2;
135 int const y1 = y2 - arrow_size;
136 int const y3 = y2 + arrow_size;
139 pi.pain.line(x2, y3, x3, y2, Color_added_space);
140 pi.pain.line(x2, y1, x3, y2, Color_added_space);
143 pi.pain.line(x4, y3, x3, y2, Color_added_space);
144 pi.pain.line(x4, y1, x3, y2, Color_added_space);
147 pi.pain.line(x1, y2, x5, y2, Color_added_space);
150 else if (kind_ == mathllap) {
153 // y2--- ------------------>
160 int const x3 = x + dim.wid;
161 int const x2 = std::max(x1, x3 - arrow_size);
163 int const y2 = y + (dim.des - dim.asc) / 2;
164 int const y1 = y2 - arrow_size;
165 int const y3 = y2 + arrow_size;
168 pi.pain.line(x3, y2, x2, y3, Color_added_space);
169 pi.pain.line(x3, y2, x2, y1, Color_added_space);
172 pi.pain.line(x1, y2, x3, y2, Color_added_space);
175 else if (kind_ == mathrlap) {
178 // y2--- <------------------
185 int const x3 = x + dim.wid;
186 int const x2 = std::min(x3, x + arrow_size);
188 int const y2 = y + (dim.des - dim.asc) / 2;
189 int const y1 = y2 - arrow_size;
190 int const y3 = y2 + arrow_size;
193 pi.pain.line(x1, y2, x2, y3, Color_added_space);
194 pi.pain.line(x1, y2, x2, y1, Color_added_space);
197 pi.pain.line(x1, y2, x3, y2, Color_added_space);
200 else if (kind_ == smash || kind_ == smasht || kind_ == smashb) {
214 int const x2 = x + dim.wid / 2;
215 int const x1 = x2 - arrow_size;
216 int const x3 = x2 + arrow_size;
218 int const y1 = y - dim.asc;
219 int const y5 = y + dim.des;
221 int const y2 = std::max(y1, y3 - arrow_size);
222 int const y4 = std::min(y5, y3 + arrow_size);
225 if (kind_ != smashb) {
226 pi.pain.line(x1, y2, x2, y3, Color_added_space);
227 pi.pain.line(x3, y2, x2, y3, Color_added_space);
231 if (kind_ != smasht) {
232 pi.pain.line(x1, y4, x2, y3, Color_added_space);
233 pi.pain.line(x3, y4, x2, y3, Color_added_space);
238 pi.pain.line(x2, y1, x2, y3, Color_added_space);
239 else if (kind_ == smashb)
240 pi.pain.line(x2, y3, x2, y5, Color_added_space);
242 pi.pain.line(x2, y1, x2, y5, Color_added_space);
245 drawMarkers(pi, x, y);
249 void InsetMathPhantom::write(WriteStream & os) const
251 MathEnsurer ensurer(os);
283 os << cell(0) << '}';
287 void InsetMathPhantom::normalize(NormalStream & os) const
318 os << cell(0) << ']';
322 void InsetMathPhantom::infoize(odocstream & os) const
356 void InsetMathPhantom::validate(LaTeXFeatures & features) const
358 InsetMathNest::validate(features);
367 features.require("amsmath");
372 features.require("mathtools");
378 bool InsetMathPhantom::visibleContents() const
380 return kind_ == phantom || kind_ == vphantom || kind_ == hphantom;