]> git.lyx.org Git - lyx.git/blob - src/insets/insetnewline.C
fix #832
[lyx.git] / src / insets / insetnewline.C
1 /**
2  * \file insetnewline.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13
14 #include "BufferView.h"
15 #include "paragraph.h"
16 #include "lyxtext.h"
17 #include "insetnewline.h"
18 #include "support/LOstream.h"
19 #include "frontends/Painter.h"
20 #include "frontends/font_metrics.h"
21
22 #include "debug.h"
23
24 using std::ostream;
25 using std::endl;
26
27 InsetNewline::InsetNewline()
28         : Inset()
29 {}
30
31
32 void InsetNewline::read(Buffer const *, LyXLex &)
33 {
34         /* Nothing to read */
35 }
36
37
38 void InsetNewline::write(Buffer const *, ostream & os) const
39 {
40         os << "\n\\newline \n";
41 }
42
43
44 int InsetNewline::ascent(BufferView *, LyXFont const & font) const
45 {
46         return font_metrics::maxAscent(font);
47 }
48
49
50 int InsetNewline::descent(BufferView *, LyXFont const & font) const
51 {
52         return font_metrics::maxDescent(font);
53 }
54
55
56 int InsetNewline::width(BufferView *, LyXFont const & font) const
57 {
58         return font_metrics::width('n', font);
59 }
60
61
62 int InsetNewline::latex(Buffer const *, ostream &, bool, bool) const
63 {
64         lyxerr << "Eek, calling InsetNewline::latex !" << endl;
65         return 0;
66 }
67
68
69 int InsetNewline::ascii(Buffer const *, ostream & os, int) const
70 {
71         os << '\n';
72         return 0;
73 }
74
75
76 int InsetNewline::linuxdoc(Buffer const *, std::ostream &) const
77 {
78         /* FIXME */
79         return 0;
80 }
81
82
83 int InsetNewline::docbook(Buffer const *, std::ostream &, bool) const
84 {
85         /* FIXME */
86         return 0;
87 }
88
89
90 void InsetNewline::draw(BufferView * bv, LyXFont const & font,
91                         int baseline, float & x) const
92 {
93         Painter & pain(bv->painter());
94
95         int const wid = font_metrics::width('n', font);
96         int const asc = font_metrics::maxAscent(font);
97         int const y = baseline;
98
99         // hack, and highly dubious
100         lyx::pos_type pos = parOwner()->getPositionOfInset(this);
101         bool const ltr_pos = (bv->text->bidi_level(pos) % 2 == 0);
102
103         int xp[3];
104         int yp[3];
105
106         yp[0] = int(y - 0.875 * asc * 0.75);
107         yp[1] = int(y - 0.500 * asc * 0.75);
108         yp[2] = int(y - 0.125 * asc * 0.75);
109
110         if (ltr_pos) {
111                 xp[0] = int(x + wid * 0.375);
112                 xp[1] = int(x);
113                 xp[2] = int(x + wid * 0.375);
114         } else {
115                 xp[0] = int(x + wid * 0.625);
116                 xp[1] = int(x + wid);
117                 xp[2] = int(x + wid * 0.625);
118         }
119
120         pain.lines(xp, yp, 3, LColor::eolmarker);
121
122         yp[0] = int(y - 0.500 * asc * 0.75);
123         yp[1] = int(y - 0.500 * asc * 0.75);
124         yp[2] = int(y - asc * 0.75);
125
126         if (ltr_pos) {
127                 xp[0] = int(x);
128                 xp[1] = int(x + wid);
129                 xp[2] = int(x + wid);
130         } else {
131                 xp[0] = int(x + wid);
132                 xp[1] = int(x);
133                 xp[2] = int(x);
134         }
135
136         pain.lines(xp, yp, 3, LColor::eolmarker);
137
138         x += wid;
139 }