A bit more re-organization.
[lyx.git] / src / mathed / InsetMathSpecialChar.cpp
blob2c600d0c2b38791bf7c0852c368fb06630a5a38a
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.
6 * \author Enrico Forestieri
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "InsetMathSpecialChar.h"
15 #include "MathSupport.h"
16 #include "MathStream.h"
17 #include "MetricsInfo.h"
19 #include "Dimension.h"
20 #include "LaTeXFeatures.h"
21 #include "TextPainter.h"
23 #include "frontends/FontMetrics.h"
24 #include "frontends/Painter.h"
26 #include "support/lassert.h"
29 namespace lyx {
32 InsetMathSpecialChar::InsetMathSpecialChar(docstring const & name)
33 : name_(name), kerning_(0)
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, /**/);
44 } else
45 char_ = name.at(0);
50 Inset * InsetMathSpecialChar::clone() const
52 return new InsetMathSpecialChar(*this);
56 void InsetMathSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
58 if (char_ == ' ') {
59 dim.asc = 4;
60 dim.des = 0;
61 dim.wid = 10;
62 } else if (mi.base.fontname == "mathnormal") {
63 ShapeChanger dummy(mi.base.font, UP_SHAPE);
64 dim = theFontMetrics(mi.base.font).dimension(char_);
65 } else {
66 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
67 dim = fm.dimension(char_);
68 kerning_ = fm.rbearing(char_) - dim.wid;
73 void InsetMathSpecialChar::draw(PainterInfo & pi, int x, int y) const
75 if (char_ == ' ') {
76 int xp[4];
77 int yp[4];
78 int w = 10;
80 xp[0] = ++x; yp[0] = y - 3;
81 xp[1] = x; yp[1] = y;
82 xp[2] = x + w - 2; yp[2] = y;
83 xp[3] = x + w - 2; yp[3] = y - 3;
85 pi.pain.lines(xp, yp, 4, Color_special);
86 } else if (pi.base.fontname == "mathnormal") {
87 ShapeChanger dummy(pi.base.font, UP_SHAPE);
88 pi.draw(x, y, char_);
89 } else {
90 pi.draw(x, y, char_);
95 void InsetMathSpecialChar::metricsT(TextMetricsInfo const &, Dimension & dim) const
97 dim.wid = 1;
98 dim.asc = 1;
99 dim.des = 0;
103 void InsetMathSpecialChar::drawT(TextPainter & pain, int x, int y) const
105 pain.draw(x, y, char_);
109 void InsetMathSpecialChar::write(WriteStream & os) const
111 os << '\\' << name_;
112 if (name_.size() != 1)
113 os.pendingSpace(true);
117 void InsetMathSpecialChar::validate(LaTeXFeatures & features) const
119 if (name_ == "mathcircumflex")
120 features.require("mathcircumflex");
124 void InsetMathSpecialChar::normalize(NormalStream & os) const
126 os << "[char ";
127 os.os().put(char_);
128 os << " mathalpha]";
132 void InsetMathSpecialChar::maple(MapleStream & os) const
134 os.os().put(char_);
138 void InsetMathSpecialChar::mathematica(MathematicaStream & os) const
140 os.os().put(char_);
144 void InsetMathSpecialChar::octave(OctaveStream & os) const
146 os.os().put(char_);
150 void InsetMathSpecialChar::mathmlize(MathStream & ms) const
152 switch (char_) {
153 case '&':
154 ms << "&amp;";
155 break;
156 default:
157 ms.os().put(char_);
158 break;
163 } // namespace lyx