]> git.lyx.org Git - lyx.git/blob - src/insets/insetnewline.C
the ascent/descent/width -> dimensions() change
[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 #include "insetnewline.h"
14
15 #include "BufferView.h"
16 #include "debug.h"
17 #include "dimension.h"
18 #include "paragraph.h"
19 #include "lyxtext.h"
20 #include "support/LOstream.h"
21 #include "frontends/Painter.h"
22 #include "frontends/font_metrics.h"
23
24 using std::ostream;
25 using std::endl;
26
27
28 void InsetNewline::read(Buffer const *, LyXLex &)
29 {
30         /* Nothing to read */
31 }
32
33
34 void InsetNewline::write(Buffer const *, ostream & os) const
35 {
36         os << "\n\\newline \n";
37 }
38
39
40 void InsetNewline::dimension(BufferView *, LyXFont const & font,
41         Dimension & dim) const
42 {
43         dim.a = font_metrics::maxAscent(font);
44         dim.d = font_metrics::maxDescent(font);
45         dim.w = font_metrics::width('n', font);
46 }
47
48
49 int InsetNewline::latex(Buffer const *, ostream &, bool, bool) const
50 {
51         lyxerr << "Eek, calling InsetNewline::latex !" << endl;
52         return 0;
53 }
54
55
56 int InsetNewline::ascii(Buffer const *, ostream & os, int) const
57 {
58         os << '\n';
59         return 0;
60 }
61
62
63 int InsetNewline::linuxdoc(Buffer const *, std::ostream &) const
64 {
65         /* FIXME */
66         return 0;
67 }
68
69
70 int InsetNewline::docbook(Buffer const *, std::ostream &, bool) const
71 {
72         /* FIXME */
73         return 0;
74 }
75
76
77 void InsetNewline::draw(BufferView * bv, LyXFont const & font,
78                         int baseline, float & x) const
79 {
80         Painter & pain(bv->painter());
81
82         int const wid = font_metrics::width('n', font);
83         int const asc = font_metrics::maxAscent(font);
84         int const y = baseline;
85
86         // hack, and highly dubious
87         lyx::pos_type pos = parOwner()->getPositionOfInset(this);
88         bool const ltr_pos = (bv->text->bidi_level(pos) % 2 == 0);
89
90         int xp[3];
91         int yp[3];
92
93         yp[0] = int(y - 0.875 * asc * 0.75);
94         yp[1] = int(y - 0.500 * asc * 0.75);
95         yp[2] = int(y - 0.125 * asc * 0.75);
96
97         if (ltr_pos) {
98                 xp[0] = int(x + wid * 0.375);
99                 xp[1] = int(x);
100                 xp[2] = int(x + wid * 0.375);
101         } else {
102                 xp[0] = int(x + wid * 0.625);
103                 xp[1] = int(x + wid);
104                 xp[2] = int(x + wid * 0.625);
105         }
106
107         pain.lines(xp, yp, 3, LColor::eolmarker);
108
109         yp[0] = int(y - 0.500 * asc * 0.75);
110         yp[1] = int(y - 0.500 * asc * 0.75);
111         yp[2] = int(y - asc * 0.75);
112
113         if (ltr_pos) {
114                 xp[0] = int(x);
115                 xp[1] = int(x + wid);
116                 xp[2] = int(x + wid);
117         } else {
118                 xp[0] = int(x + wid);
119                 xp[1] = int(x);
120                 xp[2] = int(x);
121         }
122
123         pain.lines(xp, yp, 3, LColor::eolmarker);
124
125         x += wid;
126 }