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 bool 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'));
78 bool const changed = dim_ != dim;
84 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
86 int const w = width();
87 int const h = theFontMetrics(pi.base.font)
92 yp[0] = y - max(h / 4, 1);
93 if (kind_ == NORMAL) {
95 xp[2] = x + w; yp[2] = y;
97 xp[1] = x; yp[1] = y + max(h / 4, 1);
98 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
101 yp[3] = y - max(h / 4, 1);
103 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
104 pi.pain.lines(xp, yp, 4, LColor::latex);
106 pi.pain.lines(xp, yp, 4, LColor::special);
110 void InsetSpace::write(Buffer const &, ostream & os) const
115 command = "\\space{}";
121 command = "\\thinspace{}";
124 command = "\\quad{}";
127 command = "\\qquad{}";
130 command = "\\enspace{}";
133 command = "\\enskip{}";
136 command = "\\negthinspace{}";
139 os << "\\InsetSpace " << command << "\n";
143 void InsetSpace::read(Buffer const &, Lexer & lex)
146 string const command = lex.getString();
148 if (command == "\\space{}")
150 else if (command == "~")
152 else if (command == "\\thinspace{}")
154 else if (command == "\\quad{}")
156 else if (command == "\\qquad{}")
158 else if (command == "\\enspace{}")
160 else if (command == "\\enskip{}")
162 else if (command == "\\negthinspace{}")
165 lex.printError("InsetSpace: Unknown kind: `$$Token'");
169 int InsetSpace::latex(Buffer const &, odocstream & os,
170 OutputParams const & runparams) const
174 os << (runparams.free_spacing ? " " : "\\ ");
177 os << (runparams.free_spacing ? ' ' : '~');
180 os << (runparams.free_spacing ? " " : "\\,");
183 os << (runparams.free_spacing ? " " : "\\quad{}");
186 os << (runparams.free_spacing ? " " : "\\qquad{}");
189 os << (runparams.free_spacing ? " " : "\\enspace{}");
192 os << (runparams.free_spacing ? " " : "\\enskip{}");
195 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
202 int InsetSpace::plaintext(Buffer const &, odocstream & os,
203 OutputParams const &) const
210 int InsetSpace::docbook(Buffer const &, odocstream & os,
211 OutputParams const &) const
231 int InsetSpace::textString(Buffer const & buf, odocstream & os,
232 OutputParams const & op) const
234 return plaintext(buf, os, op);
238 auto_ptr<InsetBase> InsetSpace::doClone() const
240 return auto_ptr<InsetBase>(new InsetSpace(kind_));
244 bool InsetSpace::isChar() const
249 bool InsetSpace::isLetter() const
254 bool InsetSpace::isSpace() const