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