2 * \file insetspecialchar.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup Nielsen
7 * \author Jean-Marc Lasgouttes
8 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
15 #include "insetspecialchar.h"
18 #include "LaTeXFeatures.h"
21 #include "metricsinfo.h"
23 #include "frontends/Application.h"
24 #include "frontends/FontLoader.h"
25 #include "frontends/FontMetrics.h"
26 #include "frontends/Painter.h"
35 InsetSpecialChar::InsetSpecialChar(Kind k)
40 InsetSpecialChar::Kind InsetSpecialChar::kind() const
46 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
48 lyx::frontend::FontMetrics const & fm =
49 theApp->fontLoader().metrics(mi.base.font);
50 dim.asc = fm.maxAscent();
51 dim.des = fm.maxDescent();
55 case LIGATURE_BREAK: s = "|"; break;
56 case END_OF_SENTENCE: s = "."; break;
57 case LDOTS: s = ". . ."; break;
58 case MENU_SEPARATOR: s = " x "; break;
59 case HYPHENATION: s = "-"; break;
61 docstring ds(s.begin(), s.end());
62 dim.wid = fm.width(ds);
63 if (kind_ == HYPHENATION && dim.wid > 5)
64 dim.wid -= 2; // to make it look shorter
69 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
71 LyXFont font = pi.base.font;
76 font.setColor(LColor::special);
77 pi.pain.text(x, y, lyx::char_type('-'), font);
82 font.setColor(LColor::special);
83 pi.pain.text(x, y, lyx::char_type('|'), font);
88 font.setColor(LColor::special);
89 pi.pain.text(x, y, lyx::char_type('.'), font);
94 font.setColor(LColor::special);
95 string ell = ". . . ";
96 docstring dell(ell.begin(), ell.end());
97 pi.pain.text(x, y, dell, font);
102 lyx::frontend::FontMetrics const & fm =
103 theApp->fontLoader().metrics(font);
105 // A triangle the width and height of an 'x'
106 int w = fm.width(lyx::char_type('x'));
107 int ox = fm.width(lyx::char_type(' ')) + x;
108 int h = fm.ascent(lyx::char_type('x'));
111 xp[0] = ox; yp[0] = y;
112 xp[1] = ox; yp[1] = y - h;
113 xp[2] = ox + w; yp[2] = y - h/2;
114 xp[3] = ox; yp[3] = y;
116 pi.pain.lines(xp, yp, 4, LColor::special);
123 // In lyxf3 this will be just LaTeX
124 void InsetSpecialChar::write(Buffer const &, ostream & os) const
132 command = "\\textcompwordmark{}";
134 case END_OF_SENTENCE:
138 command = "\\ldots{}";
141 command = "\\menuseparator";
144 os << "\\SpecialChar " << command << "\n";
148 // This function will not be necessary when lyx3
149 void InsetSpecialChar::read(Buffer const &, LyXLex & lex)
152 string const command = lex.getString();
154 if (command == "\\-")
156 else if (command == "\\textcompwordmark{}")
157 kind_ = LIGATURE_BREAK;
158 else if (command == "\\@.")
159 kind_ = END_OF_SENTENCE;
160 else if (command == "\\ldots{}")
162 else if (command == "\\menuseparator")
163 kind_ = MENU_SEPARATOR;
165 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
169 int InsetSpecialChar::latex(Buffer const &, ostream & os,
170 OutputParams const &) const
177 os << "\\textcompwordmark{}";
179 case END_OF_SENTENCE:
186 os << "\\lyxarrow{}";
193 int InsetSpecialChar::plaintext(Buffer const &, ostream & os,
194 OutputParams const &) const
200 case END_OF_SENTENCE:
214 int InsetSpecialChar::docbook(Buffer const &, ostream & os,
215 OutputParams const &) const
221 case END_OF_SENTENCE:
235 int InsetSpecialChar::textString(Buffer const & buf, ostream & os,
236 OutputParams const & op) const
238 return plaintext(buf, os, op);
242 auto_ptr<InsetBase> InsetSpecialChar::doClone() const
244 return auto_ptr<InsetBase>(new InsetSpecialChar(kind_));
248 void InsetSpecialChar::validate(LaTeXFeatures & features) const
250 if (kind_ == MENU_SEPARATOR) {
251 features.require("lyxarrow");
256 bool InsetSpecialChar::isChar() const
262 bool InsetSpecialChar::isLetter() const
264 return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
268 bool InsetSpecialChar::isLineSeparator() const
271 // this would be nice, but it does not work, since
272 // Paragraph::stripLeadingSpaces nukes the characters which
273 // have this property. I leave the code here, since it should
274 // eventually be made to work. (JMarc 20020327)
275 return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;