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