]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathDots.cpp
Revert r32684, per Andre's suggestion.
[lyx.git] / src / mathed / InsetMathDots.cpp
1 /**
2  * \file InsetMathDots.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetMathDots.h"
15
16 #include "LaTeXFeatures.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19 #include "MathParser.h"
20 #include "MetricsInfo.h"
21
22 #include "frontends/FontMetrics.h"
23 #include "support/lassert.h"
24
25 namespace lyx {
26
27 InsetMathDots::InsetMathDots(latexkeys const * key)
28         : key_(key)
29 {}
30
31
32 Inset * InsetMathDots::clone() const
33 {
34         return new InsetMathDots(*this);
35 }
36
37
38 void InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const
39 {
40         dim = theFontMetrics(mi.base.font).dimension('M');
41         dh_ = 0;
42         if (key_->name == "cdots" || key_->name == "dotsb"
43                         || key_->name == "dotsm" || key_->name == "dotsi")
44                 dh_ = dim.asc / 2;
45         else if (key_->name == "dotsc")
46                 dh_ = dim.asc / 4;
47         else if (key_->name == "vdots") {
48                 dim.wid = (dim.wid / 2) + 1;
49                 dh_ = dim.asc;
50         }
51         else if (key_->name == "ddots" || key_->name == "adots" || key_->name == "iddots")
52                 dh_ = dim.asc;
53 }
54
55
56 void InsetMathDots::draw(PainterInfo & pain, int x, int y) const
57 {
58         Dimension const dim = dimension(*pain.base.bv);
59         if (key_->name == "adots" || key_->name == "iddots")
60                 --y;
61         mathed_draw_deco(pain, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
62                         key_->name);
63         if (key_->name == "vdots" || key_->name == "ddots" || key_->name == "adots" || key_->name == "iddots")
64                 ++x;
65         if (key_->name == "adots" || key_->name == "iddots")
66                 ++y;
67         else if (key_->name != "vdots")
68                 --y;
69         mathed_draw_deco(pain, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
70                 key_->name);
71         setPosCache(pain, x, y);
72 }
73
74
75 docstring InsetMathDots::name() const
76 {
77         return key_->name;
78 }
79
80
81 void InsetMathDots::validate(LaTeXFeatures & features) const
82 {
83         if (!key_->requires.empty())
84                 features.require(to_utf8(key_->requires));
85 }
86
87
88 void InsetMathDots::mathmlize(MathStream & os) const
89 {
90         // which symbols we support is decided by what is listed in
91         // lib/symbols as generating a dots inset
92         docstring const & n = key_->name;
93         std::string ent;
94         if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
95                 ent = "&hellip;";
96         else if (n == "adots")
97                 ent = "&utdot;";
98         else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
99                 ent = "&ctdot;";
100         else if (n == "ddots")
101                 ent = "&dtdot;";
102         else if (n == "iddots")
103                 ent = "&utdot;";
104         else if (n == "vdots")
105                 ent = "&vellip;";
106         else
107                 LASSERT(false, ent = "&hellip;");
108         os << MTag("mi") << from_ascii(ent) << ETag("mi");
109 }
110
111 } // namespace lyx