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
193 signed char dummy = 0;
194 Latex(command, dummy);
200 int InsetSpecialChar::Latex(string & file, signed char /*fragile*/) const
203 case HYPHENATION: file += "\\-"; break;
204 case END_OF_SENTENCE: file += "\\@."; break;
205 case LDOTS: file += "\\ldots{}"; break;
206 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
207 case PROTECTED_SEPARATOR: file += "~"; break;
213 int InsetSpecialChar::Linuxdoc(string & file) const
216 case HYPHENATION: file += ""; break;
217 case END_OF_SENTENCE: file += ""; break;
218 case LDOTS: file += "..."; break;
219 case MENU_SEPARATOR: file += "->"; break;
220 case PROTECTED_SEPARATOR: file += " "; break;
226 int InsetSpecialChar::DocBook(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 Inset * InsetSpecialChar::Clone() const
241 return new InsetSpecialChar(kind);
245 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
247 if (kind == MENU_SEPARATOR) {
248 features.lyxarrow = true;