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);
78 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
80 int const w = width();
81 int const h = font_metrics::ascent('x', pi.base.font);
85 yp[0] = y - max(h / 4, 1);
86 if (kind_ == NORMAL) {
88 xp[2] = x + w; yp[2] = y;
90 xp[1] = x; yp[1] = y + max(h / 4, 1);
91 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
94 yp[3] = y - max(h / 4, 1);
96 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
97 pi.pain.lines(xp, yp, 4, LColor::latex);
99 pi.pain.lines(xp, yp, 4, LColor::special);
103 void InsetSpace::write(Buffer const *, ostream & os) const
117 command = "\\quad{}";
120 command = "\\qquad{}";
123 command = "\\enspace{}";
126 command = "\\enskip{}";
129 command = "\\negthinspace{}";
132 os << "\\InsetSpace " << command << "\n";
136 // This function will not be necessary when lyx3
137 void InsetSpace::read(Buffer const *, LyXLex & lex)
140 string const command = lex.getString();
142 if (command == "\\space")
144 else if (command == "~")
146 else if (command == "\\,")
148 else if (command == "\\quad{}")
150 else if (command == "\\qquad{}")
152 else if (command == "\\enspace{}")
154 else if (command == "\\enskip{}")
156 else if (command == "\\negthinspace{}")
159 lex.printError("InsetSpace: Unknown kind: `$$Token'");
163 int InsetSpace::latex(Buffer const *, ostream & os,
164 LatexRunParams const & runparams) const
168 os << (runparams.free_spacing ? " " : "\\ ");
171 os << (runparams.free_spacing ? ' ' : '~');
174 os << (runparams.free_spacing ? " " : "\\,");
177 os << (runparams.free_spacing ? " " : "\\quad{}");
180 os << (runparams.free_spacing ? " " : "\\qquad{}");
183 os << (runparams.free_spacing ? " " : "\\enspace{}");
186 os << (runparams.free_spacing ? " " : "\\enskip{}");
189 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
196 int InsetSpace::ascii(Buffer const *, ostream & os, int) const
214 int InsetSpace::linuxdoc(Buffer const *, ostream & os) const
234 int InsetSpace::docbook(Buffer const *, ostream & os, bool) const
254 InsetBase * InsetSpace::clone() const
256 return new InsetSpace(kind_);
260 bool InsetSpace::isChar() const
265 bool InsetSpace::isLetter() const
270 bool InsetSpace::isSpace() const
275 bool InsetSpace::isLineSeparator() const