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"
32 InsetSpecialChar::InsetSpecialChar(Kind k)
37 InsetSpecialChar::Kind InsetSpecialChar::kind() const
43 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
45 LyXFont & font = mi.base.font;
46 dim.asc = font_metrics::maxAscent(font);
47 dim.des = font_metrics::maxDescent(font);
51 case LIGATURE_BREAK: s = "|"; break;
52 case END_OF_SENTENCE: s = "."; break;
53 case LDOTS: s = ". . ."; break;
54 case MENU_SEPARATOR: s = " x "; break;
55 case HYPHENATION: s = "-"; break;
57 dim.wid = font_metrics::width(s, font);
58 if (kind_ == HYPHENATION && dim.wid > 5)
59 dim.wid -= 2; // to make it look shorter
64 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
66 LyXFont font = pi.base.font;
71 font.setColor(LColor::special);
72 pi.pain.text(x, y, '-', font);
77 font.setColor(LColor::special);
78 pi.pain.text(x, y, '|', font);
83 font.setColor(LColor::special);
84 pi.pain.text(x, y, '.', font);
89 font.setColor(LColor::special);
90 pi.pain.text(x, y, ". . .", font);
95 // A triangle the width and height of an 'x'
96 int w = font_metrics::width('x', font);
97 int ox = font_metrics::width(' ', font) + x;
98 int h = font_metrics::ascent('x', font);
101 xp[0] = ox; yp[0] = y;
102 xp[1] = ox; yp[1] = y - h;
103 xp[2] = ox + w; yp[2] = y - h/2;
104 xp[3] = ox; yp[3] = y;
106 pi.pain.lines(xp, yp, 4, LColor::special);
113 // In lyxf3 this will be just LaTeX
114 void InsetSpecialChar::write(Buffer const &, ostream & os) const
122 command = "\\textcompwordmark{}";
124 case END_OF_SENTENCE:
128 command = "\\ldots{}";
131 command = "\\menuseparator";
134 os << "\\SpecialChar " << command << "\n";
138 // This function will not be necessary when lyx3
139 void InsetSpecialChar::read(Buffer const &, LyXLex & lex)
142 string const command = lex.getString();
144 if (command == "\\-")
146 else if (command == "\\textcompwordmark{}")
147 kind_ = LIGATURE_BREAK;
148 else if (command == "\\@.")
149 kind_ = END_OF_SENTENCE;
150 else if (command == "\\ldots{}")
152 else if (command == "\\menuseparator")
153 kind_ = MENU_SEPARATOR;
155 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
159 int InsetSpecialChar::latex(Buffer const &, ostream & os,
160 OutputParams const &) const
167 os << "\\textcompwordmark{}";
169 case END_OF_SENTENCE:
176 os << "\\lyxarrow{}";
183 int InsetSpecialChar::plaintext(Buffer const &, ostream & os,
184 OutputParams const &) const
190 case END_OF_SENTENCE:
204 int InsetSpecialChar::linuxdoc(Buffer const &, ostream & os,
205 OutputParams const &) const
211 case END_OF_SENTENCE:
225 int InsetSpecialChar::docbook(Buffer const &, ostream & os,
226 OutputParams const &) const
232 case END_OF_SENTENCE:
246 auto_ptr<InsetBase> InsetSpecialChar::doClone() const
248 return auto_ptr<InsetBase>(new InsetSpecialChar(kind_));
252 void InsetSpecialChar::validate(LaTeXFeatures & features) const
254 if (kind_ == MENU_SEPARATOR) {
255 features.require("lyxarrow");
260 bool InsetSpecialChar::isChar() const
266 bool InsetSpecialChar::isLetter() const
268 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
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;