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"
21 InsetSpecialChar::InsetSpecialChar(Kind k)
26 int InsetSpecialChar::Ascent(LyXFont const & font) const
28 return font.maxAscent();
32 int InsetSpecialChar::Descent(LyXFont const & font) const
34 return font.maxDescent();
38 int InsetSpecialChar::Width(LyXFont const & font) const
44 int w = f.textWidth("-", 1);
46 w -= 2; // to make it look shorter
51 return f.textWidth(".", 1);
55 return f.textWidth(". . .", 5);
57 case MENU_SEPARATOR: {
58 return f.textWidth(" x ", 3);
61 return 1; // To shut up gcc
65 void InsetSpecialChar::Draw(LyXFont font, LyXScreen & scr,
66 int baseline, float & x)
71 font.setColor(LyXFont::MAGENTA);
72 scr.drawText(font, "-", 1, baseline, int(x));
78 font.setColor(LyXFont::MAGENTA);
79 scr.drawText(font, ".", 1, baseline, int(x));
85 font.setColor(LyXFont::MAGENTA);
86 scr.drawText(font, ". . .", 5, baseline, int(x));
92 // A triangle the width and height of an 'x'
93 int w = font.textWidth("x", 1);
94 int ox = font.textWidth(" ", 1) + int(x);
95 int h = font.ascent('x');
97 p[0].x = ox; p[0].y = baseline;
98 p[1].x = ox; p[1].y = baseline - h;
99 p[2].x = ox + w;p[2].y = baseline - h/2;
100 p[3].x = ox; p[3].y = baseline;
101 scr.drawLines(getGC(gc_copy), p, 4);
108 // In lyxf3 this will be just LaTeX
109 void InsetSpecialChar::Write(ostream & os)
113 case HYPHENATION: command = "\\-"; break;
114 case END_OF_SENTENCE: command = "\\@."; break;
115 case LDOTS: command = "\\ldots{}"; break;
116 case MENU_SEPARATOR: command = "\\menuseparator"; break;
118 os << "\\SpecialChar " << command << "\n";
122 // This function will not be necessary when lyx3
123 void InsetSpecialChar::Read(LyXLex & lex)
126 string command = lex.GetString();
128 if (command == "\\-")
130 else if (command == "\\@.")
131 kind = END_OF_SENTENCE;
132 else if (command == "\\ldots{}")
134 else if (command == "\\menuseparator")
135 kind = MENU_SEPARATOR;
137 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
141 int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/)
144 signed char dummy = 0;
145 Latex(command, dummy);
151 int InsetSpecialChar::Latex(string & file, signed char /*fragile*/)
154 case HYPHENATION: file += "\\-"; break;
155 case END_OF_SENTENCE: file += "\\@."; break;
156 case LDOTS: file += "\\ldots{}"; break;
157 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
163 int InsetSpecialChar::Linuxdoc(string & file)
166 case HYPHENATION: file += ""; break;
167 case END_OF_SENTENCE: file += ""; break;
168 case LDOTS: file += "..."; break;
169 case MENU_SEPARATOR: file += "->"; break;
175 int InsetSpecialChar::DocBook(string & file)
178 case HYPHENATION: file += ""; break;
179 case END_OF_SENTENCE: file += ""; break;
180 case LDOTS: file += "..."; break;
181 case MENU_SEPARATOR: file += "->"; break;
187 Inset * InsetSpecialChar::Clone() const
189 return new InsetSpecialChar(kind);
193 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
195 if (kind == MENU_SEPARATOR) {
196 features.lyxarrow = true;