1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1997 Asger Alstrup
8 *======================================================*/
13 #pragma implementation
16 #include "insetspecialchar.h"
19 #include "LaTeXFeatures.h"
21 // $Id: insetspecialchar.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $
23 #if !defined(lint) && !defined(WITH_WARNINGS)
24 static char vcid[] = "$Id: insetspecialchar.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $";
27 InsetSpecialChar::InsetSpecialChar()
32 InsetSpecialChar::InsetSpecialChar(Kind k)
38 InsetSpecialChar::~InsetSpecialChar()
43 int InsetSpecialChar::Ascent(LyXFont const&font) const
45 return font.maxAscent();
49 int InsetSpecialChar::Descent(LyXFont const&font) const
51 return font.maxDescent();
55 int InsetSpecialChar::Width(LyXFont const&font) const
61 int w = f.textWidth("-", 1);
63 w -= 2; // to make it look shorter
68 return f.textWidth(".", 1);
72 return f.textWidth(". . .", 5);
74 case MENU_SEPARATOR: {
75 return f.textWidth(" x ", 3);
78 return 1; // To shut up gcc
82 void InsetSpecialChar::Draw(LyXFont font, LyXScreen &scr,
83 int baseline, float &x)
88 font.setColor(LyXFont::MAGENTA);
89 scr.drawText(font, "-", 1, baseline, int(x));
95 font.setColor(LyXFont::MAGENTA);
96 scr.drawText(font, ".", 1, baseline, int(x));
102 font.setColor(LyXFont::MAGENTA);
103 scr.drawText(font, ". . .", 5, baseline, int(x));
109 // A triangle the width and height of an 'x'
110 int w = font.textWidth("x", 1);
111 int ox = font.textWidth(" ", 1) + int(x);
112 int h = font.ascent('x');
114 p[0].x = ox; p[0].y = baseline;
115 p[1].x = ox; p[1].y = baseline - h;
116 p[2].x = ox + w;p[2].y = baseline - h/2;
117 p[3].x = ox; p[3].y = baseline;
118 scr.drawLines(getGC(gc_copy), p, 4);
125 // In lyxf3 this will be just LaTeX
126 void InsetSpecialChar::Write(FILE *file)
130 case HYPHENATION: command = "\\-"; break;
131 case END_OF_SENTENCE: command = "\\@."; break;
132 case LDOTS: command = "\\ldots{}"; break;
133 case MENU_SEPARATOR: command = "\\menuseparator"; break;
135 fprintf(file, "\\SpecialChar %s\n", command.c_str());
139 // This function will not be necessary when lyx3
140 void InsetSpecialChar::Read(LyXLex &lex)
143 LString command = lex.GetString();
147 else if (command=="\\@.")
148 kind = END_OF_SENTENCE;
149 else if (command=="\\ldots{}")
151 else if (command=="\\menuseparator")
152 kind = MENU_SEPARATOR;
154 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
158 int InsetSpecialChar::Latex(FILE *file, signed char /*fragile*/)
161 signed char dummy = 0;
162 Latex(command, dummy);
163 fprintf(file, "%s", command.c_str());
168 int InsetSpecialChar::Latex(LString &file, signed char /*fragile*/)
171 case HYPHENATION: file += "\\-"; break;
172 case END_OF_SENTENCE: file += "\\@."; break;
173 case LDOTS: file += "\\ldots{}"; break;
174 case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
180 int InsetSpecialChar::Linuxdoc(LString &file)
183 case HYPHENATION: file += ""; break;
184 case END_OF_SENTENCE: file += ""; break;
185 case LDOTS: file += "..."; break;
186 case MENU_SEPARATOR: file += "->"; break;
192 int InsetSpecialChar::DocBook(LString &file)
195 case HYPHENATION: file += ""; break;
196 case END_OF_SENTENCE: file += ""; break;
197 case LDOTS: file += "..."; break;
198 case MENU_SEPARATOR: file += "->"; break;
204 Inset* InsetSpecialChar::Clone()
206 InsetSpecialChar *result = new InsetSpecialChar(kind);
211 void InsetSpecialChar::Validate(LaTeXFeatures& features) const
213 if (kind == MENU_SEPARATOR) {
214 features.lyxarrow = true;