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);
43 metricsMarkers(mi, dim);
47 void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
49 Changer dummy = pi.base.changeEnsureMath();
50 static int const arrow_size = 4;
52 // We first draw the text and then an arrow
53 ColorCode const origcol = pi.base.font.color();
54 if (visibleContents())
55 pi.base.font.setColor(Color_special);
56 cell(0).draw(pi, x + 1, y);
57 if (visibleContents())
58 pi.base.font.setColor(origcol);
59 Dimension const dim = dimension(*pi.base.bv);
61 if (kind_ == phantom || kind_ == vphantom) {
74 int const x2 = x + dim.wid / 2;
75 int const x1 = x2 - arrow_size;
76 int const x3 = x2 + arrow_size;
78 int const y1 = y - dim.asc;
79 int const y2 = y1 + arrow_size;
80 int const y4 = y + dim.des;
81 int const y3 = y4 - arrow_size;
84 pi.pain.line(x2, y1, x1, y2, Color_added_space);
85 pi.pain.line(x2, y1, x3, y2, Color_added_space);
88 pi.pain.line(x2, y4, x1, y3, Color_added_space);
89 pi.pain.line(x2, y4, x3, y3, Color_added_space);
92 pi.pain.line(x2, y1, x2, y4, Color_added_space);
95 if (kind_ == phantom || kind_ == hphantom) {
98 // y2--- <---------------->
105 int const x2 = x + arrow_size;
106 int const x4 = x + dim.wid;
107 int const x3 = x4 - arrow_size;
109 int const y2 = y + (dim.des - dim.asc) / 2;
110 int const y1 = y2 - arrow_size;
111 int const y3 = y2 + arrow_size;
114 pi.pain.line(x1, y2, x2, y3, Color_added_space);
115 pi.pain.line(x1, y2, x2, y1, Color_added_space);
118 pi.pain.line(x4, y2, x3, y3, Color_added_space);
119 pi.pain.line(x4, y2, x3, y1, Color_added_space);
122 pi.pain.line(x1, y2, x4, y2, Color_added_space);
125 else if (kind_ == mathclap) {
128 // y2--- -------->-<--------
135 int const x5 = x + dim.wid;
136 int const x3 = x + dim.wid / 2;
137 int const x2 = std::max(x1, x3 - arrow_size);
138 int const x4 = std::min(x5, x3 + arrow_size);
140 int const y2 = y + (dim.des - dim.asc) / 2;
141 int const y1 = y2 - arrow_size;
142 int const y3 = y2 + arrow_size;
145 pi.pain.line(x2, y3, x3, y2, Color_added_space);
146 pi.pain.line(x2, y1, x3, y2, Color_added_space);
149 pi.pain.line(x4, y3, x3, y2, Color_added_space);
150 pi.pain.line(x4, y1, x3, y2, Color_added_space);
153 pi.pain.line(x1, y2, x5, y2, Color_added_space);
156 else if (kind_ == mathllap) {
159 // y2--- ------------------>
166 int const x3 = x + dim.wid;
167 int const x2 = std::max(x1, x3 - arrow_size);
169 int const y2 = y + (dim.des - dim.asc) / 2;
170 int const y1 = y2 - arrow_size;
171 int const y3 = y2 + arrow_size;
174 pi.pain.line(x3, y2, x2, y3, Color_added_space);
175 pi.pain.line(x3, y2, x2, y1, Color_added_space);
178 pi.pain.line(x1, y2, x3, y2, Color_added_space);
181 else if (kind_ == mathrlap) {
184 // y2--- <------------------
191 int const x3 = x + dim.wid;
192 int const x2 = std::min(x3, x + arrow_size);
194 int const y2 = y + (dim.des - dim.asc) / 2;
195 int const y1 = y2 - arrow_size;
196 int const y3 = y2 + arrow_size;
199 pi.pain.line(x1, y2, x2, y3, Color_added_space);
200 pi.pain.line(x1, y2, x2, y1, Color_added_space);
203 pi.pain.line(x1, y2, x3, y2, Color_added_space);
206 else if (kind_ == smash || kind_ == smasht || kind_ == smashb) {
220 int const x2 = x + dim.wid / 2;
221 int const x1 = x2 - arrow_size;
222 int const x3 = x2 + arrow_size;
224 int const y1 = y - dim.asc;
225 int const y5 = y + dim.des;
227 int const y2 = std::max(y1, y3 - arrow_size);
228 int const y4 = std::min(y5, y3 + arrow_size);
231 if (kind_ != smashb) {
232 pi.pain.line(x1, y2, x2, y3, Color_added_space);
233 pi.pain.line(x3, y2, x2, y3, Color_added_space);
237 if (kind_ != smasht) {
238 pi.pain.line(x1, y4, x2, y3, Color_added_space);
239 pi.pain.line(x3, y4, x2, y3, Color_added_space);
244 pi.pain.line(x2, y1, x2, y3, Color_added_space);
245 else if (kind_ == smashb)
246 pi.pain.line(x2, y3, x2, y5, Color_added_space);
248 pi.pain.line(x2, y1, x2, y5, Color_added_space);
251 drawMarkers(pi, x, y);
255 void InsetMathPhantom::write(WriteStream & os) const
257 MathEnsurer ensurer(os);
289 os << cell(0) << '}';
293 void InsetMathPhantom::normalize(NormalStream & os) const
324 os << cell(0) << ']';
328 void InsetMathPhantom::infoize(odocstream & os) const
362 void InsetMathPhantom::validate(LaTeXFeatures & features) const
364 InsetMathNest::validate(features);
373 features.require("amsmath");
378 features.require("mathtools");
384 bool InsetMathPhantom::visibleContents() const
386 return kind_ == phantom || kind_ == vphantom || kind_ == hphantom;