2 * \file insetspecialchar.C
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"
18 #include "LaTeXFeatures.h"
21 #include "metricsinfo.h"
23 #include "frontends/font_metrics.h"
24 #include "frontends/Painter.h"
30 InsetSpecialChar::InsetSpecialChar(Kind k)
35 InsetSpecialChar::Kind InsetSpecialChar::kind() const
41 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
43 LyXFont & font = mi.base.font;
44 dim.asc = font_metrics::maxAscent(font);
45 dim.des = font_metrics::maxDescent(font);
49 case LIGATURE_BREAK: s = "|"; break;
50 case END_OF_SENTENCE: s = "."; break;
51 case LDOTS: s = ". . ."; break;
52 case MENU_SEPARATOR: s = " x "; break;
53 case HYPHENATION: s = "-"; break;
55 dim.wid = font_metrics::width(s, font);
56 if (kind_ == HYPHENATION && dim.wid > 5)
57 dim.wid -= 2; // to make it look shorter
62 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
64 LyXFont font = pi.base.font;
69 font.setColor(LColor::special);
70 pi.pain.text(x, y, '-', font);
75 font.setColor(LColor::special);
76 pi.pain.text(x, y, '|', font);
81 font.setColor(LColor::special);
82 pi.pain.text(x, y, '.', font);
87 font.setColor(LColor::special);
88 pi.pain.text(x, y, ". . .", font);
93 // A triangle the width and height of an 'x'
94 int w = font_metrics::width('x', font);
95 int ox = font_metrics::width(' ', font) + x;
96 int h = font_metrics::ascent('x', font);
99 xp[0] = ox; yp[0] = y;
100 xp[1] = ox; yp[1] = y - h;
101 xp[2] = ox + w; yp[2] = y - h/2;
102 xp[3] = ox; yp[3] = y;
104 pi.pain.lines(xp, yp, 4, LColor::special);
111 // In lyxf3 this will be just LaTeX
112 void InsetSpecialChar::write(Buffer const &, ostream & os) const
120 command = "\\textcompwordmark{}";
122 case END_OF_SENTENCE:
126 command = "\\ldots{}";
129 command = "\\menuseparator";
132 os << "\\SpecialChar " << command << "\n";
136 // This function will not be necessary when lyx3
137 void InsetSpecialChar::read(Buffer const &, LyXLex & lex)
140 string const command = lex.getString();
142 if (command == "\\-")
144 else if (command == "\\textcompwordmark{}")
145 kind_ = LIGATURE_BREAK;
146 else if (command == "\\@.")
147 kind_ = END_OF_SENTENCE;
148 else if (command == "\\ldots{}")
150 else if (command == "\\menuseparator")
151 kind_ = MENU_SEPARATOR;
153 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
157 int InsetSpecialChar::latex(Buffer const &, ostream & os,
158 LatexRunParams const &) const
165 os << "\\textcompwordmark{}";
167 case END_OF_SENTENCE:
174 os << "\\lyxarrow{}";
181 int InsetSpecialChar::ascii(Buffer const &, ostream & os, int) const
187 case END_OF_SENTENCE:
201 int InsetSpecialChar::linuxdoc(Buffer const &, ostream & os) const
207 case END_OF_SENTENCE:
221 int InsetSpecialChar::docbook(Buffer const &, ostream & os, bool) const
227 case END_OF_SENTENCE:
241 auto_ptr<InsetBase> InsetSpecialChar::clone() const
243 return auto_ptr<InsetBase>(new InsetSpecialChar(kind_));
247 void InsetSpecialChar::validate(LaTeXFeatures & features) const
249 if (kind_ == MENU_SEPARATOR) {
250 features.require("lyxarrow");
255 bool InsetSpecialChar::isChar() const
261 bool InsetSpecialChar::isLetter() const
263 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
267 bool InsetSpecialChar::isSpace() const
273 bool InsetSpecialChar::isLineSeparator() const
276 // this would be nice, but it does not work, since
277 // Paragraph::stripLeadingSpaces nukes the characters which
278 // have this property. I leave the code here, since it should
279 // eventually be made to work. (JMarc 20020327)
280 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;