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"
24 InsetSpecialChar::InsetSpecialChar(Kind k)
30 int InsetSpecialChar::ascent(Painter &, LyXFont const & font) const
32 return font.maxAscent();
35 int InsetSpecialChar::Ascent(LyXFont const & font) const
37 return font.maxAscent();
43 int InsetSpecialChar::descent(Painter &, LyXFont const & font) const
45 return font.maxDescent();
48 int InsetSpecialChar::Descent(LyXFont const & font) const
50 return font.maxDescent();
56 int InsetSpecialChar::width(Painter &, LyXFont const & font) const
62 int w = f.textWidth("-", 1);
64 w -= 2; // to make it look shorter
69 return f.textWidth(".", 1);
73 return f.textWidth(". . .", 5);
75 case MENU_SEPARATOR: {
76 return f.textWidth(" x ", 3);
79 return 1; // To shut up gcc
82 int InsetSpecialChar::Width(LyXFont const & font) const
88 int w = f.textWidth("-", 1);
90 w -= 2; // to make it look shorter
95 return f.textWidth(".", 1);
99 return f.textWidth(". . .", 5);
101 case MENU_SEPARATOR: {
102 return f.textWidth(" x ", 3);
105 return 1; // To shut up gcc
111 void InsetSpecialChar::draw(Painter & pain, LyXFont const & f,
112 int baseline, float & x) const
118 font.setColor(LColor::special);
119 pain.text(int(x), baseline, "-", font);
120 x += width(pain, font);
123 case END_OF_SENTENCE:
125 font.setColor(LColor::special);
126 pain.text(int(x), baseline, ".", font);
127 x += width(pain, font);
132 font.setColor(LColor::special);
133 pain.text(int(x), baseline, ". . .", font);
134 x += width(pain, font);
139 // A triangle the width and height of an 'x'
140 int w = font.textWidth("x", 1);
141 int ox = font.textWidth(" ", 1) + int(x);
142 int h = font.ascent('x');
145 xp[0] = ox; yp[0] = baseline;
146 xp[1] = ox; yp[1] = baseline - h;
147 xp[2] = ox + w; yp[2] = baseline - h/2;
148 xp[3] = ox; yp[3] = baseline;
150 pain.lines(xp, yp, 4, LColor::special);
151 x += width(pain, font);
156 void InsetSpecialChar::Draw(LyXFont font, LyXScreen & scr,
157 int baseline, float & x)
162 font.setColor(LyXFont::BLUE);
163 scr.drawText(font, "-", 1, baseline, int(x));
167 case END_OF_SENTENCE:
169 font.setColor(LyXFont::BLUE);
170 scr.drawText(font, ".", 1, baseline, int(x));
176 font.setColor(LyXFont::BLUE);
177 scr.drawText(font, ". . .", 5, baseline, int(x));
183 // A triangle the width and height of an 'x'
184 int w = font.textWidth("x", 1);
185 int ox = font.textWidth(" ", 1) + int(x);
186 int h = font.ascent('x');
188 p[0].x = ox; p[0].y = baseline;
189 p[1].x = ox; p[1].y = baseline - h;
190 p[2].x = ox + w;p[2].y = baseline - h/2;
191 p[3].x = ox; p[3].y = baseline;
192 scr.drawLines(getGC(gc_copy), p, 4);
200 // In lyxf3 this will be just LaTeX
201 void InsetSpecialChar::Write(ostream & os)
205 case HYPHENATION: command = "\\-"; break;
206 case END_OF_SENTENCE: command = "\\@."; break;
207 case LDOTS: command = "\\ldots{}"; break;
208 case MENU_SEPARATOR: command = "\\menuseparator"; break;
210 os << "\\SpecialChar " << command << "\n";
214 // This function will not be necessary when lyx3
215 void InsetSpecialChar::Read(LyXLex & lex)
218 string command = lex.GetString();
220 if (command == "\\-")
222 else if (command == "\\@.")
223 kind = END_OF_SENTENCE;
224 else if (command == "\\ldots{}")
226 else if (command == "\\menuseparator")
227 kind = MENU_SEPARATOR;
229 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
233 int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/)
236 signed char dummy = 0;
237 Latex(command, dummy);
243 int InsetSpecialChar::Latex(string & file, signed char /*fragile*/)
246 case HYPHENATION: file += "\\-"; break;
247 case END_OF_SENTENCE: file += "\\@."; break;
248 case LDOTS: file += "\\ldots{}"; break;
249 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
255 int InsetSpecialChar::Linuxdoc(string & file)
258 case HYPHENATION: file += ""; break;
259 case END_OF_SENTENCE: file += ""; break;
260 case LDOTS: file += "..."; break;
261 case MENU_SEPARATOR: file += "->"; break;
267 int InsetSpecialChar::DocBook(string & file)
270 case HYPHENATION: file += ""; break;
271 case END_OF_SENTENCE: file += ""; break;
272 case LDOTS: file += "..."; break;
273 case MENU_SEPARATOR: file += "->"; 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;