]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macroarg.C
fonts as insets
[lyx.git] / src / mathed / math_macroarg.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_macroarg.h"
6 #include "math_macro.h"
7 #include "math_mathmlstream.h"
8 #include "math_support.h"
9 #include "debug.h"
10
11
12 using std::endl;
13
14
15 MathMacroArgument::MathMacroArgument(int n)
16         : MathNestInset(1), number_(n), expanded_(false)
17 {
18         if (n < 1 || n > 9) {
19                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
20                         << n << endl;
21         }
22         str_[0] = '#';
23         str_[1] = static_cast<unsigned char>('0' + n);
24         str_[2] = '\0';
25 }
26
27
28 MathInset * MathMacroArgument::clone() const
29 {
30         return new MathMacroArgument(*this);
31 }
32
33
34 void MathMacroArgument::write(WriteStream & os) const
35 {
36         os << str_;
37 }
38
39
40 void MathMacroArgument::metrics(MathMetricsInfo & mi) const
41 {
42         if (expanded_) {
43                 xcell(0).metrics(mi);
44                 width_   = xcell(0).width();
45                 ascent_  = xcell(0).ascent();
46                 descent_ = xcell(0).descent();
47         } else {
48                 mathed_string_dim(mi.base.font, str_, ascent_, descent_, width_);
49         }
50 }
51
52
53 void MathMacroArgument::draw(MathPainterInfo & pi, int x, int y) const
54 {
55         if (expanded_)
56                 xcell(0).draw(pi, x, y);
57         else
58                 drawStrRed(pi, x, y, str_);
59 }
60
61
62 void MathMacroArgument::normalize(NormalStream & os) const
63 {
64         os << "[macroarg " << str_ << "] ";
65 }
66
67
68 void MathMacroArgument::substitute(MathMacro const & m)
69 {
70         cell(0) = m.cell(number_ - 1);
71         expanded_ = true;
72 }