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"
32 InsetSpace::InsetSpace(Kind k)
37 InsetSpace::Kind InsetSpace::kind() const
43 void InsetSpace::dimension(BufferView *, LyXFont const & font,
44 Dimension & dim) const
46 dim.a = font_metrics::maxAscent(font);
47 dim.d = font_metrics::maxDescent(font);
52 dim.w = font_metrics::width("x", font) / 3;
56 dim.w = font_metrics::width("x", font);
72 void InsetSpace::draw(BufferView * bv, LyXFont const & f,
73 int baseline, float & x) const
75 Painter & pain = bv->painter();
78 float w = width(bv, font);
79 int h = font_metrics::ascent('x', font);
82 xp[0] = int(x); yp[0] = baseline - max(h / 4, 1);
83 if (kind_ == NORMAL) {
84 xp[1] = int(x); yp[1] = baseline;
85 xp[2] = int(x + w); yp[2] = baseline;
87 xp[1] = int(x); yp[1] = baseline + max(h / 4, 1);
88 xp[2] = int(x + w); yp[2] = baseline + max(h / 4, 1);
90 xp[3] = int(x + w); yp[3] = baseline - max(h / 4, 1);
92 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
93 pain.lines(xp, yp, 4, LColor::latex);
95 pain.lines(xp, yp, 4, LColor::special);
100 void InsetSpace::write(Buffer const *, ostream & os) const
114 command = "\\quad{}";
117 command = "\\qquad{}";
120 command = "\\enspace{}";
123 command = "\\enskip{}";
126 command = "\\negthinspace{}";
129 os << "\\InsetSpace " << command << "\n";
133 // This function will not be necessary when lyx3
134 void InsetSpace::read(Buffer const *, LyXLex & lex)
137 string const command = lex.getString();
139 if (command == "\\space")
141 else if (command == "~")
143 else if (command == "\\,")
145 else if (command == "\\quad{}")
147 else if (command == "\\qquad{}")
149 else if (command == "\\enspace{}")
151 else if (command == "\\enskip{}")
153 else if (command == "\\negthinspace{}")
156 lex.printError("InsetSpace: Unknown kind: `$$Token'");
160 int InsetSpace::latex(Buffer const *, ostream & os,
161 LatexRunParams const & runparams) const
165 os << (runparams.free_spacing ? " " : "\\ ");
168 os << (runparams.free_spacing ? ' ' : '~');
171 os << (runparams.free_spacing ? " " : "\\,");
174 os << (runparams.free_spacing ? " " : "\\quad{}");
177 os << (runparams.free_spacing ? " " : "\\qquad{}");
180 os << (runparams.free_spacing ? " " : "\\enspace{}");
183 os << (runparams.free_spacing ? " " : "\\enskip{}");
186 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
193 int InsetSpace::ascii(Buffer const *, ostream & os, int) const
211 int InsetSpace::linuxdoc(Buffer const *, ostream & os) const
232 int InsetSpace::docbook(Buffer const *, ostream & os, bool) const
253 Inset * InsetSpace::clone(Buffer const &, bool) 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