2 * \file InsetNewline.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetNewline.h"
15 #include "Dimension.h"
16 #include "MetricsInfo.h"
17 #include "OutputParams.h"
19 #include "frontends/FontMetrics.h"
20 #include "frontends/Painter.h"
22 #include "support/debug.h"
23 #include "support/docstring.h"
24 #include "support/docstream.h"
31 void InsetNewline::read(Buffer const &, Lexer &)
37 void InsetNewline::write(Buffer const &, ostream & os) const
39 os << "\n" << getLyXName() << '\n';
43 void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
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');
52 int InsetNewline::latex(Buffer const &, odocstream & os,
53 OutputParams const &) const
55 os << from_ascii(getCmdName()) << '\n';
60 int InsetNewline::plaintext(Buffer const &, odocstream & os,
61 OutputParams const &) const
64 return PLAINTEXT_NEWLINE;
68 int InsetNewline::docbook(Buffer const &, odocstream & os,
69 OutputParams const &) const
76 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
79 font.setColor(ColorName());
81 frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
82 int const wid = fm.width('n');
83 int const asc = fm.maxAscent();
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);
93 xp[0] = int(x + wid * 0.375);
95 xp[2] = int(x + wid * 0.375);
97 xp[0] = int(x + wid * 0.625);
99 xp[2] = int(x + wid * 0.625);
102 pi.pain.lines(xp, yp, 3, ColorName());
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);
110 xp[1] = int(x + wid);
111 xp[2] = int(x + wid);
113 xp[0] = int(x + wid);
118 pi.pain.lines(xp, yp, 3, ColorName());
120 // add label text behind the newline marker to divide from \newline
124 theFontMetrics(font).rectText(insetLabel(), w, a, d);
126 int const text_start = int(x + 2 * wid);
128 pi.pain.rectText(text_start, yp[0] + d, insetLabel(), font,
129 Color_none, Color_none);
133 bool InsetNewline::isSpace() const