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 Changer dummy = mi.base.changeEnsureMath();
42 cell(0).metrics(mi, dim);
46 void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
48 Changer dummy = pi.base.changeEnsureMath();
49 static int const arrow_size = 4;
51 // We first draw the text and then an arrow
52 ColorCode const origcol = pi.base.font.color();
53 if (visibleContents())
54 pi.base.font.setColor(Color_special);
55 cell(0).draw(pi, x, y);
56 if (visibleContents())
57 pi.base.font.setColor(origcol);
58 Dimension const dim = dimension(*pi.base.bv);
60 if (kind_ == phantom || kind_ == vphantom) {
73 int const x2 = x + dim.wid / 2;
74 int const x1 = x2 - arrow_size;
75 int const x3 = x2 + arrow_size;
77 int const y1 = y - dim.asc;
78 int const y2 = y1 + arrow_size;
79 int const y4 = y + dim.des;
80 int const y3 = y4 - arrow_size;
83 pi.pain.line(x2, y1, x1, y2, Color_added_space);
84 pi.pain.line(x2, y1, x3, y2, Color_added_space);
87 pi.pain.line(x2, y4, x1, y3, Color_added_space);
88 pi.pain.line(x2, y4, x3, y3, Color_added_space);
91 pi.pain.line(x2, y1, x2, y4, Color_added_space);
94 if (kind_ == phantom || kind_ == hphantom) {
97 // y2--- <---------------->
104 int const x2 = x + arrow_size;
105 int const x4 = x + dim.wid;
106 int const x3 = x4 - arrow_size;
108 int const y2 = y + (dim.des - dim.asc) / 2;
109 int const y1 = y2 - arrow_size;
110 int const y3 = y2 + arrow_size;
113 pi.pain.line(x1, y2, x2, y3, Color_added_space);
114 pi.pain.line(x1, y2, x2, y1, Color_added_space);
117 pi.pain.line(x4, y2, x3, y3, Color_added_space);
118 pi.pain.line(x4, y2, x3, y1, Color_added_space);
121 pi.pain.line(x1, y2, x4, y2, Color_added_space);
124 else if (kind_ == mathclap) {
127 // y2--- -------->-<--------
134 int const x5 = x + dim.wid;
135 int const x3 = x + dim.wid / 2;
136 int const x2 = std::max(x1, x3 - arrow_size);
137 int const x4 = std::min(x5, x3 + arrow_size);
139 int const y2 = y + (dim.des - dim.asc) / 2;
140 int const y1 = y2 - arrow_size;
141 int const y3 = y2 + arrow_size;
144 pi.pain.line(x2, y3, x3, y2, Color_added_space);
145 pi.pain.line(x2, y1, x3, y2, Color_added_space);
148 pi.pain.line(x4, y3, x3, y2, Color_added_space);
149 pi.pain.line(x4, y1, x3, y2, Color_added_space);
152 pi.pain.line(x1, y2, x5, y2, Color_added_space);
155 else if (kind_ == mathllap) {
158 // y2--- ------------------>
165 int const x3 = x + dim.wid;
166 int const x2 = std::max(x1, x3 - arrow_size);
168 int const y2 = y + (dim.des - dim.asc) / 2;
169 int const y1 = y2 - arrow_size;
170 int const y3 = y2 + arrow_size;
173 pi.pain.line(x3, y2, x2, y3, Color_added_space);
174 pi.pain.line(x3, y2, x2, y1, Color_added_space);
177 pi.pain.line(x1, y2, x3, y2, Color_added_space);
180 else if (kind_ == mathrlap) {
183 // y2--- <------------------
190 int const x3 = x + dim.wid;
191 int const x2 = std::min(x3, x + arrow_size);
193 int const y2 = y + (dim.des - dim.asc) / 2;
194 int const y1 = y2 - arrow_size;
195 int const y3 = y2 + arrow_size;
198 pi.pain.line(x1, y2, x2, y3, Color_added_space);
199 pi.pain.line(x1, y2, x2, y1, Color_added_space);
202 pi.pain.line(x1, y2, x3, y2, Color_added_space);
205 else if (kind_ == smash || kind_ == smasht || kind_ == smashb) {
219 int const x2 = x + dim.wid / 2;
220 int const x1 = x2 - arrow_size;
221 int const x3 = x2 + arrow_size;
223 int const y1 = y - dim.asc;
224 int const y5 = y + dim.des;
226 int const y2 = std::max(y1, y3 - arrow_size);
227 int const y4 = std::min(y5, y3 + arrow_size);
230 if (kind_ != smashb) {
231 pi.pain.line(x1, y2, x2, y3, Color_added_space);
232 pi.pain.line(x3, y2, x2, y3, Color_added_space);
236 if (kind_ != smasht) {
237 pi.pain.line(x1, y4, x2, y3, Color_added_space);
238 pi.pain.line(x3, y4, x2, y3, Color_added_space);
243 pi.pain.line(x2, y1, x2, y3, Color_added_space);
244 else if (kind_ == smashb)
245 pi.pain.line(x2, y3, x2, y5, Color_added_space);
247 pi.pain.line(x2, y1, x2, y5, Color_added_space);
252 void InsetMathPhantom::write(TeXMathStream & os) const
254 MathEnsurer ensurer(os);
286 os << cell(0) << '}';
290 void InsetMathPhantom::normalize(NormalStream & os) const
321 os << cell(0) << ']';
325 void InsetMathPhantom::infoize(odocstream & os) const
359 void InsetMathPhantom::validate(LaTeXFeatures & features) const
361 InsetMathNest::validate(features);
370 features.require("amsmath");
375 features.require("mathtools");
381 bool InsetMathPhantom::visibleContents() const
383 return kind_ == phantom || kind_ == vphantom || kind_ == hphantom;