]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSpecialChar.cpp
g-brief loads babel internally. So don't load it ourselves.
[lyx.git] / src / mathed / InsetMathSpecialChar.cpp
1 /**
2  * \file InsetMathSpecialChar.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Enrico Forestieri
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathSpecialChar.h"
14
15 #include "MathSupport.h"
16 #include "MathStream.h"
17 #include "MetricsInfo.h"
18
19 #include "Dimension.h"
20 #include "LaTeXFeatures.h"
21 #include "TextPainter.h"
22
23 #include "frontends/FontMetrics.h"
24 #include "frontends/Painter.h"
25
26 #include "support/lassert.h"
27
28
29 namespace lyx {
30
31
32 InsetMathSpecialChar::InsetMathSpecialChar(docstring const & name)
33         : name_(name), kerning_(0)
34 {
35         if (name.size() != 1) {
36                 if (name == "textasciicircum" || name == "mathcircumflex")
37                         char_ = '^';
38                 else if (name == "textasciitilde")
39                         char_ = '~';
40                 else if (name == "textbackslash")
41                         char_ = '\\';
42                 else
43                         LASSERT(false, char_ = '?');
44         } else
45                 char_ = name.at(0);
46 }
47
48
49
50 Inset * InsetMathSpecialChar::clone() const
51 {
52         return new InsetMathSpecialChar(*this);
53 }
54
55
56 void InsetMathSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
57 {
58         if (mi.base.fontname == "mathnormal") {
59                 Changer dummy = mi.base.font.changeShape(UP_SHAPE);
60                 dim = theFontMetrics(mi.base.font).dimension(char_);
61         } else {
62                 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
63                 dim = fm.dimension(char_);
64                 kerning_ = mathed_char_kerning(mi.base.font, char_);
65         }
66 }
67
68
69 void InsetMathSpecialChar::draw(PainterInfo & pi, int x, int y) const
70 {
71         if (pi.base.fontname == "mathnormal") {
72                 Changer dummy = pi.base.font.changeShape(UP_SHAPE);
73                 pi.draw(x, y, char_);
74         } else {
75                 pi.draw(x, y, char_);
76         }
77 }
78
79
80 void InsetMathSpecialChar::metricsT(TextMetricsInfo const &, Dimension & dim) const
81 {
82         dim.wid = 1;
83         dim.asc = 1;
84         dim.des = 0;
85 }
86
87
88 void InsetMathSpecialChar::drawT(TextPainter & pain, int x, int y) const
89 {
90         pain.draw(x, y, char_);
91 }
92
93
94 void InsetMathSpecialChar::write(TeXMathStream & os) const
95 {
96         os << '\\' << name_;
97         if (name_.size() != 1)
98                 os.pendingSpace(true);
99 }
100
101
102 void InsetMathSpecialChar::validate(LaTeXFeatures & features) const
103 {
104         if (name_ == "mathcircumflex")
105                 features.require("mathcircumflex");
106 }
107
108
109 void InsetMathSpecialChar::normalize(NormalStream & os) const
110 {
111         os << "[char ";
112         os.os().put(char_);
113         os << " mathalpha]";
114 }
115
116
117 void InsetMathSpecialChar::maple(MapleStream & os) const
118 {
119         os.os().put(char_);
120 }
121
122
123 void InsetMathSpecialChar::mathematica(MathematicaStream & os) const
124 {
125         os.os().put(char_);
126 }
127
128
129 void InsetMathSpecialChar::octave(OctaveStream & os) const
130 {
131         os.os().put(char_);
132 }
133
134
135 void InsetMathSpecialChar::mathmlize(MathMLStream & ms) const
136 {
137         switch (char_) {
138         case '&':
139                 ms << "&amp;";
140                 break;
141         default:
142                 ms.os().put(char_);
143                 break;
144         }
145 }
146
147
148 void InsetMathSpecialChar::htmlize(HtmlStream & ms) const
149 {
150         switch (char_) {
151         case '&':
152                 ms << "&amp;";
153                 break;
154         default:
155                 ms.os().put(char_);
156                 break;
157         }
158 }
159
160
161 } // namespace lyx