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 "BufferView.h"
22 #include "frontends/Painter.h"
23 #include "frontends/font_metrics.h"
31 InsetSpace::InsetSpace(Kind k)
36 InsetSpace::Kind InsetSpace::kind() const
42 void InsetSpace::dimension(BufferView *, LyXFont const & font,
43 Dimension & dim) const
45 dim.a = font_metrics::maxAscent(font);
46 dim.d = font_metrics::maxDescent(font);
51 dim.w = font_metrics::width("x", font) / 3;
55 dim.w = font_metrics::width("x", font);
71 void InsetSpace::draw(BufferView * bv, LyXFont const & f,
72 int baseline, float & x) const
74 Painter & pain = bv->painter();
77 float w = width(bv, font);
78 int h = font_metrics::ascent('x', font);
81 xp[0] = int(x); yp[0] = baseline - max(h / 4, 1);
82 if (kind_ == NORMAL) {
83 xp[1] = int(x); yp[1] = baseline;
84 xp[2] = int(x + w); yp[2] = baseline;
86 xp[1] = int(x); yp[1] = baseline + max(h / 4, 1);
87 xp[2] = int(x + w); yp[2] = baseline + max(h / 4, 1);
89 xp[3] = int(x + w); yp[3] = baseline - max(h / 4, 1);
91 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
92 pain.lines(xp, yp, 4, LColor::latex);
94 pain.lines(xp, yp, 4, LColor::special);
99 void InsetSpace::write(Buffer const *, ostream & os) const
113 command = "\\quad{}";
116 command = "\\qquad{}";
119 command = "\\enspace{}";
122 command = "\\enskip{}";
125 command = "\\negthinspace{}";
128 os << "\\InsetSpace " << command << "\n";
132 // This function will not be necessary when lyx3
133 void InsetSpace::read(Buffer const *, LyXLex & lex)
136 string const command = lex.getString();
138 if (command == "\\space")
140 else if (command == "~")
142 else if (command == "\\,")
144 else if (command == "\\quad{}")
146 else if (command == "\\qquad{}")
148 else if (command == "\\enspace{}")
150 else if (command == "\\enskip{}")
152 else if (command == "\\negthinspace{}")
155 lex.printError("InsetSpace: Unknown kind: `$$Token'");
159 int InsetSpace::latex(Buffer const *, ostream & os, bool /*fragile*/,
160 bool free_space) const
164 os << (free_space ? " " : "\\ ");
167 os << (free_space ? ' ' : '~');
170 os << (free_space ? " " : "\\,");
173 os << (free_space ? " " : "\\quad{}");
176 os << (free_space ? " " : "\\qquad{}");
179 os << (free_space ? " " : "\\enspace{}");
182 os << (free_space ? " " : "\\enskip{}");
185 os << (free_space ? " " : "\\negthinspace{}");
192 int InsetSpace::ascii(Buffer const *, ostream & os, int) const
210 int InsetSpace::linuxdoc(Buffer const *, ostream & os) const
231 int InsetSpace::docbook(Buffer const *, ostream & os, bool) const
252 Inset * InsetSpace::clone(Buffer const &, bool) const
254 return new InsetSpace(kind_);
258 bool InsetSpace::isChar() const
263 bool InsetSpace::isLetter() const
268 bool InsetSpace::isSpace() const
273 bool InsetSpace::isLineSeparator() const