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"
21 #include "MetricsInfo.h"
22 #include "OutputParams.h"
24 #include "frontends/FontMetrics.h"
25 #include "frontends/Painter.h"
35 InsetSpace::InsetSpace()
39 InsetSpace::InsetSpace(Kind k)
44 InsetSpace::Kind InsetSpace::kind() const
50 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
52 frontend::FontMetrics const & fm =
53 theFontMetrics(mi.base.font);
54 dim.asc = fm.maxAscent();
55 dim.des = fm.maxDescent();
60 dim.wid = fm.width(char_type('x')) / 3;
64 dim.wid = fm.width(char_type('x'));
77 // Cache the inset dimension.
82 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
84 Dimension const dim = dimension(*pi.base.bv);
85 int const w = dim.wid;
86 int const h = theFontMetrics(pi.base.font)
91 yp[0] = y - max(h / 4, 1);
92 if (kind_ == NORMAL) {
94 xp[2] = x + w; yp[2] = y;
96 xp[1] = x; yp[1] = y + max(h / 4, 1);
97 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
100 yp[3] = y - max(h / 4, 1);
102 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
103 pi.pain.lines(xp, yp, 4, Color::latex);
105 pi.pain.lines(xp, yp, 4, Color::special);
109 void InsetSpace::write(Buffer const &, ostream & os) const
114 command = "\\space{}";
120 command = "\\thinspace{}";
123 command = "\\quad{}";
126 command = "\\qquad{}";
129 command = "\\enspace{}";
132 command = "\\enskip{}";
135 command = "\\negthinspace{}";
138 os << "\\InsetSpace " << command << "\n";
142 void InsetSpace::read(Buffer const &, Lexer & lex)
145 string const command = lex.getString();
147 if (command == "\\space{}")
149 else if (command == "~")
151 else if (command == "\\thinspace{}")
153 else if (command == "\\quad{}")
155 else if (command == "\\qquad{}")
157 else if (command == "\\enspace{}")
159 else if (command == "\\enskip{}")
161 else if (command == "\\negthinspace{}")
164 lex.printError("InsetSpace: Unknown kind: `$$Token'");
168 int InsetSpace::latex(Buffer const &, odocstream & os,
169 OutputParams const & runparams) const
173 os << (runparams.free_spacing ? " " : "\\ ");
176 os << (runparams.free_spacing ? ' ' : '~');
179 os << (runparams.free_spacing ? " " : "\\,");
182 os << (runparams.free_spacing ? " " : "\\quad{}");
185 os << (runparams.free_spacing ? " " : "\\qquad{}");
188 os << (runparams.free_spacing ? " " : "\\enspace{}");
191 os << (runparams.free_spacing ? " " : "\\enskip{}");
194 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
201 int InsetSpace::plaintext(Buffer const &, odocstream & os,
202 OutputParams const &) const
209 int InsetSpace::docbook(Buffer const &, odocstream & os,
210 OutputParams const &) const
230 int InsetSpace::textString(Buffer const & buf, odocstream & os,
231 OutputParams const & op) const
233 return plaintext(buf, os, op);
237 Inset * InsetSpace::clone() const
239 return new InsetSpace(kind_);
243 bool InsetSpace::isChar() const
248 bool InsetSpace::isLetter() const
253 bool InsetSpace::isSpace() const