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"
22 InsetSpecialChar::InsetSpecialChar(Kind k)
27 int InsetSpecialChar::ascent(Painter &, LyXFont const & font) const
29 return font.maxAscent();
33 int InsetSpecialChar::descent(Painter &, LyXFont const & font) const
35 return font.maxDescent();
39 int InsetSpecialChar::width(Painter &, LyXFont const & font) const
44 int w = font.textWidth("-", 1);
46 w -= 2; // to make it look shorter
51 return font.textWidth(".", 1);
55 return font.textWidth(". . .", 5);
59 return font.textWidth(" x ", 3);
66 case PROTECTED_SEPARATOR:
68 return font.textWidth("x", 1);
72 return 1; // To shut up gcc
76 void InsetSpecialChar::draw(Painter & pain, LyXFont const & f,
77 int baseline, float & x) const
83 font.setColor(LColor::special);
84 pain.text(int(x), baseline, "-", font);
85 x += width(pain, font);
90 font.setColor(LColor::special);
91 pain.text(int(x), baseline, ".", font);
92 x += width(pain, font);
97 font.setColor(LColor::special);
98 pain.text(int(x), baseline, ". . .", font);
99 x += width(pain, font);
104 // A triangle the width and height of an 'x'
105 int w = font.textWidth("x", 1);
106 int ox = font.textWidth(" ", 1) + int(x);
107 int h = font.ascent('x');
110 xp[0] = ox; yp[0] = baseline;
111 xp[1] = ox; yp[1] = baseline - h;
112 xp[2] = ox + w; yp[2] = baseline - h/2;
113 xp[3] = ox; yp[3] = baseline;
115 pain.lines(xp, yp, 4, LColor::special);
116 x += width(pain, font);
124 case PROTECTED_SEPARATOR:
126 float w = width(pain, font);
127 int h = font.ascent('x');
131 yp[0] = baseline - max(h / 4, 1);
140 yp[3] = baseline - max(h / 4, 1);
142 pain.lines(xp, yp, 4, LColor::special);
150 // In lyxf3 this will be just LaTeX
151 void InsetSpecialChar::Write(ostream & os) const
155 case HYPHENATION: command = "\\-"; break;
156 case END_OF_SENTENCE: command = "\\@."; break;
157 case LDOTS: command = "\\ldots{}"; break;
158 case MENU_SEPARATOR: command = "\\menuseparator"; break;
160 case NEWLINE: command = "\\newline"; break;
162 case PROTECTED_SEPARATOR:
163 command = "\\protected_separator"; break;
165 os << "\\SpecialChar " << command << "\n";
169 // This function will not be necessary when lyx3
170 void InsetSpecialChar::Read(LyXLex & lex)
173 string command = lex.GetString();
175 if (command == "\\-")
177 else if (command == "\\@.")
178 kind = END_OF_SENTENCE;
179 else if (command == "\\ldots{}")
181 else if (command == "\\menuseparator")
182 kind = MENU_SEPARATOR;
183 else if (command == "\\protected_separator")
184 kind = PROTECTED_SEPARATOR;
186 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
190 int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/) const
192 #ifdef USE_OSTREAM_ONLY
194 case HYPHENATION: os << "\\-"; break;
195 case END_OF_SENTENCE: os << "\\@."; break;
196 case LDOTS: os << "\\ldots{}"; break;
197 case MENU_SEPARATOR: os << "\\lyxarrow{}"; break;
198 case PROTECTED_SEPARATOR: os << "~"; break;
203 signed char dummy = 0;
204 Latex(command, dummy);
211 #ifndef USE_OSTREAM_ONLY
212 int InsetSpecialChar::Latex(string & file, signed char /*fragile*/) const
215 case HYPHENATION: file += "\\-"; break;
216 case END_OF_SENTENCE: file += "\\@."; break;
217 case LDOTS: file += "\\ldots{}"; break;
218 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
219 case PROTECTED_SEPARATOR: file += "~"; break;
225 int InsetSpecialChar::Linuxdoc(string & file) const
228 case HYPHENATION: file += ""; break;
229 case END_OF_SENTENCE: file += ""; break;
230 case LDOTS: file += "..."; break;
231 case MENU_SEPARATOR: file += "->"; break;
232 case PROTECTED_SEPARATOR: file += " "; break;
238 int InsetSpecialChar::DocBook(string & file) const
241 case HYPHENATION: file += ""; break;
242 case END_OF_SENTENCE: file += ""; break;
243 case LDOTS: file += "..."; break;
244 case MENU_SEPARATOR: file += "->"; break;
245 case PROTECTED_SEPARATOR: file += " "; break;
252 int InsetSpecialChar::Linuxdoc(ostream & os) const
255 case HYPHENATION: os << ""; break;
256 case END_OF_SENTENCE: os << ""; break;
257 case LDOTS: os << "..."; break;
258 case MENU_SEPARATOR: os << "->"; break;
259 case PROTECTED_SEPARATOR: os << " "; break;
265 int InsetSpecialChar::DocBook(ostream & os) const
268 case HYPHENATION: os << ""; break;
269 case END_OF_SENTENCE: os << ""; break;
270 case LDOTS: os << "..."; break;
271 case MENU_SEPARATOR: os << "->"; break;
272 case PROTECTED_SEPARATOR: os << " "; break;
279 Inset * InsetSpecialChar::Clone() const
281 return new InsetSpecialChar(kind);
285 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
287 if (kind == MENU_SEPARATOR) {
288 features.lyxarrow = true;