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"
36 InsetSpace::InsetSpace()
40 InsetSpace::InsetSpace(Kind k)
45 InsetSpace::Kind InsetSpace::kind() const
51 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
53 frontend::FontMetrics const & fm =
54 theFontMetrics(mi.base.font);
55 dim.asc = fm.maxAscent();
56 dim.des = fm.maxDescent();
61 dim.wid = fm.width(char_type('x')) / 3;
65 dim.wid = fm.width(char_type('x'));
82 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
84 int const w = width();
85 int const h = theFontMetrics(pi.base.font)
90 yp[0] = y - max(h / 4, 1);
91 if (kind_ == NORMAL) {
93 xp[2] = x + w; yp[2] = y;
95 xp[1] = x; yp[1] = y + max(h / 4, 1);
96 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
99 yp[3] = y - max(h / 4, 1);
101 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
102 pi.pain.lines(xp, yp, 4, LColor::latex);
104 pi.pain.lines(xp, yp, 4, LColor::special);
108 void InsetSpace::write(Buffer const &, ostream & os) const
113 command = "\\space{}";
119 command = "\\thinspace{}";
122 command = "\\quad{}";
125 command = "\\qquad{}";
128 command = "\\enspace{}";
131 command = "\\enskip{}";
134 command = "\\negthinspace{}";
137 os << "\\InsetSpace " << command << "\n";
141 void InsetSpace::read(Buffer const &, LyXLex & lex)
144 string const command = lex.getString();
146 if (command == "\\space{}")
148 else if (command == "~")
150 else if (command == "\\thinspace{}")
152 else if (command == "\\quad{}")
154 else if (command == "\\qquad{}")
156 else if (command == "\\enspace{}")
158 else if (command == "\\enskip{}")
160 else if (command == "\\negthinspace{}")
163 lex.printError("InsetSpace: Unknown kind: `$$Token'");
167 int InsetSpace::latex(Buffer const &, odocstream & os,
168 OutputParams const & runparams) const
172 os << (runparams.free_spacing ? " " : "\\ ");
175 os << (runparams.free_spacing ? ' ' : '~');
178 os << (runparams.free_spacing ? " " : "\\,");
181 os << (runparams.free_spacing ? " " : "\\quad{}");
184 os << (runparams.free_spacing ? " " : "\\qquad{}");
187 os << (runparams.free_spacing ? " " : "\\enspace{}");
190 os << (runparams.free_spacing ? " " : "\\enskip{}");
193 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
200 int InsetSpace::plaintext(Buffer const &, odocstream & os,
201 OutputParams const &) const
219 int InsetSpace::docbook(Buffer const &, odocstream & os,
220 OutputParams const &) const
240 int InsetSpace::textString(Buffer const & buf, odocstream & os,
241 OutputParams const & op) const
243 return plaintext(buf, os, op);
247 auto_ptr<InsetBase> InsetSpace::doClone() const
249 return auto_ptr<InsetBase>(new InsetSpace(kind_));
253 bool InsetSpace::isChar() const
258 bool InsetSpace::isLetter() const
263 bool InsetSpace::isSpace() const