]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathFont.cpp
bfeeeff3977120bc30636c6f8b59481b614047aa
[lyx.git] / src / mathed / InsetMathFont.cpp
1 /**
2  * \file InsetMathFont.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathFont.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "MathParser.h"
17 #include "LaTeXFeatures.h"
18 #include "support/std_ostream.h"
19
20
21 namespace lyx {
22
23 using std::auto_ptr;
24
25
26 InsetMathFont::InsetMathFont(latexkeys const * key)
27         : InsetMathNest(1), key_(key)
28 {}
29
30
31 auto_ptr<Inset> InsetMathFont::doClone() const
32 {
33         return auto_ptr<Inset>(new InsetMathFont(*this));
34 }
35
36
37 InsetMath::mode_type InsetMathFont::currentMode() const
38 {
39         if (key_->extra == "mathmode")
40                 return MATH_MODE;
41         if (key_->extra == "textmode")
42                 return TEXT_MODE;
43         return UNDECIDED_MODE;
44 }
45
46
47 bool InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
48 {
49         FontSetChanger dummy(mi.base, key_->name);
50         cell(0).metrics(mi, dim);
51         metricsMarkers(dim);
52         if (dim_ == dim)
53                 return false;
54         dim_ = dim;
55         return true;
56 }
57
58
59 void InsetMathFont::draw(PainterInfo & pi, int x, int y) const
60 {
61         FontSetChanger dummy(pi.base, key_->name.c_str());
62         cell(0).draw(pi, x + 1, y);
63         drawMarkers(pi, x, y);
64         setPosCache(pi, x, y);
65 }
66
67
68 void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
69 {
70         cell(0).metricsT(mi, dim_);
71 }
72
73
74 void InsetMathFont::drawT(TextPainter & pain, int x, int y) const
75 {
76         cell(0).drawT(pain, x, y);
77 }
78
79
80 docstring InsetMathFont::name() const
81 {
82         return key_->name;
83 }
84
85
86 void InsetMathFont::validate(LaTeXFeatures & features) const
87 {
88         InsetMathNest::validate(features);
89         // Make sure amssymb is put in preamble if Blackboard Bold or
90         // Fraktur used:
91         if (key_->name == "mathfrak" || key_->name == "mathbb")
92                 features.require("amssymb");
93         if (key_->name == "text")
94                 features.require("amsmath");
95         if (key_->name == "textipa")
96                 features.require("tipa");
97 }
98
99
100 void InsetMathFont::infoize(odocstream & os) const
101 {
102         os << "Font: " << key_->name;
103 }
104
105
106 } // namespace lyx