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"
20 #include "metricsinfo.h"
22 #include "frontends/font_metrics.h"
23 #include "frontends/Painter.h"
29 InsetSpecialChar::InsetSpecialChar(Kind k)
34 InsetSpecialChar::Kind InsetSpecialChar::kind() const
40 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
42 LyXFont & font = mi.base.font;
43 dim.asc = font_metrics::maxAscent(font);
44 dim.des = font_metrics::maxDescent(font);
48 case LIGATURE_BREAK: s = "|"; break;
49 case END_OF_SENTENCE: s = "."; break;
50 case LDOTS: s = ". . ."; break;
51 case MENU_SEPARATOR: s = " x "; break;
52 case HYPHENATION: s = "-"; break;
54 dim.wid = font_metrics::width(s, font);
55 if (kind_ == HYPHENATION && dim.wid > 5)
56 dim.wid -= 2; // to make it look shorter
61 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
63 LyXFont font = pi.base.font;
68 font.setColor(LColor::special);
69 pi.pain.text(x, y, '-', font);
74 font.setColor(LColor::special);
75 pi.pain.text(x, y, '|', font);
80 font.setColor(LColor::special);
81 pi.pain.text(x, y, '.', font);
86 font.setColor(LColor::special);
87 pi.pain.text(x, y, ". . .", font);
92 // A triangle the width and height of an 'x'
93 int w = font_metrics::width('x', font);
94 int ox = font_metrics::width(' ', font) + x;
95 int h = font_metrics::ascent('x', font);
98 xp[0] = ox; yp[0] = y;
99 xp[1] = ox; yp[1] = y - h;
100 xp[2] = ox + w; yp[2] = y - h/2;
101 xp[3] = ox; yp[3] = y;
103 pi.pain.lines(xp, yp, 4, LColor::special);
110 // In lyxf3 this will be just LaTeX
111 void InsetSpecialChar::write(Buffer const &, ostream & os) const
119 command = "\\textcompwordmark{}";
121 case END_OF_SENTENCE:
125 command = "\\ldots{}";
128 command = "\\menuseparator";
131 os << "\\SpecialChar " << command << "\n";
135 // This function will not be necessary when lyx3
136 void InsetSpecialChar::read(Buffer const &, LyXLex & lex)
139 string const command = lex.getString();
141 if (command == "\\-")
143 else if (command == "\\textcompwordmark{}")
144 kind_ = LIGATURE_BREAK;
145 else if (command == "\\@.")
146 kind_ = END_OF_SENTENCE;
147 else if (command == "\\ldots{}")
149 else if (command == "\\menuseparator")
150 kind_ = MENU_SEPARATOR;
152 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
156 int InsetSpecialChar::latex(Buffer const &, ostream & os,
157 LatexRunParams const &) const
164 os << "\\textcompwordmark{}";
166 case END_OF_SENTENCE:
173 os << "\\lyxarrow{}";
180 int InsetSpecialChar::ascii(Buffer const &, ostream & os, int) const
186 case END_OF_SENTENCE:
200 int InsetSpecialChar::linuxdoc(Buffer const &, ostream & os) const
206 case END_OF_SENTENCE:
220 int InsetSpecialChar::docbook(Buffer const &, ostream & os, bool) const
226 case END_OF_SENTENCE:
240 auto_ptr<InsetBase> InsetSpecialChar::clone() const
242 return auto_ptr<InsetBase>(new InsetSpecialChar(kind_));
246 void InsetSpecialChar::validate(LaTeXFeatures & features) const
248 if (kind_ == MENU_SEPARATOR) {
249 features.require("lyxarrow");
254 bool InsetSpecialChar::isChar() const
260 bool InsetSpecialChar::isLetter() const
262 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
266 bool InsetSpecialChar::isSpace() const
272 bool InsetSpecialChar::isLineSeparator() const
275 // this would be nice, but it does not work, since
276 // Paragraph::stripLeadingSpaces nukes the characters which
277 // have this property. I leave the code here, since it should
278 // eventually be made to work. (JMarc 20020327)
279 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;