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()
26 InsetSpecialChar::InsetSpecialChar(Kind k)
32 InsetSpecialChar::~InsetSpecialChar()
37 int InsetSpecialChar::Ascent(LyXFont const & font) const
39 return font.maxAscent();
43 int InsetSpecialChar::Descent(LyXFont const & font) const
45 return font.maxDescent();
49 int InsetSpecialChar::Width(LyXFont const & font) const
55 int w = f.textWidth("-", 1);
57 w -= 2; // to make it look shorter
62 return f.textWidth(".", 1);
66 return f.textWidth(". . .", 5);
68 case MENU_SEPARATOR: {
69 return f.textWidth(" x ", 3);
72 return 1; // To shut up gcc
76 void InsetSpecialChar::Draw(LyXFont font, LyXScreen & scr,
77 int baseline, float & x)
82 font.setColor(LyXFont::MAGENTA);
83 scr.drawText(font, "-", 1, baseline, int(x));
89 font.setColor(LyXFont::MAGENTA);
90 scr.drawText(font, ".", 1, baseline, int(x));
96 font.setColor(LyXFont::MAGENTA);
97 scr.drawText(font, ". . .", 5, baseline, int(x));
103 // A triangle the width and height of an 'x'
104 int w = font.textWidth("x", 1);
105 int ox = font.textWidth(" ", 1) + int(x);
106 int h = font.ascent('x');
108 p[0].x = ox; p[0].y = baseline;
109 p[1].x = ox; p[1].y = baseline - h;
110 p[2].x = ox + w;p[2].y = baseline - h/2;
111 p[3].x = ox; p[3].y = baseline;
112 scr.drawLines(getGC(gc_copy), p, 4);
119 // In lyxf3 this will be just LaTeX
120 void InsetSpecialChar::Write(FILE * file)
124 case HYPHENATION: command = "\\-"; break;
125 case END_OF_SENTENCE: command = "\\@."; break;
126 case LDOTS: command = "\\ldots{}"; break;
127 case MENU_SEPARATOR: command = "\\menuseparator"; break;
129 fprintf(file, "\\SpecialChar %s\n", command.c_str());
133 // This function will not be necessary when lyx3
134 void InsetSpecialChar::Read(LyXLex & lex)
137 string command = lex.GetString();
139 if (command == "\\-")
141 else if (command == "\\@.")
142 kind = END_OF_SENTENCE;
143 else if (command == "\\ldots{}")
145 else if (command == "\\menuseparator")
146 kind = MENU_SEPARATOR;
148 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
152 int InsetSpecialChar::Latex(FILE * file, signed char /*fragile*/)
155 signed char dummy = 0;
156 Latex(command, dummy);
157 fprintf(file, "%s", command.c_str());
162 int InsetSpecialChar::Latex(string & file, signed char /*fragile*/)
165 case HYPHENATION: file += "\\-"; break;
166 case END_OF_SENTENCE: file += "\\@."; break;
167 case LDOTS: file += "\\ldots{}"; break;
168 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
174 int InsetSpecialChar::Linuxdoc(string & file)
177 case HYPHENATION: file += ""; break;
178 case END_OF_SENTENCE: file += ""; break;
179 case LDOTS: file += "..."; break;
180 case MENU_SEPARATOR: file += "->"; break;
186 int InsetSpecialChar::DocBook(string & file)
189 case HYPHENATION: file += ""; break;
190 case END_OF_SENTENCE: file += ""; break;
191 case LDOTS: file += "..."; break;
192 case MENU_SEPARATOR: file += "->"; break;
198 Inset * InsetSpecialChar::Clone()
200 InsetSpecialChar * result = new InsetSpecialChar(kind);
205 void InsetSpecialChar::Validate(LaTeXFeatures & features) const
207 if (kind == MENU_SEPARATOR) {
208 features.lyxarrow = true;