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"
19 #include "LaTeXFeatures.h"
22 InsetSpecialChar::InsetSpecialChar(Kind k)
28 int InsetSpecialChar::ascent(Painter &, LyXFont const & font) const
30 return font.maxAscent();
33 int InsetSpecialChar::Ascent(LyXFont const & font) const
35 return font.maxAscent();
41 int InsetSpecialChar::descent(Painter &, LyXFont const & font) const
43 return font.maxDescent();
46 int InsetSpecialChar::Descent(LyXFont const & font) const
48 return font.maxDescent();
54 int InsetSpecialChar::width(Painter &, LyXFont const & font) const
60 int w = f.textWidth("-", 1);
62 w -= 2; // to make it look shorter
67 return f.textWidth(".", 1);
71 return f.textWidth(". . .", 5);
73 case MENU_SEPARATOR: {
74 return f.textWidth(" x ", 3);
77 return 1; // To shut up gcc
80 int InsetSpecialChar::Width(LyXFont const & font) const
86 int w = f.textWidth("-", 1);
88 w -= 2; // to make it look shorter
93 return f.textWidth(".", 1);
97 return f.textWidth(". . .", 5);
99 case MENU_SEPARATOR: {
100 return f.textWidth(" x ", 3);
103 return 1; // To shut up gcc
109 void InsetSpecialChar::draw(Painter & pain, LyXFont const & f,
110 int baseline, float & x) const
116 font.setColor(LColor::special);
117 pain.text(int(x), baseline, "-", font);
118 x += width(pain, font);
121 case END_OF_SENTENCE:
123 font.setColor(LColor::special);
124 pain.text(int(x), baseline, ".", font);
125 x += width(pain, font);
130 font.setColor(LColor::special);
131 pain.text(int(x), baseline, ". . .", font);
132 x += width(pain, font);
137 // A triangle the width and height of an 'x'
138 int w = font.textWidth("x", 1);
139 int ox = font.textWidth(" ", 1) + int(x);
140 int h = font.ascent('x');
143 xp[0] = ox; yp[0] = baseline;
144 xp[1] = ox; yp[1] = baseline - h;
145 xp[2] = ox + w; yp[2] = baseline - h/2;
146 xp[3] = ox; yp[3] = baseline;
148 pain.lines(xp, yp, 4, LColor::special);
149 x += width(pain, font);
154 void InsetSpecialChar::Draw(LyXFont font, LyXScreen & scr,
155 int baseline, float & x)
160 font.setColor(LyXFont::BLUE);
161 scr.drawText(font, "-", 1, baseline, int(x));
165 case END_OF_SENTENCE:
167 font.setColor(LyXFont::BLUE);
168 scr.drawText(font, ".", 1, baseline, int(x));
174 font.setColor(LyXFont::BLUE);
175 scr.drawText(font, ". . .", 5, baseline, int(x));
181 // A triangle the width and height of an 'x'
182 int w = font.textWidth("x", 1);
183 int ox = font.textWidth(" ", 1) + int(x);
184 int h = font.ascent('x');
186 p[0].x = ox; p[0].y = baseline;
187 p[1].x = ox; p[1].y = baseline - h;
188 p[2].x = ox + w;p[2].y = baseline - h/2;
189 p[3].x = ox; p[3].y = baseline;
190 scr.drawLines(getGC(gc_copy), p, 4);
198 // In lyxf3 this will be just LaTeX
199 void InsetSpecialChar::Write(ostream & os)
203 case HYPHENATION: command = "\\-"; break;
204 case END_OF_SENTENCE: command = "\\@."; break;
205 case LDOTS: command = "\\ldots{}"; break;
206 case MENU_SEPARATOR: command = "\\menuseparator"; break;
208 os << "\\SpecialChar " << command << "\n";
212 // This function will not be necessary when lyx3
213 void InsetSpecialChar::Read(LyXLex & lex)
216 string command = lex.GetString();
218 if (command == "\\-")
220 else if (command == "\\@.")
221 kind = END_OF_SENTENCE;
222 else if (command == "\\ldots{}")
224 else if (command == "\\menuseparator")
225 kind = MENU_SEPARATOR;
227 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
231 int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/)
234 signed char dummy = 0;
235 Latex(command, dummy);
241 int InsetSpecialChar::Latex(string & file, signed char /*fragile*/)
244 case HYPHENATION: file += "\\-"; break;
245 case END_OF_SENTENCE: file += "\\@."; break;
246 case LDOTS: file += "\\ldots{}"; break;
247 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
253 int InsetSpecialChar::Linuxdoc(string & file)
256 case HYPHENATION: file += ""; break;
257 case END_OF_SENTENCE: file += ""; break;
258 case LDOTS: file += "..."; break;
259 case MENU_SEPARATOR: file += "->"; break;
265 int InsetSpecialChar::DocBook(string & file)
268 case HYPHENATION: file += ""; break;
269 case END_OF_SENTENCE: file += ""; break;
270 case LDOTS: file += "..."; break;
271 case MENU_SEPARATOR: file += "->"; break;
277 Inset * InsetSpecialChar::Clone() const
279 return new InsetSpecialChar(kind);
283 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
285 if (kind == MENU_SEPARATOR) {
286 features.lyxarrow = true;