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"
25 InsetSpecialChar::InsetSpecialChar(Kind k)
30 int InsetSpecialChar::ascent(Painter &, LyXFont const & font) const
32 return lyxfont::maxAscent(font);
36 int InsetSpecialChar::descent(Painter &, LyXFont const & font) const
38 return lyxfont::maxDescent(font);
42 int InsetSpecialChar::width(Painter &, LyXFont const & font) const
47 int w = lyxfont::width('-', font);
49 w -= 2; // to make it look shorter
54 return lyxfont::width('.', font);
58 return lyxfont::width(". . .", font);
62 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(Painter & pain, LyXFont const & f,
80 int baseline, float & x) const
86 font.setColor(LColor::special);
87 pain.text(int(x), baseline, "-", font);
88 x += width(pain, font);
93 font.setColor(LColor::special);
94 pain.text(int(x), baseline, ".", font);
95 x += width(pain, font);
100 font.setColor(LColor::special);
101 pain.text(int(x), baseline, ". . .", font);
102 x += width(pain, font);
107 // A triangle the width and height of an 'x'
108 int w = lyxfont::width('x', font);
109 int ox = lyxfont::width(' ', font) + int(x);
110 int h = lyxfont::ascent('x', font);
113 xp[0] = ox; yp[0] = baseline;
114 xp[1] = ox; yp[1] = baseline - h;
115 xp[2] = ox + w; yp[2] = baseline - h/2;
116 xp[3] = ox; yp[3] = baseline;
118 pain.lines(xp, yp, 4, LColor::special);
119 x += width(pain, font);
127 case PROTECTED_SEPARATOR:
129 float w = width(pain, font);
130 int h = lyxfont::ascent('x', font);
134 yp[0] = baseline - max(h / 4, 1);
143 yp[3] = baseline - max(h / 4, 1);
145 pain.lines(xp, yp, 4, LColor::special);
153 // In lyxf3 this will be just LaTeX
154 void InsetSpecialChar::Write(ostream & os) const
158 case HYPHENATION: command = "\\-"; break;
159 case END_OF_SENTENCE: command = "\\@."; break;
160 case LDOTS: command = "\\ldots{}"; break;
161 case MENU_SEPARATOR: command = "\\menuseparator"; break;
163 case NEWLINE: command = "\\newline"; break;
165 case PROTECTED_SEPARATOR:
166 command = "\\protected_separator"; break;
168 os << "\\SpecialChar " << command << "\n";
172 // This function will not be necessary when lyx3
173 void InsetSpecialChar::Read(LyXLex & lex)
176 string command = lex.GetString();
178 if (command == "\\-")
180 else if (command == "\\@.")
181 kind = END_OF_SENTENCE;
182 else if (command == "\\ldots{}")
184 else if (command == "\\menuseparator")
185 kind = MENU_SEPARATOR;
186 else if (command == "\\protected_separator")
187 kind = PROTECTED_SEPARATOR;
189 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
193 int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/,
194 bool free_space) const
197 case HYPHENATION: os << "\\-"; break;
198 case END_OF_SENTENCE: os << "\\@."; break;
199 case LDOTS: os << "\\ldots{}"; break;
200 case MENU_SEPARATOR: os << "\\lyxarrow{}"; break;
201 case PROTECTED_SEPARATOR: os << (free_space ? " " : "~"); break;
207 int InsetSpecialChar::Linuxdoc(ostream & os) const
210 case HYPHENATION: os << ""; break;
211 case END_OF_SENTENCE: os << ""; break;
212 case LDOTS: os << "..."; break;
213 case MENU_SEPARATOR: os << "->"; break;
214 case PROTECTED_SEPARATOR: os << " "; break;
220 int InsetSpecialChar::DocBook(ostream & os) const
223 case HYPHENATION: os << ""; break;
224 case END_OF_SENTENCE: os << ""; break;
225 case LDOTS: os << "..."; break;
226 case MENU_SEPARATOR: os << "->"; break;
227 case PROTECTED_SEPARATOR: os << " "; break;
233 Inset * InsetSpecialChar::Clone() const
235 return new InsetSpecialChar(kind);
239 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
241 if (kind == MENU_SEPARATOR) {
242 features.lyxarrow = true;