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 Juergen Spitzmueller
11 * Full author contact details are available in file CREDITS
16 #include "insetspace.h"
19 #include "dimension.h"
20 #include "LaTeXFeatures.h"
21 #include "latexrunparams.h"
22 #include "BufferView.h"
23 #include "frontends/Painter.h"
24 #include "frontends/font_metrics.h"
27 #include "metricsinfo.h"
33 InsetSpace::InsetSpace()
37 InsetSpace::InsetSpace(Kind k)
42 InsetSpace::Kind InsetSpace::kind() const
48 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
50 LyXFont & font = mi.base.font;
51 dim.asc = font_metrics::maxAscent(font);
52 dim.des = font_metrics::maxDescent(font);
57 dim.wid = font_metrics::width("x", font) / 3;
61 dim.wid = font_metrics::width("x", font);
77 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
79 int const w = width(pi.base.bv, pi.base.font);
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 Inset * InsetSpace::clone() const
255 return new InsetSpace(kind_);
259 bool InsetSpace::isChar() const
264 bool InsetSpace::isLetter() const
269 bool InsetSpace::isSpace() const
274 bool InsetSpace::isLineSeparator() const