1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1997 Asger Alstrup
8 * ====================================================== */
13 #pragma implementation
16 #include "insetspecialchar.h"
18 #include "LaTeXFeatures.h"
19 #include "BufferView.h"
27 InsetSpecialChar::InsetSpecialChar(Kind k)
32 InsetSpecialChar::Kind InsetSpecialChar::kind() const
37 int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const
39 return lyxfont::maxAscent(font);
43 int InsetSpecialChar::descent(BufferView *, LyXFont const & font) const
45 return lyxfont::maxDescent(font);
49 int InsetSpecialChar::width(BufferView *, LyXFont const & font) const
54 int w = lyxfont::width('-', font);
56 w -= 2; // to make it look shorter
61 return lyxfont::width('|', font);
65 return lyxfont::width('.', font);
69 return lyxfont::width(". . .", font);
73 return lyxfont::width(" x ", font);
75 case PROTECTED_SEPARATOR:
77 return lyxfont::width('x', font);
81 return 1; // To shut up gcc
85 void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
86 int baseline, float & x, bool) const
88 Painter & pain = bv->painter();
94 font.setColor(LColor::special);
95 pain.text(int(x), baseline, "-", font);
101 font.setColor(LColor::special);
102 pain.text(int(x), baseline, "|", font);
103 x += width(bv, font);
106 case END_OF_SENTENCE:
108 font.setColor(LColor::special);
109 pain.text(int(x), baseline, ".", font);
110 x += width(bv, font);
115 font.setColor(LColor::special);
116 pain.text(int(x), baseline, ". . .", font);
117 x += width(bv, font);
122 // A triangle the width and height of an 'x'
123 int w = lyxfont::width('x', font);
124 int ox = lyxfont::width(' ', font) + int(x);
125 int h = lyxfont::ascent('x', font);
128 xp[0] = ox; yp[0] = baseline;
129 xp[1] = ox; yp[1] = baseline - h;
130 xp[2] = ox + w; yp[2] = baseline - h/2;
131 xp[3] = ox; yp[3] = baseline;
133 pain.lines(xp, yp, 4, LColor::special);
134 x += width(bv, font);
137 case PROTECTED_SEPARATOR:
139 float w = width(bv, font);
140 int h = lyxfont::ascent('x', font);
144 yp[0] = baseline - max(h / 4, 1);
153 yp[3] = baseline - max(h / 4, 1);
155 pain.lines(xp, yp, 4, LColor::special);
163 // In lyxf3 this will be just LaTeX
164 void InsetSpecialChar::write(Buffer const *, ostream & os) const
172 command = "\\textcompwordmark{}";
174 case END_OF_SENTENCE:
178 command = "\\ldots{}";
181 command = "\\menuseparator";
183 case PROTECTED_SEPARATOR:
184 //command = "\\protected_separator";
188 os << "\\SpecialChar " << command << "\n";
192 // This function will not be necessary when lyx3
193 void InsetSpecialChar::read(Buffer const *, LyXLex & lex)
196 string const command = lex.getString();
198 if (command == "\\-")
200 else if (command == "\\textcompwordmark{}")
201 kind_ = LIGATURE_BREAK;
202 else if (command == "\\@.")
203 kind_ = END_OF_SENTENCE;
204 else if (command == "\\ldots{}")
206 else if (command == "\\menuseparator")
207 kind_ = MENU_SEPARATOR;
208 else if (command == "\\protected_separator"
210 kind_ = PROTECTED_SEPARATOR;
212 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
216 int InsetSpecialChar::latex(Buffer const *, ostream & os, bool /*fragile*/,
217 bool free_space) const
224 os << "\\textcompwordmark{}";
226 case END_OF_SENTENCE:
233 os << "\\lyxarrow{}";
235 case PROTECTED_SEPARATOR:
236 os << (free_space ? " " : "~");
243 int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const
249 case END_OF_SENTENCE:
258 case PROTECTED_SEPARATOR:
266 int InsetSpecialChar::linuxdoc(Buffer const * buf, ostream & os) const
268 return ascii(buf, os, 0);
272 int InsetSpecialChar::docBook(Buffer const * buf, ostream & os) const
274 return ascii(buf, os, 0);
278 Inset * InsetSpecialChar::clone(Buffer const &, bool) const
280 return new InsetSpecialChar(kind_);
284 void InsetSpecialChar::validate(LaTeXFeatures & features) const
286 if (kind_ == MENU_SEPARATOR) {
287 features.lyxarrow = true;