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"
|
|
|
|
#include "lyxdraw.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
|
|
|
InsetSpecialChar::InsetSpecialChar(Kind k)
|
|
|
|
: kind(k)
|
1999-11-22 16:19:48 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetSpecialChar::Ascent(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return font.maxAscent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetSpecialChar::Descent(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return font.maxDescent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetSpecialChar::Width(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
LyXFont f = font;
|
|
|
|
switch (kind) {
|
|
|
|
case HYPHENATION:
|
|
|
|
{
|
|
|
|
int w = f.textWidth("-", 1);
|
|
|
|
if (w > 5)
|
|
|
|
w -= 2; // to make it look shorter
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
{
|
|
|
|
return f.textWidth(".", 1);
|
|
|
|
}
|
|
|
|
case LDOTS:
|
|
|
|
{
|
|
|
|
return f.textWidth(". . .", 5);
|
|
|
|
}
|
|
|
|
case MENU_SEPARATOR: {
|
|
|
|
return f.textWidth(" x ", 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1; // To shut up gcc
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetSpecialChar::Draw(LyXFont font, LyXScreen & scr,
|
|
|
|
int baseline, float & x)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
switch (kind) {
|
|
|
|
case HYPHENATION:
|
|
|
|
{
|
|
|
|
font.setColor(LyXFont::MAGENTA);
|
|
|
|
scr.drawText(font, "-", 1, baseline, int(x));
|
|
|
|
x += Width(font);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
{
|
|
|
|
font.setColor(LyXFont::MAGENTA);
|
|
|
|
scr.drawText(font, ".", 1, baseline, int(x));
|
|
|
|
x += Width(font);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LDOTS:
|
|
|
|
{
|
|
|
|
font.setColor(LyXFont::MAGENTA);
|
|
|
|
scr.drawText(font, ". . .", 5, baseline, int(x));
|
|
|
|
x += Width(font);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
{
|
|
|
|
// A triangle the width and height of an 'x'
|
|
|
|
int w = font.textWidth("x", 1);
|
|
|
|
int ox = font.textWidth(" ", 1) + int(x);
|
|
|
|
int h = font.ascent('x');
|
|
|
|
XPoint p[4];
|
|
|
|
p[0].x = ox; p[0].y = baseline;
|
|
|
|
p[1].x = ox; p[1].y = baseline - h;
|
|
|
|
p[2].x = ox + w;p[2].y = baseline - h/2;
|
|
|
|
p[3].x = ox; p[3].y = baseline;
|
|
|
|
scr.drawLines(getGC(gc_copy), p, 4);
|
|
|
|
x += Width(font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// In lyxf3 this will be just LaTeX
|
1999-12-07 00:44:53 +00:00
|
|
|
void InsetSpecialChar::Write(ostream & os)
|
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) {
|
|
|
|
case HYPHENATION: command = "\\-"; break;
|
|
|
|
case END_OF_SENTENCE: command = "\\@."; break;
|
|
|
|
case LDOTS: command = "\\ldots{}"; break;
|
|
|
|
case MENU_SEPARATOR: command = "\\menuseparator"; break;
|
|
|
|
}
|
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
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetSpecialChar::Read(LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
lex.nextToken();
|
1999-10-02 16:21:10 +00:00
|
|
|
string 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;
|
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;
|
|
|
|
else
|
|
|
|
lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/)
|
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
|
|
|
signed char dummy = 0;
|
|
|
|
Latex(command, dummy);
|
1999-12-07 00:44:53 +00:00
|
|
|
os << command;
|
1999-09-27 18:44:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetSpecialChar::Latex(string & file, signed char /*fragile*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
switch (kind) {
|
|
|
|
case HYPHENATION: file += "\\-"; break;
|
|
|
|
case END_OF_SENTENCE: file += "\\@."; break;
|
|
|
|
case LDOTS: file += "\\ldots{}"; break;
|
|
|
|
case MENU_SEPARATOR: file += "\\lyxarrow{}"; break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetSpecialChar::Linuxdoc(string & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
switch (kind) {
|
|
|
|
case HYPHENATION: file += ""; break;
|
|
|
|
case END_OF_SENTENCE: file += ""; break;
|
|
|
|
case LDOTS: file += "..."; break;
|
|
|
|
case MENU_SEPARATOR: file += "->"; break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetSpecialChar::DocBook(string & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
switch (kind) {
|
|
|
|
case HYPHENATION: file += ""; break;
|
|
|
|
case END_OF_SENTENCE: file += ""; break;
|
|
|
|
case LDOTS: file += "..."; break;
|
|
|
|
case MENU_SEPARATOR: file += "->"; break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
Inset * InsetSpecialChar::Clone() 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
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetSpecialChar::Validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (kind == MENU_SEPARATOR) {
|
|
|
|
features.lyxarrow = true;
|
|
|
|
}
|
|
|
|
}
|