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 "dimension.h"
19 #include "LaTeXFeatures.h"
20 #include "BufferView.h"
21 #include "frontends/Painter.h"
22 #include "frontends/font_metrics.h"
25 #include "metricsinfo.h"
31 InsetSpecialChar::InsetSpecialChar(Kind k)
36 InsetSpecialChar::Kind InsetSpecialChar::kind() const
42 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
44 LyXFont & font = mi.base.font;
45 dim.asc = font_metrics::maxAscent(font);
46 dim.des = font_metrics::maxDescent(font);
50 case LIGATURE_BREAK: s = "|"; break;
51 case END_OF_SENTENCE: s = "."; break;
52 case LDOTS: s = ". . ."; break;
53 case MENU_SEPARATOR: s = " x "; break;
54 case HYPHENATION: s = "-"; break;
56 dim.wid = font_metrics::width(s, font);
57 if (kind_ == HYPHENATION && dim.wid > 5)
58 dim.wid -= 2; // to make it look shorter
63 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
65 LyXFont font = pi.base.font;
70 font.setColor(LColor::special);
71 pi.pain.text(x, y, '-', font);
76 font.setColor(LColor::special);
77 pi.pain.text(x, y, '|', font);
82 font.setColor(LColor::special);
83 pi.pain.text(x, y, '.', font);
88 font.setColor(LColor::special);
89 pi.pain.text(x, y, ". . .", font);
94 // A triangle the width and height of an 'x'
95 int w = font_metrics::width('x', font);
96 int ox = font_metrics::width(' ', font) + x;
97 int h = font_metrics::ascent('x', font);
100 xp[0] = ox; yp[0] = y;
101 xp[1] = ox; yp[1] = y - h;
102 xp[2] = ox + w; yp[2] = y - h/2;
103 xp[3] = ox; yp[3] = y;
105 pi.pain.lines(xp, yp, 4, LColor::special);
112 // In lyxf3 this will be just LaTeX
113 void InsetSpecialChar::write(Buffer const *, ostream & os) const
121 command = "\\textcompwordmark{}";
123 case END_OF_SENTENCE:
127 command = "\\ldots{}";
130 command = "\\menuseparator";
133 os << "\\SpecialChar " << command << "\n";
137 // This function will not be necessary when lyx3
138 void InsetSpecialChar::read(Buffer const *, LyXLex & lex)
141 string const command = lex.getString();
143 if (command == "\\-")
145 else if (command == "\\textcompwordmark{}")
146 kind_ = LIGATURE_BREAK;
147 else if (command == "\\@.")
148 kind_ = END_OF_SENTENCE;
149 else if (command == "\\ldots{}")
151 else if (command == "\\menuseparator")
152 kind_ = MENU_SEPARATOR;
154 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
158 int InsetSpecialChar::latex(Buffer const *, ostream & os,
159 LatexRunParams const &) const
166 os << "\\textcompwordmark{}";
168 case END_OF_SENTENCE:
175 os << "\\lyxarrow{}";
182 int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const
188 case END_OF_SENTENCE:
202 int InsetSpecialChar::linuxdoc(Buffer const *, ostream & os) const
208 case END_OF_SENTENCE:
222 int InsetSpecialChar::docbook(Buffer const *, ostream & os, bool) const
228 case END_OF_SENTENCE:
242 InsetBase * InsetSpecialChar::clone() const
244 return new InsetSpecialChar(kind_);
248 void InsetSpecialChar::validate(LaTeXFeatures & features) const
250 if (kind_ == MENU_SEPARATOR) {
251 features.require("lyxarrow");
256 bool InsetSpecialChar::isChar() const
262 bool InsetSpecialChar::isLetter() const
264 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
268 bool InsetSpecialChar::isSpace() const
274 bool InsetSpecialChar::isLineSeparator() const
277 // this would be nice, but it does not work, since
278 // Paragraph::stripLeadingSpaces nukes the characters which
279 // have this property. I leave the code here, since it should
280 // eventually be made to work. (JMarc 20020327)
281 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;