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