]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathDots.cpp
Rename MathStream to MathMLStream.
[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 "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('M');
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")
47                 dh_ = dim.asc / 4;
48         else if (key_->name == "vdots") {
49                 dim.wid = (dim.wid / 2) + 1;
50                 dh_ = dim.asc;
51         }
52         else if (key_->name == "ddots" || key_->name == "adots" || key_->name == "iddots")
53                 dh_ = dim.asc;
54 }
55
56
57 void InsetMathDots::draw(PainterInfo & pi, int x, int y) const
58 {
59         Dimension const dim = dimension(*pi.base.bv);
60         if (key_->name == "adots" || key_->name == "iddots")
61                 --y;
62         mathed_draw_deco(pi, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
63                         key_->name);
64         if (key_->name == "vdots" || key_->name == "ddots" || key_->name == "adots" || key_->name == "iddots")
65                 ++x;
66         if (key_->name == "adots" || key_->name == "iddots")
67                 ++y;
68         else if (key_->name != "vdots")
69                 --y;
70         mathed_draw_deco(pi, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
71                 key_->name);
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_->required.empty())
84                 features.require(key_->required);
85 }
86
87
88 void InsetMathDots::mathmlize(MathMLStream & ms) 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 (ms.xmlMode()) {
95                 if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
96                         ent = "&#x2026;";
97                 else if (n == "adots" || n == "iddots")
98                         ent = "&#x22F0;";
99                 else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
100                         ent = "&#x22EF;";
101                 else if (n == "ddots")
102                         ent = "&#x22F1;";
103                 else if (n == "vdots")
104                         ent = "&#x22EE;";
105                 else LASSERT(false, ent = "&#x2026;");
106         } else {
107                 if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
108                         ent = "&hellip;";
109                 else if (n == "adots" || n == "iddots")
110                         ent = "&utdot;";
111                 else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
112                         ent = "&ctdot;";
113                 else if (n == "ddots")
114                         ent = "&dtdot;";
115                 else if (n == "vdots")
116                         ent = "&vellip;";
117                 else LASSERT(false, ent = "&hellip;");
118         }
119         ms << MTag("mi") << from_ascii(ent) << ETag("mi");
120 }
121
122
123 void InsetMathDots::htmlize(HtmlStream & os) const
124 {
125         // which symbols we support is decided by what is listed in
126         // lib/symbols as generating a dots inset
127         docstring const & n = key_->name;
128         std::string ent;
129         if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
130                 ent = "&#x02026;";
131         else if (n == "adots" || n == "iddots")
132                 ent = "&#x022F0;";
133         else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
134                 ent = "&#x022EF;";
135         else if (n == "ddots")
136                 ent = "&#x022F1;";
137         else if (n == "vdots")
138                 ent = "&#x022EE;";
139         else
140                 LASSERT(false, ent = "#x02026;");
141         os << from_ascii(ent);
142 }
143
144 } // namespace lyx