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