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"
25 InsetSpecialChar::InsetSpecialChar(Kind k)
30 int InsetSpecialChar::ascent(Painter &, LyXFont const & font) const
32 return lyxfont::maxAscent(font);
36 int InsetSpecialChar::descent(Painter &, LyXFont const & font) const
38 return lyxfont::maxDescent(font);
42 int InsetSpecialChar::width(Painter &, LyXFont const & font) const
47 int w = lyxfont::width('-', font);
49 w -= 2; // to make it look shorter
54 return lyxfont::width('.', font);
58 return lyxfont::width(". . .", font);
62 return lyxfont::width(" x ", font);
64 case PROTECTED_SEPARATOR:
66 return lyxfont::width('x', font);
70 return 1; // To shut up gcc
74 void InsetSpecialChar::draw(Painter & pain, LyXFont const & f,
75 int baseline, float & x) const
81 font.setColor(LColor::special);
82 pain.text(int(x), baseline, "-", font);
83 x += width(pain, font);
88 font.setColor(LColor::special);
89 pain.text(int(x), baseline, ".", font);
90 x += width(pain, font);
95 font.setColor(LColor::special);
96 pain.text(int(x), baseline, ". . .", font);
97 x += width(pain, font);
102 // A triangle the width and height of an 'x'
103 int w = lyxfont::width('x', font);
104 int ox = lyxfont::width(' ', font) + int(x);
105 int h = lyxfont::ascent('x', font);
108 xp[0] = ox; yp[0] = baseline;
109 xp[1] = ox; yp[1] = baseline - h;
110 xp[2] = ox + w; yp[2] = baseline - h/2;
111 xp[3] = ox; yp[3] = baseline;
113 pain.lines(xp, yp, 4, LColor::special);
114 x += width(pain, font);
117 case PROTECTED_SEPARATOR:
119 float w = width(pain, font);
120 int h = lyxfont::ascent('x', font);
124 yp[0] = baseline - max(h / 4, 1);
133 yp[3] = baseline - max(h / 4, 1);
135 pain.lines(xp, yp, 4, LColor::special);
143 // In lyxf3 this will be just LaTeX
144 void InsetSpecialChar::Write(ostream & os) const
148 case HYPHENATION: command = "\\-"; break;
149 case END_OF_SENTENCE: command = "\\@."; break;
150 case LDOTS: command = "\\ldots{}"; break;
151 case MENU_SEPARATOR: command = "\\menuseparator"; break;
152 case PROTECTED_SEPARATOR:
153 //command = "\\protected_separator";
157 os << "\\SpecialChar " << command << "\n";
161 // This function will not be necessary when lyx3
162 void InsetSpecialChar::Read(LyXLex & lex)
165 string command = lex.GetString();
167 if (command == "\\-")
169 else if (command == "\\@.")
170 kind = END_OF_SENTENCE;
171 else if (command == "\\ldots{}")
173 else if (command == "\\menuseparator")
174 kind = MENU_SEPARATOR;
175 else if (command == "\\protected_separator"
177 kind = PROTECTED_SEPARATOR;
179 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
183 int InsetSpecialChar::Latex(ostream & os, bool /*fragile*/,
184 bool free_space) const
187 case HYPHENATION: os << "\\-"; break;
188 case END_OF_SENTENCE: os << "\\@."; break;
189 case LDOTS: os << "\\ldots{}"; break;
190 case MENU_SEPARATOR: os << "\\lyxarrow{}"; break;
191 case PROTECTED_SEPARATOR: os << (free_space ? " " : "~"); break;
196 int InsetSpecialChar::Ascii(ostream & os) const
199 case HYPHENATION: break;
200 case END_OF_SENTENCE: os << "."; break;
201 case LDOTS: os << "..."; break;
202 case MENU_SEPARATOR: os << "->"; break;
203 case PROTECTED_SEPARATOR: os << " "; break;
209 int InsetSpecialChar::Linuxdoc(ostream & os) const
215 int InsetSpecialChar::DocBook(ostream & os) const
221 Inset * InsetSpecialChar::Clone() const
223 return new InsetSpecialChar(kind);
227 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
229 if (kind == MENU_SEPARATOR) {
230 features.lyxarrow = true;