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"
22 #include "output_xhtml.h"
24 #include "frontends/FontMetrics.h"
25 #include "frontends/Painter.h"
27 #include "support/debug.h"
28 #include "support/docstream.h"
35 InsetSpecialChar::InsetSpecialChar(Kind k)
40 InsetSpecialChar::Kind InsetSpecialChar::kind() const
46 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
48 frontend::FontMetrics const & fm =
49 theFontMetrics(mi.base.font);
50 dim.asc = fm.maxAscent();
51 dim.des = fm.maxDescent();
77 docstring ds(s.begin(), s.end());
78 dim.wid = fm.width(ds);
79 if (kind_ == HYPHENATION && dim.wid > 5)
80 dim.wid -= 2; // to make it look shorter
86 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
88 FontInfo font = pi.base.font;
93 font.setColor(Color_special);
94 pi.pain.text(x, y, char_type('-'), font);
99 font.setColor(Color_special);
100 pi.pain.text(x, y, char_type('|'), font);
103 case END_OF_SENTENCE:
105 font.setColor(Color_special);
106 pi.pain.text(x, y, char_type('.'), font);
111 font.setColor(Color_special);
112 string ell = ". . . ";
113 docstring dell(ell.begin(), ell.end());
114 pi.pain.text(x, y, dell, font);
119 frontend::FontMetrics const & fm =
120 theFontMetrics(font);
122 // A triangle the width and height of an 'x'
123 int w = fm.width(char_type('x'));
124 int ox = fm.width(char_type(' ')) + x;
125 int h = fm.ascent(char_type('x'));
128 xp[0] = ox; yp[0] = y;
129 xp[1] = ox; yp[1] = y - h;
130 xp[2] = ox + w; yp[2] = y - h/2;
131 xp[3] = ox; yp[3] = y;
133 pi.pain.lines(xp, yp, 4, Color_special);
138 font.setColor(Color_special);
139 pi.pain.text(x, y, char_type('/'), font);
144 font.setColor(Color_latex);
145 pi.pain.text(x, y, char_type('-'), font);
152 // In lyxf3 this will be just LaTeX
153 void InsetSpecialChar::write(ostream & os) const
161 command = "\\textcompwordmark{}";
163 case END_OF_SENTENCE:
167 command = "\\ldots{}";
170 command = "\\menuseparator";
173 command = "\\slash{}";
176 command = "\\nobreakdash-";
179 os << "\\SpecialChar " << command << "\n";
183 // This function will not be necessary when lyx3
184 void InsetSpecialChar::read(Lexer & lex)
187 string const command = lex.getString();
189 if (command == "\\-")
191 else if (command == "\\textcompwordmark{}")
192 kind_ = LIGATURE_BREAK;
193 else if (command == "\\@.")
194 kind_ = END_OF_SENTENCE;
195 else if (command == "\\ldots{}")
197 else if (command == "\\menuseparator")
198 kind_ = MENU_SEPARATOR;
199 else if (command == "\\slash{}")
201 else if (command == "\\nobreakdash-")
204 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
208 int InsetSpecialChar::latex(odocstream & os,
209 OutputParams const & rp) const
216 os << "\\textcompwordmark{}";
218 case END_OF_SENTENCE:
225 if (rp.local_font->isRightToLeft())
226 os << "\\lyxarrow*{}";
228 os << "\\lyxarrow{}";
236 os << "\\nobreakdash-";
243 int InsetSpecialChar::plaintext(odocstream & os, OutputParams const &) const
249 case END_OF_SENTENCE:
269 int InsetSpecialChar::docbook(odocstream & os, OutputParams const &) const
275 case END_OF_SENTENCE:
295 docstring InsetSpecialChar::xhtml(XHTMLStream & xs, OutputParams const &) const
301 case END_OF_SENTENCE:
305 xs << XHTMLStream::NextRaw() << "…";
308 xs << XHTMLStream::NextRaw() << "⇒";
311 xs << XHTMLStream::NextRaw() << "⁄";
321 void InsetSpecialChar::tocString(odocstream & os) const
323 plaintext(os, OutputParams(0));
327 void InsetSpecialChar::validate(LaTeXFeatures & features) const
329 if (kind_ == MENU_SEPARATOR)
330 features.require("lyxarrow");
331 if (kind_ == NOBREAKDASH)
332 features.require("amsmath");
336 bool InsetSpecialChar::isLetter() const
338 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
342 bool InsetSpecialChar::isLineSeparator() const
345 // this would be nice, but it does not work, since
346 // Paragraph::stripLeadingSpaces nukes the characters which
347 // have this property. I leave the code here, since it should
348 // eventually be made to work. (JMarc 20020327)
349 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;