]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathDots.cpp
Add missing revert routine to lyx_2_0.py
[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 namespace {
78 std::string symbolToXMLEntity(docstring const & n) {
79         // which symbols we support is decided by what is listed in
80         // lib/symbols as generating a dots inset
81         if (n == "dots" || n == "dotsc" || n == "dotso" || n == "ldots")
82                 return "&#x2026;";
83         else if (n == "adots" || n == "iddots")
84                 return "&#x22F0;";
85         else if (n == "cdots" || n == "dotsb" || n == "dotsi" || n == "dotsm")
86                 return "&#x22EF;";
87         else if (n == "ddots")
88                 return "&#x22F1;";
89         else if (n == "vdots")
90                 return "&#x22EE;";
91         else LASSERT(false, return "&#x2026;");
92 }
93 }
94
95
96 void InsetMathDots::mathmlize(MathMLStream & ms) const
97 {
98         ms << MTagInline("mi") << from_ascii(symbolToXMLEntity(key_->name)) << ETagInline("mi");
99 }
100
101
102 void InsetMathDots::htmlize(HtmlStream & os) const
103 {
104         os << from_ascii(symbolToXMLEntity(key_->name));
105 }
106
107 } // namespace lyx