]> git.lyx.org Git - features.git/blob - src/mathed/InsetMathDots.cpp
41933f3ab18710823d25f2785fca6bfcb0faa0e0
[features.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 "Dimension.h"
17 #include "LaTeXFeatures.h"
18 #include "MathStream.h"
19 #include "MathSupport.h"
20 #include "MathParser.h"
21 #include "MetricsInfo.h"
22
23 #include "frontends/FontMetrics.h"
24 #include "support/lassert.h"
25
26 namespace lyx {
27
28 InsetMathDots::InsetMathDots(latexkeys const * key)
29         : dh_(0), key_(key)
30 {}
31
32
33 Inset * InsetMathDots::clone() const
34 {
35         return new InsetMathDots(*this);
36 }
37
38
39 void InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const
40 {
41         dim = theFontMetrics(mi.base.font).dimension('X');
42         dh_ = 0;
43         if (key_->name == "cdots" || key_->name == "dotsb"
44                         || key_->name == "dotsm" || key_->name == "dotsi")
45                 dh_ = dim.asc / 2;
46         else if (key_->name == "dotsc" || key_->name == "ldots")
47                 dh_ = 2;
48         else if (key_->name == "ddots" || key_->name == "adots"
49                         || key_->name == "iddots" || key_->name == "vdots")
50                 dh_ = dim.asc;
51 }
52
53
54 void InsetMathDots::draw(PainterInfo & pi, int x, int y) const
55 {
56         Dimension const dim = dimension(*pi.base.bv);
57         if (key_->name == "adots" || key_->name == "iddots")
58                 --y;
59         else if (key_->name == "vdots")
60                 x += (dim.width() - 2) / 2;
61         mathed_draw_deco(pi, x - 1, y - dh_, dim.width() - 2, dim.ascent(),
62                         key_->name);
63 }
64
65
66 docstring InsetMathDots::name() const
67 {
68         return key_->name;
69 }
70
71
72 void InsetMathDots::validate(LaTeXFeatures & features) const
73 {
74         if (!key_->required.empty())
75                 features.require(key_->required);
76 }
77
78
79 void InsetMathDots::mathmlize(MathMLStream & ms) const
80 {
81         // which symbols we support is decided by what is listed in
82         // lib/symbols as generating a dots inset
83         docstring const & n = key_->name;
84         std::string ent;
85         if (ms.xmlMode()) {
86                 if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
87                         ent = "&#x2026;";
88                 else if (n == "adots" || n == "iddots")
89                         ent = "&#x22F0;";
90                 else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
91                         ent = "&#x22EF;";
92                 else if (n == "ddots")
93                         ent = "&#x22F1;";
94                 else if (n == "vdots")
95                         ent = "&#x22EE;";
96                 else LASSERT(false, ent = "&#x2026;");
97         } else {
98                 if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
99                         ent = "&hellip;";
100                 else if (n == "adots" || n == "iddots")
101                         ent = "&utdot;";
102                 else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
103                         ent = "&ctdot;";
104                 else if (n == "ddots")
105                         ent = "&dtdot;";
106                 else if (n == "vdots")
107                         ent = "&vellip;";
108                 else LASSERT(false, ent = "&hellip;");
109         }
110         ms << MTag("mi") << from_ascii(ent) << ETag("mi");
111 }
112
113
114 void InsetMathDots::htmlize(HtmlStream & os) const
115 {
116         // which symbols we support is decided by what is listed in
117         // lib/symbols as generating a dots inset
118         docstring const & n = key_->name;
119         std::string ent;
120         if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
121                 ent = "&#x02026;";
122         else if (n == "adots" || n == "iddots")
123                 ent = "&#x022F0;";
124         else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
125                 ent = "&#x022EF;";
126         else if (n == "ddots")
127                 ent = "&#x022F1;";
128         else if (n == "vdots")
129                 ent = "&#x022EE;";
130         else
131                 LASSERT(false, ent = "#x02026;");
132         os << from_ascii(ent);
133 }
134
135 } // namespace lyx