3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup Nielsen
7 * \author Jean-Marc Lasgouttes
8 * \author Lars Gullik Bjønnes
9 * \author Jürgen Spitzmüller
11 * Full author contact details are available in file CREDITS.
16 #include "insetspace.h"
19 #include "latexrunparams.h"
21 #include "metricsinfo.h"
23 #include "frontends/font_metrics.h"
24 #include "frontends/Painter.h"
31 InsetSpace::InsetSpace()
35 InsetSpace::InsetSpace(Kind k)
40 InsetSpace::Kind InsetSpace::kind() const
46 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
48 LyXFont & font = mi.base.font;
49 dim.asc = font_metrics::maxAscent(font);
50 dim.des = font_metrics::maxDescent(font);
55 dim.wid = font_metrics::width("x", font) / 3;
59 dim.wid = font_metrics::width("x", font);
76 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
78 int const w = width();
79 int const h = font_metrics::ascent('x', pi.base.font);
83 yp[0] = y - max(h / 4, 1);
84 if (kind_ == NORMAL) {
86 xp[2] = x + w; yp[2] = y;
88 xp[1] = x; yp[1] = y + max(h / 4, 1);
89 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
92 yp[3] = y - max(h / 4, 1);
94 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
95 pi.pain.lines(xp, yp, 4, LColor::latex);
97 pi.pain.lines(xp, yp, 4, LColor::special);
101 void InsetSpace::write(Buffer const &, ostream & os) const
115 command = "\\quad{}";
118 command = "\\qquad{}";
121 command = "\\enspace{}";
124 command = "\\enskip{}";
127 command = "\\negthinspace{}";
130 os << "\\InsetSpace " << command << "\n";
134 // This function will not be necessary when lyx3
135 void InsetSpace::read(Buffer const &, LyXLex & lex)
138 string const command = lex.getString();
140 if (command == "\\space")
142 else if (command == "~")
144 else if (command == "\\,")
146 else if (command == "\\quad{}")
148 else if (command == "\\qquad{}")
150 else if (command == "\\enspace{}")
152 else if (command == "\\enskip{}")
154 else if (command == "\\negthinspace{}")
157 lex.printError("InsetSpace: Unknown kind: `$$Token'");
161 int InsetSpace::latex(Buffer const &, ostream & os,
162 LatexRunParams const & runparams) const
166 os << (runparams.free_spacing ? " " : "\\ ");
169 os << (runparams.free_spacing ? ' ' : '~');
172 os << (runparams.free_spacing ? " " : "\\,");
175 os << (runparams.free_spacing ? " " : "\\quad{}");
178 os << (runparams.free_spacing ? " " : "\\qquad{}");
181 os << (runparams.free_spacing ? " " : "\\enspace{}");
184 os << (runparams.free_spacing ? " " : "\\enskip{}");
187 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
194 int InsetSpace::ascii(Buffer const &, ostream & os, int) const
212 int InsetSpace::linuxdoc(Buffer const &, ostream & os) const
232 int InsetSpace::docbook(Buffer const &, ostream & os, bool) const
252 auto_ptr<InsetBase> InsetSpace::clone() const
254 return auto_ptr<InsetBase>(new InsetSpace(kind_));
258 bool InsetSpace::isChar() const
263 bool InsetSpace::isLetter() const
268 bool InsetSpace::isSpace() const
273 bool InsetSpace::isLineSeparator() const