1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1997 Asger Alstrup
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 10:58:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetspecialchar.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2000-06-21 15:07:57 +00:00
|
|
|
#include "BufferView.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
#include "Painter.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
#include "font.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
|
|
|
|
|
|
|
InsetSpecialChar::InsetSpecialChar(Kind k)
|
|
|
|
: kind(k)
|
1999-11-22 16:19:48 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::maxAscent(font);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetSpecialChar::descent(BufferView *, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::maxDescent(font);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetSpecialChar::width(BufferView *, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
switch (kind) {
|
|
|
|
case HYPHENATION:
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
int w = lyxfont::width('-', font);
|
2000-02-10 17:53:36 +00:00
|
|
|
if (w > 5)
|
|
|
|
w -= 2; // to make it look shorter
|
|
|
|
return w;
|
|
|
|
}
|
2001-07-20 09:38:19 +00:00
|
|
|
case HYPHENATION_BREAK:
|
|
|
|
{
|
|
|
|
return lyxfont::width('|', font);
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
case END_OF_SENTENCE:
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::width('.', font);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
case LDOTS:
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::width(". . .", font);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2000-02-29 02:19:17 +00:00
|
|
|
case MENU_SEPARATOR:
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::width(" x ", font);
|
2000-02-29 02:19:17 +00:00
|
|
|
}
|
|
|
|
case PROTECTED_SEPARATOR:
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::width('x', font);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2000-02-29 02:19:17 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
return 1; // To shut up gcc
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
|
2000-06-23 15:02:46 +00:00
|
|
|
int baseline, float & x, bool) 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
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
switch (kind) {
|
|
|
|
case HYPHENATION:
|
|
|
|
{
|
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;
|
|
|
|
}
|
2001-07-20 09:38:19 +00:00
|
|
|
case HYPHENATION_BREAK:
|
|
|
|
{
|
|
|
|
font.setColor(LColor::special);
|
|
|
|
pain.text(int(x), baseline, "|", font);
|
|
|
|
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);
|
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 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'
|
2000-04-04 00:19:15 +00:00
|
|
|
int w = lyxfont::width('x', font);
|
|
|
|
int ox = lyxfont::width(' ', font) + int(x);
|
|
|
|
int h = lyxfont::ascent('x', font);
|
2000-02-11 16:56:34 +00:00
|
|
|
int xp[4], yp[4];
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
case PROTECTED_SEPARATOR:
|
|
|
|
{
|
2000-07-05 14:57:48 +00:00
|
|
|
float w = width(bv, font);
|
2000-04-04 00:19:15 +00:00
|
|
|
int h = lyxfont::ascent('x', font);
|
2000-02-29 02:19:17 +00:00
|
|
|
int xp[4], yp[4];
|
|
|
|
|
|
|
|
xp[0] = int(x);
|
|
|
|
yp[0] = baseline - max(h / 4, 1);
|
|
|
|
|
|
|
|
xp[1] = int(x);
|
|
|
|
yp[1] = baseline;
|
|
|
|
|
|
|
|
xp[2] = int(x + w);
|
|
|
|
yp[2] = baseline;
|
|
|
|
|
|
|
|
xp[3] = int(x + w);
|
|
|
|
yp[3] = baseline - max(h / 4, 1);
|
|
|
|
|
|
|
|
pain.lines(xp, yp, 4, LColor::special);
|
|
|
|
x += w;
|
|
|
|
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;
|
1999-09-27 18:44:28 +00:00
|
|
|
switch (kind) {
|
2001-07-20 09:38:19 +00:00
|
|
|
case HYPHENATION:
|
|
|
|
command = "\\-";
|
|
|
|
break;
|
|
|
|
case HYPHENATION_BREAK:
|
|
|
|
command = "\\textcompwordmark{}";
|
|
|
|
break;
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
command = "\\@.";
|
|
|
|
break;
|
|
|
|
case LDOTS:
|
|
|
|
command = "\\ldots{}";
|
|
|
|
break;
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
command = "\\menuseparator";
|
|
|
|
break;
|
2000-02-29 02:19:17 +00:00
|
|
|
case PROTECTED_SEPARATOR:
|
2000-05-05 08:44:11 +00:00
|
|
|
//command = "\\protected_separator";
|
|
|
|
command = "~";
|
|
|
|
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)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
lex.nextToken();
|
2001-05-29 09:50:02 +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 == "\\-")
|
1999-09-27 18:44:28 +00:00
|
|
|
kind = HYPHENATION;
|
2001-07-20 09:38:19 +00:00
|
|
|
else if (command == "\\textcompwordmark{}")
|
|
|
|
kind = HYPHENATION_BREAK;
|
1999-11-15 10:58:38 +00:00
|
|
|
else if (command == "\\@.")
|
1999-09-27 18:44:28 +00:00
|
|
|
kind = END_OF_SENTENCE;
|
1999-11-15 10:58:38 +00:00
|
|
|
else if (command == "\\ldots{}")
|
1999-09-27 18:44:28 +00:00
|
|
|
kind = LDOTS;
|
1999-11-15 10:58:38 +00:00
|
|
|
else if (command == "\\menuseparator")
|
1999-09-27 18:44:28 +00:00
|
|
|
kind = MENU_SEPARATOR;
|
2000-05-05 08:44:11 +00:00
|
|
|
else if (command == "\\protected_separator"
|
|
|
|
|| command == "~")
|
2000-02-29 02:19:17 +00:00
|
|
|
kind = PROTECTED_SEPARATOR;
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
|
|
|
lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetSpecialChar::latex(Buffer const *, ostream & os, bool /*fragile*/,
|
2000-03-09 03:36:48 +00:00
|
|
|
bool free_space) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-02 02:19:43 +00:00
|
|
|
switch (kind) {
|
2001-07-20 09:38:19 +00:00
|
|
|
case HYPHENATION:
|
|
|
|
os << "\\-";
|
|
|
|
break;
|
|
|
|
case HYPHENATION_BREAK:
|
|
|
|
os << "\\textcompwordmark{}";
|
|
|
|
break;
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
os << "\\@.";
|
|
|
|
break;
|
|
|
|
case LDOTS:
|
|
|
|
os << "\\ldots{}";
|
|
|
|
break;
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
os << "\\lyxarrow{}";
|
|
|
|
break;
|
|
|
|
case PROTECTED_SEPARATOR:
|
|
|
|
os << (free_space ? " " : "~");
|
|
|
|
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
|
|
|
{
|
|
|
|
switch (kind) {
|
2001-07-20 09:38:19 +00:00
|
|
|
case HYPHENATION:
|
|
|
|
case HYPHENATION_BREAK:
|
|
|
|
break;
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
os << ".";
|
|
|
|
break;
|
|
|
|
case LDOTS:
|
|
|
|
os << "...";
|
|
|
|
break;
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
os << "->";
|
|
|
|
break;
|
|
|
|
case PROTECTED_SEPARATOR:
|
|
|
|
os << " ";
|
|
|
|
break;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetSpecialChar::linuxdoc(Buffer const * buf, ostream & os) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
return ascii(buf, os, 0);
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetSpecialChar::docBook(Buffer const * buf, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
return ascii(buf, os, 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
|
|
|
{
|
1999-11-22 16:19:48 +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
|
|
|
{
|
|
|
|
if (kind == MENU_SEPARATOR) {
|
|
|
|
features.lyxarrow = true;
|
|
|
|
}
|
|
|
|
}
|