2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetspecialchar.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Asger Alstrup Nielsen
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetspecialchar.h"
|
2003-05-19 17:03:12 +00:00
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2003-05-19 17:03:12 +00:00
|
|
|
|
#include "dimension.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2000-06-21 15:07:57 +00:00
|
|
|
|
#include "BufferView.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
|
#include "lyxlex.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "lyxfont.h"
|
2000-02-17 19:59:08 +00:00
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2000-03-06 16:05:12 +00:00
|
|
|
|
using std::max;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
InsetSpecialChar::InsetSpecialChar(Kind k)
|
2001-07-23 09:11:14 +00:00
|
|
|
|
: kind_(k)
|
1999-11-22 16:19:48 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
InsetSpecialChar::Kind InsetSpecialChar::kind() const
|
|
|
|
|
{
|
|
|
|
|
return kind_;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-11 15:01:29 +00:00
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
void InsetSpecialChar::dimension(BufferView *, LyXFont const & font,
|
|
|
|
|
Dimension & dim) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2003-05-19 17:03:12 +00:00
|
|
|
|
dim.a = font_metrics::maxAscent(font);
|
|
|
|
|
dim.d = font_metrics::maxDescent(font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-05-22 20:19:14 +00:00
|
|
|
|
string s;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
switch (kind_) {
|
2003-05-19 17:03:12 +00:00
|
|
|
|
case LIGATURE_BREAK: s = "|"; break;
|
|
|
|
|
case END_OF_SENTENCE: s = "."; break;
|
|
|
|
|
case LDOTS: s = ". . ."; break;
|
|
|
|
|
case MENU_SEPARATOR: s = " x "; break;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
case HYPHENATION: s = "-"; break;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2003-05-20 13:39:28 +00:00
|
|
|
|
dim.w = font_metrics::width(s, font);
|
2003-05-19 17:03:12 +00:00
|
|
|
|
if (kind_ == HYPHENATION && dim.w > 5)
|
|
|
|
|
dim.w -= 2; // to make it look shorter
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
|
2003-03-17 01:34:36 +00:00
|
|
|
|
int baseline, float & x) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2000-06-21 15:07:57 +00:00
|
|
|
|
Painter & pain = bv->painter();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
LyXFont font(f);
|
2000-06-21 15:07:57 +00:00
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
switch (kind_) {
|
2000-02-10 17:53:36 +00:00
|
|
|
|
case HYPHENATION:
|
|
|
|
|
{
|
2000-02-11 16:56:34 +00:00
|
|
|
|
font.setColor(LColor::special);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
pain.text(int(x), baseline, '-', font);
|
2000-07-05 14:57:48 +00:00
|
|
|
|
x += width(bv, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2001-07-20 13:04:36 +00:00
|
|
|
|
case LIGATURE_BREAK:
|
2001-07-20 09:38:19 +00:00
|
|
|
|
{
|
|
|
|
|
font.setColor(LColor::special);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
pain.text(int(x), baseline, '|', font);
|
2001-07-20 09:38:19 +00:00
|
|
|
|
x += width(bv, font);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
|
{
|
2000-02-11 16:56:34 +00:00
|
|
|
|
font.setColor(LColor::special);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
pain.text(int(x), baseline, '.', font);
|
2000-07-05 14:57:48 +00:00
|
|
|
|
x += width(bv, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case LDOTS:
|
|
|
|
|
{
|
2000-02-11 16:56:34 +00:00
|
|
|
|
font.setColor(LColor::special);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
pain.text(int(x), baseline, ". . .", font);
|
2000-07-05 14:57:48 +00:00
|
|
|
|
x += width(bv, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
|
{
|
|
|
|
|
// A triangle the width and height of an 'x'
|
2002-05-24 14:34:32 +00:00
|
|
|
|
int w = font_metrics::width('x', font);
|
|
|
|
|
int ox = font_metrics::width(' ', font) + int(x);
|
|
|
|
|
int h = font_metrics::ascent('x', font);
|
2000-02-11 16:56:34 +00:00
|
|
|
|
int xp[4], yp[4];
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-02-11 16:56:34 +00:00
|
|
|
|
xp[0] = ox; yp[0] = baseline;
|
|
|
|
|
xp[1] = ox; yp[1] = baseline - h;
|
|
|
|
|
xp[2] = ox + w; yp[2] = baseline - h/2;
|
|
|
|
|
xp[3] = ox; yp[3] = baseline;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-02-11 16:56:34 +00:00
|
|
|
|
pain.lines(xp, yp, 4, LColor::special);
|
2000-07-05 14:57:48 +00:00
|
|
|
|
x += width(bv, font);
|
2000-02-29 02:19:17 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// In lyxf3 this will be just LaTeX
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetSpecialChar::write(Buffer const *, ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string command;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
switch (kind_) {
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case HYPHENATION:
|
|
|
|
|
command = "\\-";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case LIGATURE_BREAK:
|
|
|
|
|
command = "\\textcompwordmark{}";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case END_OF_SENTENCE:
|
2001-07-20 09:38:19 +00:00
|
|
|
|
command = "\\@.";
|
|
|
|
|
break;
|
|
|
|
|
case LDOTS:
|
2002-03-21 17:09:55 +00:00
|
|
|
|
command = "\\ldots{}";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case MENU_SEPARATOR:
|
2002-03-21 17:09:55 +00:00
|
|
|
|
command = "\\menuseparator";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "\\SpecialChar " << command << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This function will not be necessary when lyx3
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetSpecialChar::read(Buffer const *, LyXLex & lex)
|
2002-03-21 17:09:55 +00:00
|
|
|
|
{
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.nextToken();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const command = lex.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-15 10:58:38 +00:00
|
|
|
|
if (command == "\\-")
|
2001-07-23 09:11:14 +00:00
|
|
|
|
kind_ = HYPHENATION;
|
2001-07-20 09:38:19 +00:00
|
|
|
|
else if (command == "\\textcompwordmark{}")
|
2001-07-23 09:11:14 +00:00
|
|
|
|
kind_ = LIGATURE_BREAK;
|
1999-11-15 10:58:38 +00:00
|
|
|
|
else if (command == "\\@.")
|
2001-07-23 09:11:14 +00:00
|
|
|
|
kind_ = END_OF_SENTENCE;
|
1999-11-15 10:58:38 +00:00
|
|
|
|
else if (command == "\\ldots{}")
|
2001-07-23 09:11:14 +00:00
|
|
|
|
kind_ = LDOTS;
|
1999-11-15 10:58:38 +00:00
|
|
|
|
else if (command == "\\menuseparator")
|
2002-03-21 17:09:55 +00:00
|
|
|
|
kind_ = MENU_SEPARATOR;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
|
|
|
|
lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-22 22:44:30 +00:00
|
|
|
|
int InsetSpecialChar::latex(Buffer const *, ostream & os,
|
|
|
|
|
LatexRunParams const &,
|
|
|
|
|
bool free_space) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-23 09:11:14 +00:00
|
|
|
|
switch (kind_) {
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case HYPHENATION:
|
|
|
|
|
os << "\\-";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2001-07-20 13:04:36 +00:00
|
|
|
|
case LIGATURE_BREAK:
|
2001-07-20 09:38:19 +00:00
|
|
|
|
os << "\\textcompwordmark{}";
|
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
|
os << "\\@.";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case LDOTS:
|
|
|
|
|
os << "\\ldots{}";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
|
os << "\\lyxarrow{}";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2000-03-02 02:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
|
|
|
|
|
int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2001-07-23 09:11:14 +00:00
|
|
|
|
switch (kind_) {
|
2001-07-20 09:38:19 +00:00
|
|
|
|
case HYPHENATION:
|
2001-07-20 13:04:36 +00:00
|
|
|
|
case LIGATURE_BREAK:
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case END_OF_SENTENCE:
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '.';
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case LDOTS:
|
|
|
|
|
os << "...";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
|
os << "->";
|
2001-07-20 09:38:19 +00:00
|
|
|
|
break;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-14 09:46:05 +00:00
|
|
|
|
int InsetSpecialChar::linuxdoc(Buffer const *, ostream & os) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2001-10-23 09:42:14 +00:00
|
|
|
|
switch (kind_) {
|
|
|
|
|
case HYPHENATION:
|
|
|
|
|
case LIGATURE_BREAK:
|
|
|
|
|
break;
|
|
|
|
|
case END_OF_SENTENCE:
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '.';
|
2001-10-23 09:42:14 +00:00
|
|
|
|
break;
|
|
|
|
|
case LDOTS:
|
2002-03-21 17:09:55 +00:00
|
|
|
|
os << "...";
|
2001-10-23 09:42:14 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
|
os << "&lyxarrow;";
|
2001-10-23 09:42:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2000-04-24 20:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int InsetSpecialChar::docbook(Buffer const *, ostream & os, bool) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2001-10-23 09:42:14 +00:00
|
|
|
|
switch (kind_) {
|
|
|
|
|
case HYPHENATION:
|
|
|
|
|
case LIGATURE_BREAK:
|
|
|
|
|
break;
|
|
|
|
|
case END_OF_SENTENCE:
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '.';
|
2001-10-23 09:42:14 +00:00
|
|
|
|
break;
|
|
|
|
|
case LDOTS:
|
2002-03-21 17:09:55 +00:00
|
|
|
|
os << "...";
|
2001-10-23 09:42:14 +00:00
|
|
|
|
break;
|
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
|
os << "&lyxarrow;";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
Inset * InsetSpecialChar::clone(Buffer const &, bool) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-23 09:11:14 +00:00
|
|
|
|
return new InsetSpecialChar(kind_);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetSpecialChar::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-23 09:11:14 +00:00
|
|
|
|
if (kind_ == MENU_SEPARATOR) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("lyxarrow");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-13 14:47:35 +00:00
|
|
|
|
|
|
|
|
|
|
2002-01-08 14:24:49 +00:00
|
|
|
|
bool InsetSpecialChar::isChar() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-13 14:47:35 +00:00
|
|
|
|
bool InsetSpecialChar::isLetter() const
|
|
|
|
|
{
|
|
|
|
|
return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetSpecialChar::isSpace() const
|
|
|
|
|
{
|
2003-05-22 10:40:57 +00:00
|
|
|
|
return false;
|
2001-11-13 14:47:35 +00:00
|
|
|
|
}
|
2002-02-13 10:37:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetSpecialChar::isLineSeparator() const
|
|
|
|
|
{
|
2002-03-27 00:05:28 +00:00
|
|
|
|
#if 0
|
|
|
|
|
// this would be nice, but it does not work, since
|
|
|
|
|
// Paragraph::stripLeadingSpaces nukes the characters which
|
|
|
|
|
// have this property. I leave the code here, since it should
|
|
|
|
|
// eventually be made to work. (JMarc 20020327)
|
2002-02-13 10:37:28 +00:00
|
|
|
|
return kind_ == HYPHENATION || kind_ == MENU_SEPARATOR;
|
2002-03-27 00:05:28 +00:00
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
2002-02-13 10:37:28 +00:00
|
|
|
|
}
|