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"
22 #include "metricsinfo.h"
24 #include "frontends/font_metrics.h"
25 #include "frontends/Painter.h"
32 InsetSpace::InsetSpace()
36 InsetSpace::InsetSpace(Kind k)
41 InsetSpace::Kind InsetSpace::kind() const
47 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
49 LyXFont & font = mi.base.font;
50 dim.asc = font_metrics::maxAscent(font);
51 dim.des = font_metrics::maxDescent(font);
56 dim.wid = font_metrics::width("x", font) / 3;
60 dim.wid = font_metrics::width("x", font);
77 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
79 int const w = width();
80 int const h = font_metrics::ascent('x', pi.base.font);
84 yp[0] = y - max(h / 4, 1);
85 if (kind_ == NORMAL) {
87 xp[2] = x + w; yp[2] = y;
89 xp[1] = x; yp[1] = y + max(h / 4, 1);
90 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
93 yp[3] = y - max(h / 4, 1);
95 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
96 pi.pain.lines(xp, yp, 4, LColor::latex);
98 pi.pain.lines(xp, yp, 4, LColor::special);
102 void InsetSpace::write(Buffer const &, ostream & os) const
116 command = "\\quad{}";
119 command = "\\qquad{}";
122 command = "\\enspace{}";
125 command = "\\enskip{}";
128 command = "\\negthinspace{}";
131 os << "\\InsetSpace " << command << "\n";
135 // This function will not be necessary when lyx3
136 void InsetSpace::read(Buffer const &, LyXLex & lex)
139 string const command = lex.getString();
141 if (command == "\\space")
143 else if (command == "~")
145 else if (command == "\\,")
147 else if (command == "\\quad{}")
149 else if (command == "\\qquad{}")
151 else if (command == "\\enspace{}")
153 else if (command == "\\enskip{}")
155 else if (command == "\\negthinspace{}")
158 lex.printError("InsetSpace: Unknown kind: `$$Token'");
162 int InsetSpace::latex(Buffer const &, ostream & os,
163 LatexRunParams const & runparams) const
167 os << (runparams.free_spacing ? " " : "\\ ");
170 os << (runparams.free_spacing ? ' ' : '~');
173 os << (runparams.free_spacing ? " " : "\\,");
176 os << (runparams.free_spacing ? " " : "\\quad{}");
179 os << (runparams.free_spacing ? " " : "\\qquad{}");
182 os << (runparams.free_spacing ? " " : "\\enspace{}");
185 os << (runparams.free_spacing ? " " : "\\enskip{}");
188 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
195 int InsetSpace::ascii(Buffer const &, ostream & os, int) const
213 int InsetSpace::linuxdoc(Buffer const &, ostream & os) const
233 int InsetSpace::docbook(Buffer const &, ostream & os, bool) const
253 auto_ptr<InsetBase> InsetSpace::clone() const
255 return auto_ptr<InsetBase>(new InsetSpace(kind_));
259 bool InsetSpace::isChar() const
264 bool InsetSpace::isLetter() const
269 bool InsetSpace::isSpace() const
274 bool InsetSpace::isLineSeparator() const