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 InsetSpecialChar::Kind InsetSpecialChar::kind() const
36 int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const
38 return lyxfont::maxAscent(font);
42 int InsetSpecialChar::descent(BufferView *, LyXFont const & font) const
44 return lyxfont::maxDescent(font);
48 int InsetSpecialChar::width(BufferView *, LyXFont const & font) const
53 int w = lyxfont::width('-', font);
55 w -= 2; // to make it look shorter
60 return lyxfont::width('|', font);
64 return lyxfont::width('.', font);
68 return lyxfont::width(". . .", font);
72 return lyxfont::width(" x ", font);
74 case PROTECTED_SEPARATOR:
76 return lyxfont::width('x', font);
80 return 1; // To shut up gcc
84 void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
85 int baseline, float & x, bool) const
87 Painter & pain = bv->painter();
93 font.setColor(LColor::special);
94 pain.text(int(x), baseline, "-", font);
100 font.setColor(LColor::special);
101 pain.text(int(x), baseline, "|", font);
102 x += width(bv, font);
105 case END_OF_SENTENCE:
107 font.setColor(LColor::special);
108 pain.text(int(x), baseline, ".", font);
109 x += width(bv, font);
114 font.setColor(LColor::special);
115 pain.text(int(x), baseline, ". . .", font);
116 x += width(bv, font);
121 // A triangle the width and height of an 'x'
122 int w = lyxfont::width('x', font);
123 int ox = lyxfont::width(' ', font) + int(x);
124 int h = lyxfont::ascent('x', font);
127 xp[0] = ox; yp[0] = baseline;
128 xp[1] = ox; yp[1] = baseline - h;
129 xp[2] = ox + w; yp[2] = baseline - h/2;
130 xp[3] = ox; yp[3] = baseline;
132 pain.lines(xp, yp, 4, LColor::special);
133 x += width(bv, font);
136 case PROTECTED_SEPARATOR:
138 float w = width(bv, font);
139 int h = lyxfont::ascent('x', font);
143 yp[0] = baseline - max(h / 4, 1);
152 yp[3] = baseline - max(h / 4, 1);
154 pain.lines(xp, yp, 4, LColor::special);
162 // In lyxf3 this will be just LaTeX
163 void InsetSpecialChar::write(Buffer const *, ostream & os) const
171 command = "\\textcompwordmark{}";
173 case END_OF_SENTENCE:
177 command = "\\ldots{}";
180 command = "\\menuseparator";
182 case PROTECTED_SEPARATOR:
183 //command = "\\protected_separator";
187 os << "\\SpecialChar " << command << "\n";
191 // This function will not be necessary when lyx3
192 void InsetSpecialChar::read(Buffer const *, LyXLex & lex)
195 string const command = lex.GetString();
197 if (command == "\\-")
199 else if (command == "\\textcompwordmark{}")
200 kind_ = LIGATURE_BREAK;
201 else if (command == "\\@.")
202 kind_ = END_OF_SENTENCE;
203 else if (command == "\\ldots{}")
205 else if (command == "\\menuseparator")
206 kind_ = MENU_SEPARATOR;
207 else if (command == "\\protected_separator"
209 kind_ = PROTECTED_SEPARATOR;
211 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
215 int InsetSpecialChar::latex(Buffer const *, ostream & os, bool /*fragile*/,
216 bool free_space) const
223 os << "\\textcompwordmark{}";
225 case END_OF_SENTENCE:
232 os << "\\lyxarrow{}";
234 case PROTECTED_SEPARATOR:
235 os << (free_space ? " " : "~");
242 int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const
248 case END_OF_SENTENCE:
257 case PROTECTED_SEPARATOR:
265 int InsetSpecialChar::linuxdoc(Buffer const * buf, ostream & os) const
267 return ascii(buf, os, 0);
271 int InsetSpecialChar::docBook(Buffer const * buf, ostream & os) const
273 return ascii(buf, os, 0);
277 Inset * InsetSpecialChar::clone(Buffer const &, bool) const
279 return new InsetSpecialChar(kind_);
283 void InsetSpecialChar::validate(LaTeXFeatures & features) const
285 if (kind_ == MENU_SEPARATOR) {
286 features.lyxarrow = true;