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"
23 InsetSpecialChar::InsetSpecialChar(Kind k)
28 int InsetSpecialChar::ascent(Painter &, LyXFont const & font) const
30 return font.maxAscent();
34 int InsetSpecialChar::descent(Painter &, LyXFont const & font) const
36 return font.maxDescent();
40 int InsetSpecialChar::width(Painter &, LyXFont const & font) const
45 int w = font.textWidth("-", 1);
47 w -= 2; // to make it look shorter
52 return font.textWidth(".", 1);
56 return font.textWidth(". . .", 5);
60 return font.textWidth(" x ", 3);
67 case PROTECTED_SEPARATOR:
69 return font.textWidth("x", 1);
73 return 1; // To shut up gcc
77 void InsetSpecialChar::draw(Painter & pain, LyXFont const & f,
78 int baseline, float & x) const
84 font.setColor(LColor::special);
85 pain.text(int(x), baseline, "-", font);
86 x += width(pain, font);
91 font.setColor(LColor::special);
92 pain.text(int(x), baseline, ".", font);
93 x += width(pain, font);
98 font.setColor(LColor::special);
99 pain.text(int(x), baseline, ". . .", font);
100 x += width(pain, font);
105 // A triangle the width and height of an 'x'
106 int w = font.textWidth("x", 1);
107 int ox = font.textWidth(" ", 1) + int(x);
108 int h = font.ascent('x');
111 xp[0] = ox; yp[0] = baseline;
112 xp[1] = ox; yp[1] = baseline - h;
113 xp[2] = ox + w; yp[2] = baseline - h/2;
114 xp[3] = ox; yp[3] = baseline;
116 pain.lines(xp, yp, 4, LColor::special);
117 x += width(pain, font);
125 case PROTECTED_SEPARATOR:
127 float w = width(pain, font);
128 int h = font.ascent('x');
132 yp[0] = baseline - max(h / 4, 1);
141 yp[3] = baseline - max(h / 4, 1);
143 pain.lines(xp, yp, 4, LColor::special);
151 // In lyxf3 this will be just LaTeX
152 void InsetSpecialChar::Write(ostream & os) const
156 case HYPHENATION: command = "\\-"; break;
157 case END_OF_SENTENCE: command = "\\@."; break;
158 case LDOTS: command = "\\ldots{}"; break;
159 case MENU_SEPARATOR: command = "\\menuseparator"; break;
161 case NEWLINE: command = "\\newline"; break;
163 case PROTECTED_SEPARATOR:
164 command = "\\protected_separator"; break;
166 os << "\\SpecialChar " << command << "\n";
170 // This function will not be necessary when lyx3
171 void InsetSpecialChar::Read(LyXLex & lex)
174 string command = lex.GetString();
176 if (command == "\\-")
178 else if (command == "\\@.")
179 kind = END_OF_SENTENCE;
180 else if (command == "\\ldots{}")
182 else if (command == "\\menuseparator")
183 kind = MENU_SEPARATOR;
184 else if (command == "\\protected_separator")
185 kind = PROTECTED_SEPARATOR;
187 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
191 int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/) const
193 #ifdef USE_OSTREAM_ONLY
195 case HYPHENATION: os << "\\-"; break;
196 case END_OF_SENTENCE: os << "\\@."; break;
197 case LDOTS: os << "\\ldots{}"; break;
198 case MENU_SEPARATOR: os << "\\lyxarrow{}"; break;
199 case PROTECTED_SEPARATOR: os << "~"; break;
204 signed char dummy = 0;
205 Latex(command, dummy);
212 #ifndef USE_OSTREAM_ONLY
213 int InsetSpecialChar::Latex(string & file, signed char /*fragile*/) const
216 case HYPHENATION: file += "\\-"; break;
217 case END_OF_SENTENCE: file += "\\@."; break;
218 case LDOTS: file += "\\ldots{}"; break;
219 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
220 case PROTECTED_SEPARATOR: file += "~"; break;
226 int InsetSpecialChar::Linuxdoc(string & file) const
229 case HYPHENATION: file += ""; break;
230 case END_OF_SENTENCE: file += ""; break;
231 case LDOTS: file += "..."; break;
232 case MENU_SEPARATOR: file += "->"; break;
233 case PROTECTED_SEPARATOR: file += " "; break;
239 int InsetSpecialChar::DocBook(string & file) const
242 case HYPHENATION: file += ""; break;
243 case END_OF_SENTENCE: file += ""; break;
244 case LDOTS: file += "..."; break;
245 case MENU_SEPARATOR: file += "->"; break;
246 case PROTECTED_SEPARATOR: file += " "; break;
253 int InsetSpecialChar::Linuxdoc(ostream & os) const
256 case HYPHENATION: os << ""; break;
257 case END_OF_SENTENCE: os << ""; break;
258 case LDOTS: os << "..."; break;
259 case MENU_SEPARATOR: os << "->"; break;
260 case PROTECTED_SEPARATOR: os << " "; break;
266 int InsetSpecialChar::DocBook(ostream & os) const
269 case HYPHENATION: os << ""; break;
270 case END_OF_SENTENCE: os << ""; break;
271 case LDOTS: os << "..."; break;
272 case MENU_SEPARATOR: os << "->"; break;
273 case PROTECTED_SEPARATOR: os << " "; break;
280 Inset * InsetSpecialChar::Clone() const
282 return new InsetSpecialChar(kind);
286 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
288 if (kind == MENU_SEPARATOR) {
289 features.lyxarrow = true;