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