]> git.lyx.org Git - features.git/blob - src/insets/InsetNewline.cpp
support for \linebreak:
[features.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 "Dimension.h"
17 #include "MetricsInfo.h"
18 #include "OutputParams.h"
19
20 #include "frontends/FontMetrics.h"
21 #include "frontends/Painter.h"
22
23 #include "support/docstring.h"
24
25
26 namespace lyx {
27
28 using std::endl;
29 using std::ostream;
30
31
32 void InsetNewline::read(Buffer const &, Lexer &)
33 {
34         /* Nothing to read */
35 }
36
37
38 void InsetNewline::write(Buffer const &, ostream & os) const
39 {
40         os << "\n" << getLyXName() << '\n';
41 }
42
43
44 void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
45 {
46         frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
47         dim.asc = fm.maxAscent();
48         dim.des = fm.maxDescent();
49         dim.wid = fm.width('n');
50 }
51
52
53 int InsetNewline::latex(Buffer const &, odocstream & os,
54                         OutputParams const &) const
55 {
56         os << from_ascii(getCmdName()) << '\n';
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         FontInfo font;
80         font.setColor(ColorName());
81
82         frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
83         int const wid = fm.width('n');
84         int const asc = fm.maxAscent();
85
86         int xp[3];
87         int yp[3];
88
89         yp[0] = int(y - 0.875 * asc * 0.75);
90         yp[1] = int(y - 0.500 * asc * 0.75);
91         yp[2] = int(y - 0.125 * asc * 0.75);
92
93         if (pi.ltr_pos) {
94                 xp[0] = int(x + wid * 0.375);
95                 xp[1] = int(x);
96                 xp[2] = int(x + wid * 0.375);
97         } else {
98                 xp[0] = int(x + wid * 0.625);
99                 xp[1] = int(x + wid);
100                 xp[2] = int(x + wid * 0.625);
101         }
102
103         pi.pain.lines(xp, yp, 3, ColorName());
104
105         yp[0] = int(y - 0.500 * asc * 0.75);
106         yp[1] = int(y - 0.500 * asc * 0.75);
107         yp[2] = int(y - asc * 0.75);
108
109         if (pi.ltr_pos) {
110                 xp[0] = int(x);
111                 xp[1] = int(x + wid);
112                 xp[2] = int(x + wid);
113         } else {
114                 xp[0] = int(x + wid);
115                 xp[1] = int(x);
116                 xp[2] = int(x);
117         }
118
119         pi.pain.lines(xp, yp, 3, ColorName());
120
121         // add label text behind the newline marker to divide from \newline
122         int w = 0;
123         int a = 0;
124         int d = 0;
125         theFontMetrics(font).rectText(insetLabel(), w, a, d);
126         
127         int const text_start = int(x + 2 * wid);
128                         
129         pi.pain.rectText(text_start, yp[0] + d, insetLabel(), font,
130                 Color_none, Color_none);
131 }
132
133
134 bool InsetNewline::isSpace() const
135 {
136         return true;
137 }
138
139
140 } // namespace lyx