]> git.lyx.org Git - lyx.git/blob - src/mathed/math_funcinset.C
LyX Drinkers United: patch 2
[lyx.git] / src / mathed / math_funcinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_funcinset.h"
8 #include "lyxfont.h"
9 #include "font.h"
10 #include "Painter.h"
11 #include "mathed/support.h"
12 #include "support/LOstream.h"
13
14
15 using std::ostream;
16
17 extern LyXFont WhichFont(short type, int size);
18
19
20 MathFuncInset::MathFuncInset(string const & nm, MathInsetTypes ot)
21         : MathInset(nm, ot)
22 {
23         lims_ = (GetType() == LM_OT_FUNCLIM);
24 }
25
26
27 MathInset * MathFuncInset::Clone() const
28 {
29         return new MathFuncInset(*this);
30 }
31
32
33 void MathFuncInset::draw(Painter & pain, int x, int y)
34
35         if (!name_.empty() && name_[0] > ' ') {
36                 LyXFont font = WhichFont(LM_TC_TEXTRM, size());
37 #ifndef NO_LATEX
38                 font.setLatex(LyXFont::ON);
39 #endif
40                 x += (lyxfont::width('I', font) + 3) / 4;
41                 pain.text(x, y, name_, font);
42         }
43 }
44
45
46 void MathFuncInset::Write(std::ostream & os, bool /* fragile */) const
47 {
48         os << "\\" << name_ << ' ';
49 }
50
51
52 void MathFuncInset::WriteNormal(std::ostream & os) const
53 {
54         os << "[" << name_ << "] ";
55 }
56
57
58 void MathFuncInset::Metrics(MathStyles st) 
59 {
60         LyXFont font = WhichFont(LM_TC_TEXTRM, size());
61 #ifndef NO_LATEX
62         font.setLatex(LyXFont::ON);
63 #endif
64         size_ = st;
65         if (name_.empty()) {
66                 width_   = lyxfont::width('M', font);
67                 ascent_  = lyxfont::ascent('M', font);
68                 descent_ = 0;
69         } else {
70                 width_ = lyxfont::width(name_, font) + lyxfont::width('I', font) / 2;
71                 mathed_string_height(LM_TC_TEXTRM, size_, name_, ascent_, descent_);
72         }
73 }
74
75
76 bool MathFuncInset::GetLimits() const 
77 {  
78         return lims_ && (size() == LM_ST_DISPLAY); 
79