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"
26 InsetSpecialChar::InsetSpecialChar(Kind k)
31 int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const
33 return lyxfont::maxAscent(font);
37 int InsetSpecialChar::descent(BufferView *, LyXFont const & font) const
39 return lyxfont::maxDescent(font);
43 int InsetSpecialChar::width(BufferView *, LyXFont const & font) const
48 int w = lyxfont::width('-', font);
50 w -= 2; // to make it look shorter
55 return lyxfont::width('|', font);
59 return lyxfont::width('.', font);
63 return lyxfont::width(". . .", font);
67 return lyxfont::width(" x ", font);
69 case PROTECTED_SEPARATOR:
71 return lyxfont::width('x', font);
75 return 1; // To shut up gcc
79 void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
80 int baseline, float & x, bool) const
82 Painter & pain = bv->painter();
88 font.setColor(LColor::special);
89 pain.text(int(x), baseline, "-", font);
95 font.setColor(LColor::special);
96 pain.text(int(x), baseline, "|", font);
100 case END_OF_SENTENCE:
102 font.setColor(LColor::special);
103 pain.text(int(x), baseline, ".", font);
104 x += width(bv, font);
109 font.setColor(LColor::special);
110 pain.text(int(x), baseline, ". . .", font);
111 x += width(bv, font);
116 // A triangle the width and height of an 'x'
117 int w = lyxfont::width('x', font);
118 int ox = lyxfont::width(' ', font) + int(x);
119 int h = lyxfont::ascent('x', font);
122 xp[0] = ox; yp[0] = baseline;
123 xp[1] = ox; yp[1] = baseline - h;
124 xp[2] = ox + w; yp[2] = baseline - h/2;
125 xp[3] = ox; yp[3] = baseline;
127 pain.lines(xp, yp, 4, LColor::special);
128 x += width(bv, font);
131 case PROTECTED_SEPARATOR:
133 float w = width(bv, font);
134 int h = lyxfont::ascent('x', font);
138 yp[0] = baseline - max(h / 4, 1);
147 yp[3] = baseline - max(h / 4, 1);
149 pain.lines(xp, yp, 4, LColor::special);
157 // In lyxf3 this will be just LaTeX
158 void InsetSpecialChar::write(Buffer const *, ostream & os) const
166 command = "\\textcompwordmark{}";
168 case END_OF_SENTENCE:
172 command = "\\ldots{}";
175 command = "\\menuseparator";
177 case PROTECTED_SEPARATOR:
178 //command = "\\protected_separator";
182 os << "\\SpecialChar " << command << "\n";
186 // This function will not be necessary when lyx3
187 void InsetSpecialChar::read(Buffer const *, LyXLex & lex)
190 string const command = lex.GetString();
192 if (command == "\\-")
194 else if (command == "\\textcompwordmark{}")
195 kind = LIGATURE_BREAK;
196 else if (command == "\\@.")
197 kind = END_OF_SENTENCE;
198 else if (command == "\\ldots{}")
200 else if (command == "\\menuseparator")
201 kind = MENU_SEPARATOR;
202 else if (command == "\\protected_separator"
204 kind = PROTECTED_SEPARATOR;
206 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
210 int InsetSpecialChar::latex(Buffer const *, ostream & os, bool /*fragile*/,
211 bool free_space) const
218 os << "\\textcompwordmark{}";
220 case END_OF_SENTENCE:
227 os << "\\lyxarrow{}";
229 case PROTECTED_SEPARATOR:
230 os << (free_space ? " " : "~");
237 int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const
243 case END_OF_SENTENCE:
252 case PROTECTED_SEPARATOR:
260 int InsetSpecialChar::linuxdoc(Buffer const * buf, ostream & os) const
262 return ascii(buf, os, 0);
266 int InsetSpecialChar::docBook(Buffer const * buf, ostream & os) const
268 return ascii(buf, os, 0);
272 Inset * InsetSpecialChar::clone(Buffer const &, bool) const
274 return new InsetSpecialChar(kind);
278 void InsetSpecialChar::validate(LaTeXFeatures & features) const
280 if (kind == MENU_SEPARATOR) {
281 features.lyxarrow = true;