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"
34 InsetSpace::InsetSpace()
38 InsetSpace::InsetSpace(Kind k)
43 InsetSpace::Kind InsetSpace::kind() const
49 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
51 lyx::frontend::FontMetrics const & fm =
52 theFontMetrics(mi.base.font);
53 dim.asc = fm.maxAscent();
54 dim.des = fm.maxDescent();
59 dim.wid = fm.width(lyx::char_type('x')) / 3;
63 dim.wid = fm.width(lyx::char_type('x'));
80 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
82 int const w = width();
83 int const h = theFontMetrics(pi.base.font)
88 yp[0] = y - max(h / 4, 1);
89 if (kind_ == NORMAL) {
91 xp[2] = x + w; yp[2] = y;
93 xp[1] = x; yp[1] = y + max(h / 4, 1);
94 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
97 yp[3] = y - max(h / 4, 1);
99 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
100 pi.pain.lines(xp, yp, 4, LColor::latex);
102 pi.pain.lines(xp, yp, 4, LColor::special);
106 void InsetSpace::write(Buffer const &, ostream & os) const
111 command = "\\space{}";
117 command = "\\thinspace{}";
120 command = "\\quad{}";
123 command = "\\qquad{}";
126 command = "\\enspace{}";
129 command = "\\enskip{}";
132 command = "\\negthinspace{}";
135 os << "\\InsetSpace " << command << "\n";
139 void InsetSpace::read(Buffer const &, LyXLex & lex)
142 string const command = lex.getString();
144 if (command == "\\space{}")
146 else if (command == "~")
148 else if (command == "\\thinspace{}")
150 else if (command == "\\quad{}")
152 else if (command == "\\qquad{}")
154 else if (command == "\\enspace{}")
156 else if (command == "\\enskip{}")
158 else if (command == "\\negthinspace{}")
161 lex.printError("InsetSpace: Unknown kind: `$$Token'");
165 int InsetSpace::latex(Buffer const &, ostream & os,
166 OutputParams const & runparams) const
170 os << (runparams.free_spacing ? " " : "\\ ");
173 os << (runparams.free_spacing ? ' ' : '~');
176 os << (runparams.free_spacing ? " " : "\\,");
179 os << (runparams.free_spacing ? " " : "\\quad{}");
182 os << (runparams.free_spacing ? " " : "\\qquad{}");
185 os << (runparams.free_spacing ? " " : "\\enspace{}");
188 os << (runparams.free_spacing ? " " : "\\enskip{}");
191 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
198 int InsetSpace::plaintext(Buffer const &, lyx::odocstream & os,
199 OutputParams const &) const
217 int InsetSpace::docbook(Buffer const &, ostream & os,
218 OutputParams const &) const
238 int InsetSpace::textString(Buffer const & buf, lyx::odocstream & os,
239 OutputParams const & op) const
241 return plaintext(buf, os, op);
245 auto_ptr<InsetBase> InsetSpace::doClone() const
247 return auto_ptr<InsetBase>(new InsetSpace(kind_));
251 bool InsetSpace::isChar() const
256 bool InsetSpace::isLetter() const
261 bool InsetSpace::isSpace() const