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"; break;
155 os << "\\SpecialChar " << command << "\n";
159 // This function will not be necessary when lyx3
160 void InsetSpecialChar::Read(LyXLex & lex)
163 string command = lex.GetString();
165 if (command == "\\-")
167 else if (command == "\\@.")
168 kind = END_OF_SENTENCE;
169 else if (command == "\\ldots{}")
171 else if (command == "\\menuseparator")
172 kind = MENU_SEPARATOR;
173 else if (command == "\\protected_separator")
174 kind = PROTECTED_SEPARATOR;
176 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
180 int InsetSpecialChar::Latex(ostream & os, bool /*fragile*/,
181 bool free_space) const
184 case HYPHENATION: os << "\\-"; break;
185 case END_OF_SENTENCE: os << "\\@."; break;
186 case LDOTS: os << "\\ldots{}"; break;
187 case MENU_SEPARATOR: os << "\\lyxarrow{}"; break;
188 case PROTECTED_SEPARATOR: os << (free_space ? " " : "~"); break;
193 int InsetSpecialChar::Ascii(ostream & os) const
196 case HYPHENATION: break;
197 case END_OF_SENTENCE: os << "."; break;
198 case LDOTS: os << "..."; break;
199 case MENU_SEPARATOR: os << "->"; break;
200 case PROTECTED_SEPARATOR: os << " "; break;
206 int InsetSpecialChar::Linuxdoc(ostream & os) const
212 int InsetSpecialChar::DocBook(ostream & os) const
218 Inset * InsetSpecialChar::Clone() const
220 return new InsetSpecialChar(kind);
224 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
226 if (kind == MENU_SEPARATOR) {
227 features.lyxarrow = true;