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