]> git.lyx.org Git - lyx.git/blob - src/insets/InsetNewline.cpp
Fix text frame drawing.
[lyx.git] / src / insets / InsetNewline.cpp
1 /**
2  * \file InsetNewline.cpp
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 "debug.h"
16 #include "MetricsInfo.h"
17 #include "OutputParams.h"
18
19 #include "frontends/FontMetrics.h"
20 #include "frontends/Painter.h"
21
22
23 namespace lyx {
24
25 using std::endl;
26 using std::ostream;
27
28
29 void InsetNewline::read(Buffer const &, Lexer &)
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 bool InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
42 {
43         frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
44         dim.asc = fm.maxAscent();
45         dim.des = fm.maxDescent();
46         dim.wid = fm.width('n');
47         bool const changed = dim_ != dim;
48         dim_ = dim;
49         return changed;
50 }
51
52
53 int InsetNewline::latex(Buffer const &, odocstream &,
54                         OutputParams const &) const
55 {
56         lyxerr << "Eek, calling InsetNewline::latex !" << endl;
57         return 0;
58 }
59
60
61 int InsetNewline::plaintext(Buffer const &, odocstream & os,
62                             OutputParams const &) const
63 {
64         os << '\n';
65         return PLAINTEXT_NEWLINE;
66 }
67
68
69 int InsetNewline::docbook(Buffer const &, odocstream & os,
70                           OutputParams const &) const
71 {
72         os << '\n';
73         return 0;
74 }
75
76
77 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
78 {
79         frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
80         int const wid = fm.width('n');
81         int const asc = fm.maxAscent();
82
83         int xp[3];
84         int yp[3];
85
86         yp[0] = int(y - 0.875 * asc * 0.75);
87         yp[1] = int(y - 0.500 * asc * 0.75);
88         yp[2] = int(y - 0.125 * asc * 0.75);
89
90         if (pi.ltr_pos) {
91                 xp[0] = int(x + wid * 0.375);
92                 xp[1] = int(x);
93                 xp[2] = int(x + wid * 0.375);
94         } else {
95                 xp[0] = int(x + wid * 0.625);
96                 xp[1] = int(x + wid);
97                 xp[2] = int(x + wid * 0.625);
98         }
99
100         pi.pain.lines(xp, yp, 3, Color::eolmarker);
101
102         yp[0] = int(y - 0.500 * asc * 0.75);
103         yp[1] = int(y - 0.500 * asc * 0.75);
104         yp[2] = int(y - asc * 0.75);
105
106         if (pi.ltr_pos) {
107                 xp[0] = int(x);
108                 xp[1] = int(x + wid);
109                 xp[2] = int(x + wid);
110         } else {
111                 xp[0] = int(x + wid);
112                 xp[1] = int(x);
113                 xp[2] = int(x);
114         }
115
116         pi.pain.lines(xp, yp, 3, Color::eolmarker);
117 }
118
119
120 bool InsetNewline::isSpace() const
121 {
122         return true;
123 }
124
125
126 } // namespace lyx