]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
use stream-like syntax for LaTeX output
[lyx.git] / src / mathed / math_fracinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_fracinset.h"
6 #include "mathed/support.h"
7 #include "Painter.h"
8 #include "support/LOstream.h"
9
10
11 MathFracInset::MathFracInset(bool atop)
12         : atop_(atop)
13 {}
14
15
16 MathInset * MathFracInset::clone() const
17 {   
18         return new MathFracInset(*this);
19 }
20
21
22 void MathFracInset::metrics(MathMetricsInfo const & st) const
23 {
24         size_    = st;
25         size_.size = smallerStyleFrac(size_.size);
26         xcell(0).metrics(size_);
27         xcell(1).metrics(size_);
28         width_   = std::max(xcell(0).width(), xcell(1).width()) + 4; 
29         ascent_  = xcell(0).height() + 4 + 5;
30         descent_ = xcell(1).height() + 4 - 5; 
31 }
32
33
34 void MathFracInset::draw(Painter & pain, int x, int y) const
35 {
36         xo(x);
37         yo(y);
38         int m = x + width() / 2;
39         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
40         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
41         if (!atop_)
42                 pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
43 }
44
45
46 void MathFracInset::write(MathWriteInfo & os) const
47 {
48         if (atop_)
49                 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
50         else
51                 os << "\\frac{" << cell(0) << "}{" << cell(1) << '}';
52 }
53
54
55 void MathFracInset::writeNormal(std::ostream & os) const
56 {
57         if (atop_) 
58                 os << "[atop ";
59         else
60                 os << "[frac ";
61         cell(0).writeNormal(os);
62         os << " ";
63         cell(1).writeNormal(os);
64         os << "] ";
65 }