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 "Dimension.h"
19 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
23 #include "frontends/FontMetrics.h"
24 #include "frontends/Painter.h"
26 #include "support/debug.h"
27 #include "support/docstream.h"
34 InsetSpecialChar::InsetSpecialChar(Kind k)
39 InsetSpecialChar::Kind InsetSpecialChar::kind() const
45 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
47 frontend::FontMetrics const & fm =
48 theFontMetrics(mi.base.font);
49 dim.asc = fm.maxAscent();
50 dim.des = fm.maxDescent();
76 docstring ds(s.begin(), s.end());
77 dim.wid = fm.width(ds);
78 if (kind_ == HYPHENATION && dim.wid > 5)
79 dim.wid -= 2; // to make it look shorter
85 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
87 FontInfo font = pi.base.font;
92 font.setColor(Color_special);
93 pi.pain.text(x, y, char_type('-'), font);
98 font.setColor(Color_special);
99 pi.pain.text(x, y, char_type('|'), font);
102 case END_OF_SENTENCE:
104 font.setColor(Color_special);
105 pi.pain.text(x, y, char_type('.'), font);
110 font.setColor(Color_special);
111 string ell = ". . . ";
112 docstring dell(ell.begin(), ell.end());
113 pi.pain.text(x, y, dell, font);
118 frontend::FontMetrics const & fm =
119 theFontMetrics(font);
121 // A triangle the width and height of an 'x'
122 int w = fm.width(char_type('x'));
123 int ox = fm.width(char_type(' ')) + x;
124 int h = fm.ascent(char_type('x'));
127 xp[0] = ox; yp[0] = y;
128 xp[1] = ox; yp[1] = y - h;
129 xp[2] = ox + w; yp[2] = y - h/2;
130 xp[3] = ox; yp[3] = y;
132 pi.pain.lines(xp, yp, 4, Color_special);
137 font.setColor(Color_special);
138 pi.pain.text(x, y, char_type('/'), font);
143 font.setColor(Color_latex);
144 pi.pain.text(x, y, char_type('-'), font);
151 // In lyxf3 this will be just LaTeX
152 void InsetSpecialChar::write(ostream & os) const
160 command = "\\textcompwordmark{}";
162 case END_OF_SENTENCE:
166 command = "\\ldots{}";
169 command = "\\menuseparator";
172 command = "\\slash{}";
175 command = "\\nobreakdash-";
178 os << "\\SpecialChar " << command << "\n";
182 // This function will not be necessary when lyx3
183 void InsetSpecialChar::read(Lexer & lex)
186 string const command = lex.getString();
188 if (command == "\\-")
190 else if (command == "\\textcompwordmark{}")
191 kind_ = LIGATURE_BREAK;
192 else if (command == "\\@.")
193 kind_ = END_OF_SENTENCE;
194 else if (command == "\\ldots{}")
196 else if (command == "\\menuseparator")
197 kind_ = MENU_SEPARATOR;
198 else if (command == "\\slash{}")
200 else if (command == "\\nobreakdash-")
203 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
207 int InsetSpecialChar::latex(odocstream & os,
208 OutputParams const & rp) const
215 os << "\\textcompwordmark{}";
217 case END_OF_SENTENCE:
224 if (rp.local_font->isRightToLeft())
225 os << "\\lyxarrow*{}";
227 os << "\\lyxarrow{}";
235 os << "\\nobreakdash-";
242 int InsetSpecialChar::plaintext(odocstream & os, OutputParams const &) const
248 case END_OF_SENTENCE:
268 int InsetSpecialChar::docbook(odocstream & os, OutputParams const &) const
274 case END_OF_SENTENCE:
294 docstring InsetSpecialChar::xhtml(odocstream & os, OutputParams const &) const
300 case END_OF_SENTENCE:
320 void InsetSpecialChar::tocString(odocstream & os) const
322 plaintext(os, OutputParams(0));
326 void InsetSpecialChar::validate(LaTeXFeatures & features) const
328 if (kind_ == MENU_SEPARATOR)
329 features.require("lyxarrow");
330 if (kind_ == NOBREAKDASH)
331 features.require("amsmath");
335 bool InsetSpecialChar::isChar() const
341 bool InsetSpecialChar::isLetter() const
343 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
347 bool InsetSpecialChar::isLineSeparator() const
350 // this would be nice, but it does not work, since
351 // Paragraph::stripLeadingSpaces nukes the characters which
352 // have this property. I leave the code here, since it should
353 // eventually be made to work. (JMarc 20020327)
354 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;