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"
27 using lyx::odocstream;
29 using lyx::odocstream;
37 InsetSpace::InsetSpace()
41 InsetSpace::InsetSpace(Kind k)
46 InsetSpace::Kind InsetSpace::kind() const
52 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
54 lyx::frontend::FontMetrics const & fm =
55 theFontMetrics(mi.base.font);
56 dim.asc = fm.maxAscent();
57 dim.des = fm.maxDescent();
62 dim.wid = fm.width(lyx::char_type('x')) / 3;
66 dim.wid = fm.width(lyx::char_type('x'));
83 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
85 int const w = width();
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, LColor::latex);
105 pi.pain.lines(xp, yp, 4, LColor::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 &, LyXLex & 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
220 int InsetSpace::docbook(Buffer const &, odocstream & os,
221 OutputParams const &) const
241 int InsetSpace::textString(Buffer const & buf, odocstream & os,
242 OutputParams const & op) const
244 return plaintext(buf, os, op);
248 auto_ptr<InsetBase> InsetSpace::doClone() const
250 return auto_ptr<InsetBase>(new InsetSpace(kind_));
254 bool InsetSpace::isChar() const
259 bool InsetSpace::isLetter() const
264 bool InsetSpace::isSpace() const