]> git.lyx.org Git - lyx.git/blob - src/insets/insetnewline.C
Clean up InsetGraphics::Cache and rename as GraphicsInset.
[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 }
48
49
50 int InsetNewline::latex(Buffer const *, ostream &,
51                         LatexRunParams const &) const
52 {
53         lyxerr << "Eek, calling InsetNewline::latex !" << endl;
54         return 0;
55 }
56
57
58 int InsetNewline::ascii(Buffer const *, ostream & os, int) const
59 {
60         os << '\n';
61         return 0;
62 }
63
64
65 int InsetNewline::linuxdoc(Buffer const *, std::ostream &) const
66 {
67         /* FIXME */
68         return 0;
69 }
70
71
72 int InsetNewline::docbook(Buffer const *, std::ostream &, bool) const
73 {
74         /* FIXME */
75         return 0;
76 }
77
78
79 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
80 {
81         int const wid = font_metrics::width('n', pi.base.font);
82         int const asc = font_metrics::maxAscent(pi.base.font);
83
84         // hack, and highly dubious
85         lyx::pos_type pos = parOwner()->getPositionOfInset(this);
86         bool const ltr_pos = (pi.base.bv->text->bidi_level(pos) % 2 == 0);
87
88         int xp[3];
89         int yp[3];
90
91         yp[0] = int(y - 0.875 * asc * 0.75);
92         yp[1] = int(y - 0.500 * asc * 0.75);
93         yp[2] = int(y - 0.125 * asc * 0.75);
94
95         if (ltr_pos) {
96                 xp[0] = int(x + wid * 0.375);
97                 xp[1] = int(x);
98                 xp[2] = int(x + wid * 0.375);
99         } else {
100                 xp[0] = int(x + wid * 0.625);
101                 xp[1] = int(x + wid);
102                 xp[2] = int(x + wid * 0.625);
103         }
104
105         pi.pain.lines(xp, yp, 3, LColor::eolmarker);
106
107         yp[0] = int(y - 0.500 * asc * 0.75);
108         yp[1] = int(y - 0.500 * asc * 0.75);
109         yp[2] = int(y - asc * 0.75);
110
111         if (ltr_pos) {
112                 xp[0] = int(x);
113                 xp[1] = int(x + wid);
114                 xp[2] = int(x + wid);
115         } else {
116                 xp[0] = int(x + wid);
117                 xp[1] = int(x);
118                 xp[2] = int(x);
119         }
120
121         pi.pain.lines(xp, yp, 3, LColor::eolmarker);
122 }