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
45 int w = f.textWidth("-", 1);
47 w -= 2; // to make it look shorter
52 return f.textWidth(".", 1);
56 return f.textWidth(". . .", 5);
58 case MENU_SEPARATOR: {
59 return f.textWidth(" x ", 3);
62 return 1; // To shut up gcc
66 void InsetSpecialChar::draw(Painter & pain, LyXFont const & f,
67 int baseline, float & x) const
73 font.setColor(LColor::special);
74 pain.text(int(x), baseline, "-", font);
75 x += width(pain, font);
80 font.setColor(LColor::special);
81 pain.text(int(x), baseline, ".", font);
82 x += width(pain, font);
87 font.setColor(LColor::special);
88 pain.text(int(x), baseline, ". . .", font);
89 x += width(pain, font);
94 // A triangle the width and height of an 'x'
95 int w = font.textWidth("x", 1);
96 int ox = font.textWidth(" ", 1) + int(x);
97 int h = font.ascent('x');
100 xp[0] = ox; yp[0] = baseline;
101 xp[1] = ox; yp[1] = baseline - h;
102 xp[2] = ox + w; yp[2] = baseline - h/2;
103 xp[3] = ox; yp[3] = baseline;
105 pain.lines(xp, yp, 4, LColor::special);
106 x += width(pain, font);
112 // In lyxf3 this will be just LaTeX
113 void InsetSpecialChar::Write(ostream & os)
117 case HYPHENATION: command = "\\-"; break;
118 case END_OF_SENTENCE: command = "\\@."; break;
119 case LDOTS: command = "\\ldots{}"; break;
120 case MENU_SEPARATOR: command = "\\menuseparator"; break;
122 os << "\\SpecialChar " << command << "\n";
126 // This function will not be necessary when lyx3
127 void InsetSpecialChar::Read(LyXLex & lex)
130 string command = lex.GetString();
132 if (command == "\\-")
134 else if (command == "\\@.")
135 kind = END_OF_SENTENCE;
136 else if (command == "\\ldots{}")
138 else if (command == "\\menuseparator")
139 kind = MENU_SEPARATOR;
141 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
145 int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/)
148 signed char dummy = 0;
149 Latex(command, dummy);
155 int InsetSpecialChar::Latex(string & file, signed char /*fragile*/)
158 case HYPHENATION: file += "\\-"; break;
159 case END_OF_SENTENCE: file += "\\@."; break;
160 case LDOTS: file += "\\ldots{}"; break;
161 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
167 int InsetSpecialChar::Linuxdoc(string & file)
170 case HYPHENATION: file += ""; break;
171 case END_OF_SENTENCE: file += ""; break;
172 case LDOTS: file += "..."; break;
173 case MENU_SEPARATOR: file += "->"; break;
179 int InsetSpecialChar::DocBook(string & file)
182 case HYPHENATION: file += ""; break;
183 case END_OF_SENTENCE: file += ""; break;
184 case LDOTS: file += "..."; break;
185 case MENU_SEPARATOR: file += "->"; break;
191 Inset * InsetSpecialChar::Clone() const
193 return new InsetSpecialChar(kind);
197 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
199 if (kind == MENU_SEPARATOR) {
200 features.lyxarrow = true;