]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fontinset.C
playing around with visual feedback for the new mathed font insets
[lyx.git] / src / mathed / math_fontinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_fontinset.h"
8 #include "debug.h"
9 #include "math_mathmlstream.h"
10 #include "math_streamstr.h"
11 #include "math_support.h"
12 #include "LaTeXFeatures.h"
13 #include "textpainter.h"
14 #include "frontends/Painter.h"
15
16
17
18
19 MathFontInset::MathFontInset(string const & name)
20         : MathNestInset(1), name_(name)
21 {
22         //lock(true);
23 }
24
25
26 MathInset * MathFontInset::clone() const
27 {
28         return new MathFontInset(*this);
29 }
30
31
32 void MathFontInset::metrics(MathMetricsInfo & mi) const
33 {
34         MathFontSetChanger dummy(mi.base, name_.c_str());
35         xcell(0).metrics(mi);
36         width_   = xcell(0).width() + 6;
37         ascent_  = xcell(0).ascent();
38         descent_ = xcell(0).descent() + 3;
39 }
40
41
42 void MathFontInset::draw(MathPainterInfo & pi, int x, int y) const
43 {
44         //lyxerr << "MathFontInset::draw\n";
45         MathNestInset::draw(pi, x, y);
46         MathFontSetChanger dummy(pi.base, name_.c_str());
47         xcell(0).draw(pi, x + 3, y);
48         int b = x + 1;
49         int t = x + width() - 1;
50         int d = y + descent();
51         pi.pain.line(b, d - 3, b, d, LColor::mathframe); 
52         pi.pain.line(t, d - 3, t, d, LColor::mathframe); 
53         pi.pain.line(b, d, b + 3, d, LColor::mathframe); 
54         pi.pain.line(t - 2, d, t, d, LColor::mathframe); 
55 }
56
57
58 void MathFontInset::metricsT(TextMetricsInfo const & mi) const
59 {
60         xcell(0).metricsT(mi);
61         width_   = xcell(0).width();
62         ascent_  = xcell(0).ascent();
63         descent_ = xcell(0).descent();
64 }
65
66
67 void MathFontInset::drawT(TextPainter & pain, int x, int y) const
68 {
69         //lyxerr << "drawing font code: " << code_ << '\n';
70         xcell(0).drawT(pain, x, y);
71 }
72
73
74 void MathFontInset::write(WriteStream & os) const
75 {
76         os << '\\' << name_ << '{' << cell(0) << '}';
77 }
78
79
80 void MathFontInset::normalize(NormalStream & os) const
81 {
82         os << "[font_ " << name_ << " " << cell(0) << "]";
83 }
84
85
86 void MathFontInset::validate(LaTeXFeatures & features) const
87 {
88         // Make sure amssymb is put in preamble if Blackboard Bold or
89         // Fraktur used:
90         if (name_ == "mathfrak" || name_ == "mathbb")
91                 features.require("amssymb");
92 }
93
94
95 void MathFontInset::infoize(std::ostream & os) const
96 {
97         os << "Font: " << name_;
98 }