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()
36 InsetSpace::InsetSpace(Kind k)
41 InsetSpace::Kind InsetSpace::kind() const
47 void InsetSpace::dimension(BufferView *, LyXFont const & font,
48 Dimension & dim) const
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);
76 void InsetSpace::draw(BufferView * bv, LyXFont const & f,
77 int baseline, float & x) const
79 Painter & pain = bv->painter();
82 float w = width(bv, font);
83 int h = font_metrics::ascent('x', font);
86 xp[0] = int(x); yp[0] = baseline - max(h / 4, 1);
87 if (kind_ == NORMAL) {
88 xp[1] = int(x); yp[1] = baseline;
89 xp[2] = int(x + w); yp[2] = baseline;
91 xp[1] = int(x); yp[1] = baseline + max(h / 4, 1);
92 xp[2] = int(x + w); yp[2] = baseline + max(h / 4, 1);
94 xp[3] = int(x + w); yp[3] = baseline - max(h / 4, 1);
96 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
97 pain.lines(xp, yp, 4, LColor::latex);
99 pain.lines(xp, yp, 4, LColor::special);
104 void InsetSpace::write(Buffer const *, ostream & os) const
118 command = "\\quad{}";
121 command = "\\qquad{}";
124 command = "\\enspace{}";
127 command = "\\enskip{}";
130 command = "\\negthinspace{}";
133 os << "\\InsetSpace " << command << "\n";
137 // This function will not be necessary when lyx3
138 void InsetSpace::read(Buffer const *, LyXLex & lex)
141 string const command = lex.getString();
143 if (command == "\\space")
145 else if (command == "~")
147 else if (command == "\\,")
149 else if (command == "\\quad{}")
151 else if (command == "\\qquad{}")
153 else if (command == "\\enspace{}")
155 else if (command == "\\enskip{}")
157 else if (command == "\\negthinspace{}")
160 lex.printError("InsetSpace: Unknown kind: `$$Token'");
164 int InsetSpace::latex(Buffer const *, ostream & os,
165 LatexRunParams const & runparams) const
169 os << (runparams.free_spacing ? " " : "\\ ");
172 os << (runparams.free_spacing ? ' ' : '~');
175 os << (runparams.free_spacing ? " " : "\\,");
178 os << (runparams.free_spacing ? " " : "\\quad{}");
181 os << (runparams.free_spacing ? " " : "\\qquad{}");
184 os << (runparams.free_spacing ? " " : "\\enspace{}");
187 os << (runparams.free_spacing ? " " : "\\enskip{}");
190 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
197 int InsetSpace::ascii(Buffer const *, ostream & os, int) const
215 int InsetSpace::linuxdoc(Buffer const *, ostream & os) const
236 int InsetSpace::docbook(Buffer const *, ostream & os, bool) const
257 Inset * InsetSpace::clone(Buffer const &) const
259 return new InsetSpace(kind_);
263 // Inset * InsetSpace::clone(Buffer const &, bool) const
265 // return new InsetSpace(kind_);
269 bool InsetSpace::isChar() const
274 bool InsetSpace::isLetter() const
279 bool InsetSpace::isSpace() const
284 bool InsetSpace::isLineSeparator() const