2 * \file InsetSpecialChar.cpp
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
10 * Full author contact details are available in file CREDITS.
15 #include "InsetSpecialChar.h"
17 #include "support/debug.h"
18 #include "Dimension.h"
19 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
23 #include "frontends/FontMetrics.h"
24 #include "frontends/Painter.h"
26 #include "support/docstream.h"
33 InsetSpecialChar::InsetSpecialChar(Kind k)
38 InsetSpecialChar::Kind InsetSpecialChar::kind() const
44 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
46 frontend::FontMetrics const & fm =
47 theFontMetrics(mi.base.font);
48 dim.asc = fm.maxAscent();
49 dim.des = fm.maxDescent();
75 docstring ds(s.begin(), s.end());
76 dim.wid = fm.width(ds);
77 if (kind_ == HYPHENATION && dim.wid > 5)
78 dim.wid -= 2; // to make it look shorter
84 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
86 FontInfo font = pi.base.font;
91 font.setColor(Color_special);
92 pi.pain.text(x, y, char_type('-'), font);
97 font.setColor(Color_special);
98 pi.pain.text(x, y, char_type('|'), font);
101 case END_OF_SENTENCE:
103 font.setColor(Color_special);
104 pi.pain.text(x, y, char_type('.'), font);
109 font.setColor(Color_special);
110 string ell = ". . . ";
111 docstring dell(ell.begin(), ell.end());
112 pi.pain.text(x, y, dell, font);
117 frontend::FontMetrics const & fm =
118 theFontMetrics(font);
120 // A triangle the width and height of an 'x'
121 int w = fm.width(char_type('x'));
122 int ox = fm.width(char_type(' ')) + x;
123 int h = fm.ascent(char_type('x'));
126 xp[0] = ox; yp[0] = y;
127 xp[1] = ox; yp[1] = y - h;
128 xp[2] = ox + w; yp[2] = y - h/2;
129 xp[3] = ox; yp[3] = y;
131 pi.pain.lines(xp, yp, 4, Color_special);
136 font.setColor(Color_special);
137 pi.pain.text(x, y, char_type('/'), font);
142 font.setColor(Color_latex);
143 pi.pain.text(x, y, char_type('-'), font);
150 // In lyxf3 this will be just LaTeX
151 void InsetSpecialChar::write(Buffer const &, ostream & os) const
159 command = "\\textcompwordmark{}";
161 case END_OF_SENTENCE:
165 command = "\\ldots{}";
168 command = "\\menuseparator";
171 command = "\\slash{}";
174 command = "\\nobreakdash-";
177 os << "\\SpecialChar " << command << "\n";
181 // This function will not be necessary when lyx3
182 void InsetSpecialChar::read(Buffer const &, Lexer & lex)
185 string const command = lex.getString();
187 if (command == "\\-")
189 else if (command == "\\textcompwordmark{}")
190 kind_ = LIGATURE_BREAK;
191 else if (command == "\\@.")
192 kind_ = END_OF_SENTENCE;
193 else if (command == "\\ldots{}")
195 else if (command == "\\menuseparator")
196 kind_ = MENU_SEPARATOR;
197 else if (command == "\\slash{}")
199 else if (command == "\\nobreakdash-")
202 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
206 int InsetSpecialChar::latex(Buffer const &, odocstream & os,
207 OutputParams const &) const
214 os << "\\textcompwordmark{}";
216 case END_OF_SENTENCE:
223 os << "\\lyxarrow{}";
229 os << "\\nobreakdash-";
236 int InsetSpecialChar::plaintext(Buffer const &, odocstream & os,
237 OutputParams const &) const
243 case END_OF_SENTENCE:
263 int InsetSpecialChar::docbook(Buffer const &, odocstream & os,
264 OutputParams const &) const
270 case END_OF_SENTENCE:
290 void InsetSpecialChar::textString(Buffer const & buf, odocstream & os) const
292 plaintext(buf, os, OutputParams(0));
296 Inset * InsetSpecialChar::clone() const
298 return new InsetSpecialChar(kind_);
302 void InsetSpecialChar::validate(LaTeXFeatures & features) const
304 if (kind_ == MENU_SEPARATOR)
305 features.require("lyxarrow");
306 if (kind_ == NOBREAKDASH)
307 features.require("amsmath");
311 bool InsetSpecialChar::isChar() const
317 bool InsetSpecialChar::isLetter() const
319 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
323 bool InsetSpecialChar::isLineSeparator() const
326 // this would be nice, but it does not work, since
327 // Paragraph::stripLeadingSpaces nukes the characters which
328 // have this property. I leave the code here, since it should
329 // eventually be made to work. (JMarc 20020327)
330 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;