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 Jürgen Spitzmüller
11 * Full author contact details are available in file CREDITS.
16 #include "InsetSpace.h"
18 #include "support/debug.h"
19 #include "Dimension.h"
21 #include "MetricsInfo.h"
22 #include "OutputParams.h"
24 #include "frontends/FontMetrics.h"
25 #include "frontends/Painter.h"
27 #include "support/docstream.h"
34 InsetSpace::InsetSpace()
38 InsetSpace::InsetSpace(Kind k)
43 InsetSpace::Kind InsetSpace::kind() const
49 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
51 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
52 dim.asc = fm.maxAscent();
53 dim.des = fm.maxDescent();
58 dim.wid = fm.width(char_type('M')) / 6;
62 dim.wid = fm.width(char_type(' '));
65 dim.wid = fm.width(char_type('M'));
68 dim.wid = 2 * fm.width(char_type('M'));
72 dim.wid = int(0.5 * fm.width(char_type('M')));
75 // Cache the inset dimension.
80 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
82 Dimension const dim = dimension(*pi.base.bv);
83 int const w = dim.wid;
84 int const h = theFontMetrics(pi.base.font)
89 yp[0] = y - max(h / 4, 1);
90 if (kind_ == NORMAL || kind_ == PROTECTED) {
92 xp[2] = x + w; yp[2] = y;
94 xp[1] = x; yp[1] = y + max(h / 4, 1);
95 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
98 yp[3] = y - max(h / 4, 1);
100 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
101 pi.pain.lines(xp, yp, 4, Color_latex);
103 pi.pain.lines(xp, yp, 4, Color_special);
107 void InsetSpace::write(Buffer const &, ostream & os) const
112 command = "\\space{}";
118 command = "\\thinspace{}";
121 command = "\\quad{}";
124 command = "\\qquad{}";
127 command = "\\enspace{}";
130 command = "\\enskip{}";
133 command = "\\negthinspace{}";
136 os << "\\InsetSpace " << command << "\n";
140 void InsetSpace::read(Buffer const &, Lexer & lex)
143 string const command = lex.getString();
145 if (command == "\\space{}")
147 else if (command == "~")
149 else if (command == "\\thinspace{}")
151 else if (command == "\\quad{}")
153 else if (command == "\\qquad{}")
155 else if (command == "\\enspace{}")
157 else if (command == "\\enskip{}")
159 else if (command == "\\negthinspace{}")
162 lex.printError("InsetSpace: Unknown kind: `$$Token'");
166 int InsetSpace::latex(Buffer const &, odocstream & os,
167 OutputParams const & runparams) const
171 os << (runparams.free_spacing ? " " : "\\ ");
174 os << (runparams.free_spacing ? ' ' : '~');
177 os << (runparams.free_spacing ? " " : "\\,");
180 os << (runparams.free_spacing ? " " : "\\quad{}");
183 os << (runparams.free_spacing ? " " : "\\qquad{}");
186 os << (runparams.free_spacing ? " " : "\\enspace{}");
189 os << (runparams.free_spacing ? " " : "\\enskip{}");
192 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
199 int InsetSpace::plaintext(Buffer const &, odocstream & os,
200 OutputParams const &) const
207 int InsetSpace::docbook(Buffer const &, odocstream & os,
208 OutputParams const &) const
228 int InsetSpace::textString(Buffer const & buf, odocstream & os,
229 OutputParams const & op) const
231 return plaintext(buf, os, op);
235 Inset * InsetSpace::clone() const
237 return new InsetSpace(kind_);
241 bool InsetSpace::isChar() const
246 bool InsetSpace::isLetter() const
251 bool InsetSpace::isSpace() const