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"
18 #include "Dimension.h"
20 #include "MetricsInfo.h"
21 #include "OutputParams.h"
23 #include "frontends/FontMetrics.h"
24 #include "frontends/Painter.h"
26 #include "support/debug.h"
27 #include "support/docstream.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 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
52 dim.asc = fm.maxAscent();
53 dim.des = fm.maxDescent();
58 dim.wid = fm.width(char_type('M')) / 6;
62 dim.wid = fm.width(char_type(' '));
65 dim.wid = fm.width(char_type('M'));
68 dim.wid = 2 * fm.width(char_type('M'));
72 dim.wid = int(0.5 * fm.width(char_type('M')));
75 // Cache the inset dimension.
80 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
82 Dimension const dim = dimension(*pi.base.bv);
83 int const w = dim.wid;
84 int const h = theFontMetrics(pi.base.font)
89 yp[0] = y - max(h / 4, 1);
90 if (kind_ == NORMAL || kind_ == PROTECTED) {
92 xp[2] = x + w; yp[2] = y;
94 xp[1] = x; yp[1] = y + max(h / 4, 1);
95 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
98 yp[3] = y - max(h / 4, 1);
100 if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
101 pi.pain.lines(xp, yp, 4, Color_latex);
103 pi.pain.lines(xp, yp, 4, Color_special);
107 void InsetSpace::write(ostream & os) const
112 command = "\\space{}";
118 command = "\\thinspace{}";
121 command = "\\quad{}";
124 command = "\\qquad{}";
127 command = "\\enspace{}";
130 command = "\\enskip{}";
133 command = "\\negthinspace{}";
136 os << "\\InsetSpace " << command << "\n";
140 void InsetSpace::read(Lexer & lex)
143 string const command = lex.getString();
145 if (command == "\\space{}")
147 else if (command == "~")
149 else if (command == "\\thinspace{}")
151 else if (command == "\\quad{}")
153 else if (command == "\\qquad{}")
155 else if (command == "\\enspace{}")
157 else if (command == "\\enskip{}")
159 else if (command == "\\negthinspace{}")
162 lex.printError("InsetSpace: Unknown kind: `$$Token'");
166 int InsetSpace::latex(odocstream & os, 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(odocstream & os, OutputParams const &) const
205 int InsetSpace::docbook(odocstream & os, OutputParams const &) const
225 void InsetSpace::textString(odocstream & os) const
227 plaintext(os, OutputParams(0));