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"
30 InsetSpecialChar::InsetSpecialChar(Kind k)
35 InsetSpecialChar::Kind InsetSpecialChar::kind() const
41 void InsetSpecialChar::dimension(BufferView *, LyXFont const & font,
42 Dimension & dim) const
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
61 void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
62 int baseline, float & x) const
64 Painter & pain = bv->painter();
70 font.setColor(LColor::special);
71 pain.text(int(x), baseline, '-', font);
77 font.setColor(LColor::special);
78 pain.text(int(x), baseline, '|', font);
84 font.setColor(LColor::special);
85 pain.text(int(x), baseline, '.', font);
91 font.setColor(LColor::special);
92 pain.text(int(x), baseline, ". . .", font);
98 // A triangle the width and height of an 'x'
99 int w = font_metrics::width('x', font);
100 int ox = font_metrics::width(' ', font) + int(x);
101 int h = font_metrics::ascent('x', font);
104 xp[0] = ox; yp[0] = baseline;
105 xp[1] = ox; yp[1] = baseline - h;
106 xp[2] = ox + w; yp[2] = baseline - h/2;
107 xp[3] = ox; yp[3] = baseline;
109 pain.lines(xp, yp, 4, LColor::special);
110 x += width(bv, font);
117 // In lyxf3 this will be just LaTeX
118 void InsetSpecialChar::write(Buffer const *, ostream & os) const
126 command = "\\textcompwordmark{}";
128 case END_OF_SENTENCE:
132 command = "\\ldots{}";
135 command = "\\menuseparator";
138 os << "\\SpecialChar " << command << "\n";
142 // This function will not be necessary when lyx3
143 void InsetSpecialChar::read(Buffer const *, LyXLex & lex)
146 string const command = lex.getString();
148 if (command == "\\-")
150 else if (command == "\\textcompwordmark{}")
151 kind_ = LIGATURE_BREAK;
152 else if (command == "\\@.")
153 kind_ = END_OF_SENTENCE;
154 else if (command == "\\ldots{}")
156 else if (command == "\\menuseparator")
157 kind_ = MENU_SEPARATOR;
159 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
163 int InsetSpecialChar::latex(Buffer const *, ostream & os,
164 LatexRunParams const &) const
171 os << "\\textcompwordmark{}";
173 case END_OF_SENTENCE:
180 os << "\\lyxarrow{}";
187 int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const
193 case END_OF_SENTENCE:
207 int InsetSpecialChar::linuxdoc(Buffer const *, ostream & os) const
213 case END_OF_SENTENCE:
227 int InsetSpecialChar::docbook(Buffer const *, ostream & os, bool) const
233 case END_OF_SENTENCE:
247 Inset * InsetSpecialChar::clone(Buffer const &) const
249 return new InsetSpecialChar(kind_);
253 // Inset * InsetSpecialChar::clone(Buffer const &, bool) const
255 // return new InsetSpecialChar(kind_);
259 void InsetSpecialChar::validate(LaTeXFeatures & features) const
261 if (kind_ == MENU_SEPARATOR) {
262 features.require("lyxarrow");
267 bool InsetSpecialChar::isChar() const
273 bool InsetSpecialChar::isLetter() const
275 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
279 bool InsetSpecialChar::isSpace() const
285 bool InsetSpecialChar::isLineSeparator() const
288 // this would be nice, but it does not work, since
289 // Paragraph::stripLeadingSpaces nukes the characters which
290 // have this property. I leave the code here, since it should
291 // eventually be made to work. (JMarc 20020327)
292 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;