]> git.lyx.org Git - lyx.git/blob - src/insets/InsetNewline.cpp
Fix GRAPHICS_EDIT of InsetGraphics
[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 "Dimension.h"
16 #include "MetricsInfo.h"
17 #include "OutputParams.h"
18
19 #include "frontends/FontMetrics.h"
20 #include "frontends/Painter.h"
21
22 #include "support/debug.h"
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(Lexer &)
32 {
33         /* Nothing to read */
34 }
35
36
37 void InsetNewline::write(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(odocstream & os, OutputParams const &) const
53 {
54         os << from_ascii(getCmdName()) << '\n';
55         return 0;
56 }
57
58
59 int InsetNewline::plaintext(odocstream & os, OutputParams const &) const
60 {
61         os << '\n';
62         return PLAINTEXT_NEWLINE;
63 }
64
65
66 int InsetNewline::docbook(odocstream & os, OutputParams const &) const
67 {
68         os << '\n';
69         return 0;
70 }
71
72
73 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
74 {
75         FontInfo font;
76         font.setColor(ColorName());
77
78         frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
79         int const wid = fm.width('n');
80         int const asc = fm.maxAscent();
81
82         int xp[3];
83         int yp[3];
84
85         yp[0] = int(y - 0.875 * asc * 0.75);
86         yp[1] = int(y - 0.500 * asc * 0.75);
87         yp[2] = int(y - 0.125 * asc * 0.75);
88
89         if (pi.ltr_pos) {
90                 xp[0] = int(x + wid * 0.375);
91                 xp[1] = int(x);
92                 xp[2] = int(x + wid * 0.375);
93         } else {
94                 xp[0] = int(x + wid * 0.625);
95                 xp[1] = int(x + wid);
96                 xp[2] = int(x + wid * 0.625);
97         }
98
99         pi.pain.lines(xp, yp, 3, ColorName());
100
101         yp[0] = int(y - 0.500 * asc * 0.75);
102         yp[1] = int(y - 0.500 * asc * 0.75);
103         yp[2] = int(y - asc * 0.75);
104
105         if (pi.ltr_pos) {
106                 xp[0] = int(x);
107                 xp[1] = int(x + wid);
108                 xp[2] = int(x + wid);
109         } else {
110                 xp[0] = int(x + wid);
111                 xp[1] = int(x);
112                 xp[2] = int(x);
113         }
114
115         pi.pain.lines(xp, yp, 3, ColorName());
116
117         // add label text behind the newline marker to divide from \newline
118         int w = 0;
119         int a = 0;
120         int d = 0;
121         theFontMetrics(font).rectText(insetLabel(), w, a, d);
122         
123         int const text_start = int(x + 2 * wid);
124                         
125         pi.pain.rectText(text_start, yp[0] + d, insetLabel(), font,
126                 Color_none, Color_none);
127 }
128
129
130 bool InsetNewline::isSpace() const
131 {
132         return true;
133 }
134
135
136 } // namespace lyx