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/font_metrics.h"
25 #include "frontends/Painter.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 LyXFont & font = mi.base.font;
52 dim.asc = font_metrics::maxAscent(font);
53 dim.des = font_metrics::maxDescent(font);
58 dim.wid = font_metrics::width(lyx::char_type('x'), font) / 3;
62 dim.wid = font_metrics::width(lyx::char_type('x'), font);
79 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
81 int const w = width();
82 int const h = font_metrics::ascent('x', pi.base.font);
86 yp[0] = y - max(h / 4, 1);
87 if (kind_ == NORMAL) {
89 xp[2] = x + w; yp[2] = y;
91 xp[1] = x; yp[1] = y + max(h / 4, 1);
92 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
95 yp[3] = y - max(h / 4, 1);
97 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
98 pi.pain.lines(xp, yp, 4, LColor::latex);
100 pi.pain.lines(xp, yp, 4, LColor::special);
104 void InsetSpace::write(Buffer const &, ostream & os) const
109 command = "\\space{}";
115 command = "\\thinspace{}";
118 command = "\\quad{}";
121 command = "\\qquad{}";
124 command = "\\enspace{}";
127 command = "\\enskip{}";
130 command = "\\negthinspace{}";
133 os << "\\InsetSpace " << command << "\n";
137 void InsetSpace::read(Buffer const &, LyXLex & lex)
140 string const command = lex.getString();
142 if (command == "\\space{}")
144 else if (command == "~")
146 else if (command == "\\thinspace{}")
148 else if (command == "\\quad{}")
150 else if (command == "\\qquad{}")
152 else if (command == "\\enspace{}")
154 else if (command == "\\enskip{}")
156 else if (command == "\\negthinspace{}")
159 lex.printError("InsetSpace: Unknown kind: `$$Token'");
163 int InsetSpace::latex(Buffer const &, ostream & os,
164 OutputParams const & runparams) const
168 os << (runparams.free_spacing ? " " : "\\ ");
171 os << (runparams.free_spacing ? ' ' : '~');
174 os << (runparams.free_spacing ? " " : "\\,");
177 os << (runparams.free_spacing ? " " : "\\quad{}");
180 os << (runparams.free_spacing ? " " : "\\qquad{}");
183 os << (runparams.free_spacing ? " " : "\\enspace{}");
186 os << (runparams.free_spacing ? " " : "\\enskip{}");
189 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
196 int InsetSpace::plaintext(Buffer const &, ostream & os,
197 OutputParams const &) const
215 int InsetSpace::docbook(Buffer const &, ostream & os,
216 OutputParams const &) const
236 int InsetSpace::textString(Buffer const & buf, ostream & os,
237 OutputParams const & op) const
239 return plaintext(buf, os, op);
243 auto_ptr<InsetBase> InsetSpace::doClone() const
245 return auto_ptr<InsetBase>(new InsetSpace(kind_));
249 bool InsetSpace::isChar() const
254 bool InsetSpace::isLetter() const
259 bool InsetSpace::isSpace() const