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"
18 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
22 #include "frontends/FontMetrics.h"
23 #include "frontends/Painter.h"
25 #include "support/debug.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(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(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(odocstream & os,
207 OutputParams const & rp) const
214 os << "\\textcompwordmark{}";
216 case END_OF_SENTENCE:
223 os << "\\lyxarrow{}";
231 os << "\\nobreakdash-";
238 int InsetSpecialChar::plaintext(odocstream & os, OutputParams const &) const
244 case END_OF_SENTENCE:
264 int InsetSpecialChar::docbook(odocstream & os, OutputParams const &) const
270 case END_OF_SENTENCE:
290 void InsetSpecialChar::textString(odocstream & os) const
292 plaintext(os, OutputParams(0));
296 void InsetSpecialChar::validate(LaTeXFeatures & features) const
298 if (kind_ == MENU_SEPARATOR)
299 features.require("lyxarrow");
300 if (kind_ == NOBREAKDASH)
301 features.require("amsmath");
305 bool InsetSpecialChar::isChar() const
311 bool InsetSpecialChar::isLetter() const
313 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
317 bool InsetSpecialChar::isLineSeparator() const
320 // this would be nice, but it does not work, since
321 // Paragraph::stripLeadingSpaces nukes the characters which
322 // have this property. I leave the code here, since it should
323 // eventually be made to work. (JMarc 20020327)
324 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;