]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBig.C
This commit is a big rework of the FontLoader/FontMetrics interaction. Only Qt4 for...
[lyx.git] / src / mathed / InsetMathBig.C
1 /**
2  * \file InsetMathBig.C
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 "InsetMathBig.h"
14 #include "MathSupport.h"
15 #include "MathMLStream.h"
16 #include "MathStream.h"
17
18 #include "frontends/Application.h"
19 #include "frontends/FontLoader.h"
20 #include "frontends/FontMetrics.h"
21
22 #include "support/lstrings.h"
23
24
25 using std::string;
26 using std::auto_ptr;
27
28
29 InsetMathBig::InsetMathBig(string const & name, string const & delim)
30         : name_(name), delim_(delim)
31 {}
32
33
34 string InsetMathBig::name() const
35 {
36         return name_;
37 }
38
39
40 auto_ptr<InsetBase> InsetMathBig::doClone() const
41 {
42         return auto_ptr<InsetBase>(new InsetMathBig(*this));
43 }
44
45
46 InsetMathBig::size_type InsetMathBig::size() const
47 {
48         // order: big Big bigg Bigg biggg Biggg
49         //        0   1   2    3    4     5
50         return name_[0] == 'B' ?
51                 2 * (name_.size() - 4) + 1:
52                 2 * (name_.size() - 4);
53 }
54
55
56 double InsetMathBig::increase() const
57 {
58         // The formula used in amsmath.sty is
59         // 1.2 * (1.0 + size() * 0.5) - 1.0.
60         // We use a smaller step and a bigger offset because our base size
61         // is different.
62         return (size() + 1) * 0.3;
63 }
64
65
66 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
67 {
68         double const h 
69                 = theApp->fontLoader().metrics(mi.base.font).ascent('I');
70         double const f = increase();
71         dim_.wid = 6;
72         dim_.asc = int(h + f * h);
73         dim_.des = int(f * h);
74         dim = dim_;
75 }
76
77
78 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
79 {
80         // mathed_draw_deco does not use the leading backslash, so remove it.
81         // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
82         // would treat it as |.
83         string const delim = (delim_ == "\\|") ?
84                 "Vert" :
85                 lyx::support::ltrim(delim_, "\\");
86         mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(),
87                          delim);
88         setPosCache(pi, x, y);
89 }
90
91
92 void InsetMathBig::write(WriteStream & os) const
93 {
94         os << '\\' << name_ << ' ' << delim_;
95         if (delim_[0] == '\\')
96                 os.pendingSpace(true);
97 }
98
99
100 void InsetMathBig::normalize(NormalStream & os) const
101 {
102         os << '[' << name_ << ' ' <<  delim_ << ']';
103 }
104
105
106 void InsetMathBig::infoize2(std::ostream & os) const
107 {
108         os << name_;
109 }
110
111
112 bool InsetMathBig::isBigInsetDelim(string const & delim)
113 {
114         // mathed_draw_deco must handle these
115         static char const * const delimiters[] = {
116                 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
117                 "|", "/", "\\|", "\\vert", "\\Vert", "'", "\\backslash",
118                 "\\langle", "\\lceil", "\\lfloor",
119                 "\\rangle", "\\rceil", "\\rfloor",
120                 "\\downarrow", "\\Downarrow",
121                 "\\uparrow", "\\Uparrow",
122                 "\\updownarrow", "\\Updownarrow", ""
123         };
124         return (lyx::support::findToken(delimiters, delim) >= 0);
125 }