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"
25 InsetMathPhantom::InsetMathPhantom(Buffer * buf, Kind k)
26 : InsetMathNest(buf, 1), kind_(k)
30 Inset * InsetMathPhantom::clone() const
32 return new InsetMathPhantom(*this);
36 void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
38 cell(0).metrics(mi, dim);
43 void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
45 static int const arrow_size = 4;
47 // We first draw the text and then an arrow
48 ColorCode const origcol = pi.base.font.color();
49 if (visibleContents())
50 pi.base.font.setColor(Color_special);
51 cell(0).draw(pi, x + 1, y);
52 if (visibleContents())
53 pi.base.font.setColor(origcol);
54 Dimension const dim = dimension(*pi.base.bv);
56 if (kind_ == phantom || kind_ == vphantom) {
69 int const x2 = x + dim.wid / 2;
70 int const x1 = x2 - arrow_size;
71 int const x3 = x2 + arrow_size;
73 int const y1 = y - dim.asc;
74 int const y2 = y1 + arrow_size;
75 int const y4 = y + dim.des;
76 int const y3 = y4 - arrow_size;
79 pi.pain.line(x2, y1, x1, y2, Color_added_space);
80 pi.pain.line(x2, y1, x3, y2, Color_added_space);
83 pi.pain.line(x2, y4, x1, y3, Color_added_space);
84 pi.pain.line(x2, y4, x3, y3, Color_added_space);
87 pi.pain.line(x2, y1, x2, y4, Color_added_space);
90 if (kind_ == phantom || kind_ == hphantom) {
93 // y2--- <---------------->
100 int const x2 = x + arrow_size;
101 int const x4 = x + dim.wid;
102 int const x3 = x4 - arrow_size;
104 int const y2 = y + (dim.des - dim.asc) / 2;
105 int const y1 = y2 - arrow_size;
106 int const y3 = y2 + arrow_size;
109 pi.pain.line(x1, y2, x2, y3, Color_added_space);
110 pi.pain.line(x1, y2, x2, y1, Color_added_space);
113 pi.pain.line(x4, y2, x3, y3, Color_added_space);
114 pi.pain.line(x4, y2, x3, y1, Color_added_space);
117 pi.pain.line(x1, y2, x4, y2, Color_added_space);
120 else if (kind_ == mathclap) {
123 // y2--- -------->-<--------
130 int const x5 = x + dim.wid;
131 int const x3 = x + dim.wid / 2;
132 int const x2 = std::max(x1, x3 - arrow_size);
133 int const x4 = std::min(x5, x3 + arrow_size);
135 int const y2 = y + (dim.des - dim.asc) / 2;
136 int const y1 = y2 - arrow_size;
137 int const y3 = y2 + arrow_size;
140 pi.pain.line(x2, y3, x3, y2, Color_added_space);
141 pi.pain.line(x2, y1, x3, y2, Color_added_space);
144 pi.pain.line(x4, y3, x3, y2, Color_added_space);
145 pi.pain.line(x4, y1, x3, y2, Color_added_space);
148 pi.pain.line(x1, y2, x5, y2, Color_added_space);
151 else if (kind_ == mathllap) {
154 // y2--- ------------------>
161 int const x3 = x + dim.wid;
162 int const x2 = std::max(x1, x3 - arrow_size);
164 int const y2 = y + (dim.des - dim.asc) / 2;
165 int const y1 = y2 - arrow_size;
166 int const y3 = y2 + arrow_size;
169 pi.pain.line(x3, y2, x2, y3, Color_added_space);
170 pi.pain.line(x3, y2, x2, y1, Color_added_space);
173 pi.pain.line(x1, y2, x3, y2, Color_added_space);
176 else if (kind_ == mathrlap) {
179 // y2--- <------------------
186 int const x3 = x + dim.wid;
187 int const x2 = std::min(x3, x + arrow_size);
189 int const y2 = y + (dim.des - dim.asc) / 2;
190 int const y1 = y2 - arrow_size;
191 int const y3 = y2 + arrow_size;
194 pi.pain.line(x1, y2, x2, y3, Color_added_space);
195 pi.pain.line(x1, y2, x2, y1, Color_added_space);
198 pi.pain.line(x1, y2, x3, y2, Color_added_space);
201 else if (kind_ == smash || kind_ == smasht || kind_ == smashb) {
215 int const x2 = x + dim.wid / 2;
216 int const x1 = x2 - arrow_size;
217 int const x3 = x2 + arrow_size;
219 int const y1 = y - dim.asc;
220 int const y5 = y + dim.des;
222 int const y2 = std::max(y1, y3 - arrow_size);
223 int const y4 = std::min(y5, y3 + arrow_size);
226 if (kind_ != smashb) {
227 pi.pain.line(x1, y2, x2, y3, Color_added_space);
228 pi.pain.line(x3, y2, x2, y3, Color_added_space);
232 if (kind_ != smasht) {
233 pi.pain.line(x1, y4, x2, y3, Color_added_space);
234 pi.pain.line(x3, y4, x2, y3, Color_added_space);
239 pi.pain.line(x2, y1, x2, y3, Color_added_space);
240 else if (kind_ == smashb)
241 pi.pain.line(x2, y3, x2, y5, Color_added_space);
243 pi.pain.line(x2, y1, x2, y5, Color_added_space);
246 drawMarkers(pi, x, y);
250 void InsetMathPhantom::write(WriteStream & os) const
252 MathEnsurer ensurer(os);
284 os << cell(0) << '}';
288 void InsetMathPhantom::normalize(NormalStream & os) const
319 os << cell(0) << ']';
323 void InsetMathPhantom::infoize(odocstream & os) const
357 void InsetMathPhantom::validate(LaTeXFeatures & features) const
359 InsetMathNest::validate(features);
368 features.require("amsmath");
373 features.require("mathtools");
379 bool InsetMathPhantom::visibleContents() const
381 return kind_ == phantom || kind_ == vphantom || kind_ == hphantom;