2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetSpecialChar.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* 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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetSpecialChar.h"
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "Dimension.h"
|
2009-01-11 08:31:52 +00:00
|
|
|
#include "Font.h"
|
2018-07-15 18:56:55 +00:00
|
|
|
#include "Language.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2009-11-25 22:04:41 +00:00
|
|
|
#include "output_xhtml.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2000-02-17 19:59:08 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2019-05-07 08:47:49 +00:00
|
|
|
#include "frontends/NullPainter.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-28 22:12:03 +00:00
|
|
|
#include "support/docstream.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
namespace lyx {
|
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)
|
2009-11-08 15:53:21 +00:00
|
|
|
: Inset(0), 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
|
|
|
|
2017-03-06 13:49:30 +00:00
|
|
|
docstring InsetSpecialChar::toolTip(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
docstring message;
|
|
|
|
switch (kind_) {
|
|
|
|
case ALLOWBREAK:
|
|
|
|
message = from_ascii("Optional Line Break (ZWSP)");
|
|
|
|
break;
|
|
|
|
case LIGATURE_BREAK:
|
|
|
|
message = from_ascii("Ligature Break (ZWNJ)");
|
|
|
|
break;
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
message = from_ascii("End of Sentence");
|
|
|
|
break;
|
|
|
|
case HYPHENATION:
|
|
|
|
message = from_ascii("Hyphenation Point");
|
|
|
|
break;
|
|
|
|
case SLASH:
|
|
|
|
message = from_ascii("Breakable Slash");
|
|
|
|
break;
|
|
|
|
case NOBREAKDASH:
|
|
|
|
message = from_ascii("Protected Hyphen (SHY)");
|
|
|
|
break;
|
2017-04-25 17:03:20 +00:00
|
|
|
case LDOTS:
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
case PHRASE_LYX:
|
|
|
|
case PHRASE_TEX:
|
|
|
|
case PHRASE_LATEX2E:
|
|
|
|
case PHRASE_LATEX:
|
|
|
|
// no tooltip for these ones.
|
2017-04-25 16:42:55 +00:00
|
|
|
break;
|
2017-03-06 13:49:30 +00:00
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2015-03-13 11:05:15 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-03-19 16:26:25 +00:00
|
|
|
// helper function: draw text and update x.
|
|
|
|
void drawChar(PainterInfo & pi, int & x, int const y, char_type ch)
|
|
|
|
{
|
2016-10-25 13:13:23 +00:00
|
|
|
FontInfo font = pi.base.font;
|
|
|
|
font.setPaintColor(pi.textColor(font.realColor()));
|
|
|
|
pi.pain.text(x, y, ch, font);
|
|
|
|
x += theFontMetrics(font).width(ch);
|
2016-03-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void drawLogo(PainterInfo & pi, int & x, int const y, InsetSpecialChar::Kind kind)
|
|
|
|
{
|
2015-03-13 11:05:15 +00:00
|
|
|
FontInfo const & font = pi.base.font;
|
2015-03-26 15:55:19 +00:00
|
|
|
int const em = theFontMetrics(font).em();
|
2015-03-13 11:05:15 +00:00
|
|
|
switch (kind) {
|
|
|
|
case InsetSpecialChar::PHRASE_LYX:
|
2015-03-15 17:21:01 +00:00
|
|
|
/** Reference macro:
|
|
|
|
* \providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\\@};
|
|
|
|
*/
|
2016-03-19 16:26:25 +00:00
|
|
|
drawChar(pi, x, y, 'L');
|
2015-03-18 10:32:49 +00:00
|
|
|
x -= em / 6;
|
2016-03-19 16:26:25 +00:00
|
|
|
drawChar(pi, x, y + em / 4, 'Y');
|
2015-03-18 10:32:49 +00:00
|
|
|
x -= em / 8;
|
2016-03-19 16:26:25 +00:00
|
|
|
drawChar(pi, x, y, 'X');
|
2015-03-13 11:05:15 +00:00
|
|
|
break;
|
|
|
|
|
2015-03-15 17:21:01 +00:00
|
|
|
case InsetSpecialChar::PHRASE_TEX: {
|
|
|
|
/** Reference macro:
|
|
|
|
* \def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
|
|
|
|
*/
|
2018-07-19 20:16:40 +00:00
|
|
|
int const ex = theFontMetrics(font).xHeight();
|
2016-03-19 16:26:25 +00:00
|
|
|
drawChar(pi, x, y, 'T');
|
2015-03-18 10:32:49 +00:00
|
|
|
x -= em / 6;
|
2016-03-19 16:26:25 +00:00
|
|
|
drawChar(pi, x, y + ex / 2, 'E');
|
2015-03-18 10:32:49 +00:00
|
|
|
x -= em / 8;
|
2016-03-19 16:26:25 +00:00
|
|
|
drawChar(pi, x, y, 'X');
|
2015-03-13 11:05:15 +00:00
|
|
|
break;
|
2015-03-15 17:21:01 +00:00
|
|
|
}
|
2015-03-13 11:05:15 +00:00
|
|
|
case InsetSpecialChar::PHRASE_LATEX2E:
|
2015-03-15 17:21:01 +00:00
|
|
|
/** Reference macro:
|
|
|
|
* \DeclareRobustCommand{\LaTeXe}{\mbox{\m@th
|
|
|
|
* \if b\expandafter\@car\f@series\@nil\boldmath\fi
|
|
|
|
* \LaTeX\kern.15em2$_{\textstyle\varepsilon}$}}
|
|
|
|
*/
|
2016-03-19 16:26:25 +00:00
|
|
|
drawLogo(pi, x, y, InsetSpecialChar::PHRASE_LATEX);
|
2015-03-18 10:32:49 +00:00
|
|
|
x += 3 * em / 20;
|
2016-03-19 16:26:25 +00:00
|
|
|
drawChar(pi, x, y, '2');
|
|
|
|
drawChar(pi, x, y + em / 4, char_type(0x03b5));
|
2015-03-13 11:05:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InsetSpecialChar::PHRASE_LATEX: {
|
2015-03-15 17:21:01 +00:00
|
|
|
/** Reference macro:
|
|
|
|
* \DeclareRobustCommand{\LaTeX}{L\kern-.36em%
|
|
|
|
* {\sbox\z@ T%
|
|
|
|
* \vbox to\ht\z@{\hbox{\check@mathfonts
|
|
|
|
* \fontsize\sf@size\z@
|
|
|
|
* \math@fontsfalse\selectfont
|
|
|
|
* A}%
|
|
|
|
* \vss}%
|
|
|
|
* }%
|
|
|
|
* \kern-.15em%
|
|
|
|
* \TeX}
|
|
|
|
*/
|
2016-03-19 16:26:25 +00:00
|
|
|
drawChar(pi, x, y, 'L');
|
2015-03-18 10:32:49 +00:00
|
|
|
x -= 9 * em / 25;
|
2016-03-19 16:26:25 +00:00
|
|
|
PainterInfo pi2 = pi;
|
|
|
|
pi2.base.font.decSize().decSize();
|
|
|
|
drawChar(pi2, x, y - em / 5, 'A');
|
2015-03-18 10:32:49 +00:00
|
|
|
x -= 3 * em / 20;
|
2016-03-19 16:26:25 +00:00
|
|
|
drawLogo(pi, x, y, InsetSpecialChar::PHRASE_TEX);
|
2015-03-13 11:05:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
LYXERR0("No information for drawing logo " << kind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2015-03-13 11:05:15 +00:00
|
|
|
|
2019-05-07 08:47:49 +00:00
|
|
|
|
|
|
|
void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
{
|
|
|
|
frontend::FontMetrics const & fm =
|
|
|
|
theFontMetrics(mi.base.font);
|
|
|
|
dim.asc = fm.maxAscent();
|
|
|
|
dim.des = 0;
|
|
|
|
dim.wid = 0;
|
|
|
|
|
|
|
|
docstring s;
|
|
|
|
switch (kind_) {
|
|
|
|
case ALLOWBREAK:
|
|
|
|
dim.asc = fm.xHeight();
|
|
|
|
dim.des = fm.descent('g');
|
|
|
|
dim.wid = fm.em() / 8;
|
|
|
|
break;
|
|
|
|
case LIGATURE_BREAK:
|
|
|
|
s = from_ascii("|");
|
|
|
|
break;
|
|
|
|
case END_OF_SENTENCE:
|
|
|
|
s = from_ascii(".");
|
|
|
|
break;
|
|
|
|
case LDOTS:
|
|
|
|
s = from_ascii(". . .");
|
|
|
|
break;
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
// ▹ U+25B9 WHITE RIGHT-POINTING SMALL TRIANGLE
|
|
|
|
// There is a \thinspace on each side of the triangle
|
|
|
|
dim.wid = 2 * fm.em() / 6 + fm.width(char_type(0x25B9));
|
|
|
|
break;
|
|
|
|
case HYPHENATION:
|
|
|
|
dim.wid = fm.width(from_ascii("-"));
|
|
|
|
if (dim.wid > 5)
|
|
|
|
dim.wid -= 2; // to make it look shorter
|
|
|
|
break;
|
|
|
|
case SLASH:
|
|
|
|
s = from_ascii("/");
|
|
|
|
dim.des = fm.descent(s[0]);
|
|
|
|
break;
|
|
|
|
case NOBREAKDASH:
|
|
|
|
s = from_ascii("-");
|
|
|
|
break;
|
|
|
|
case PHRASE_LYX:
|
|
|
|
case PHRASE_TEX:
|
|
|
|
case PHRASE_LATEX2E:
|
|
|
|
case PHRASE_LATEX:
|
|
|
|
dim.asc = fm.maxAscent();
|
|
|
|
dim.des = fm.maxDescent();
|
|
|
|
frontend::NullPainter np;
|
|
|
|
PainterInfo pi(mi.base.bv, np);
|
|
|
|
drawLogo(pi, dim.wid, 0, kind_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dim.wid == 0)
|
|
|
|
dim.wid = fm.width(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo font = pi.base.font;
|
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:
|
|
|
|
{
|
2007-10-25 12:41:02 +00:00
|
|
|
font.setColor(Color_special);
|
2006-10-21 00:16:43 +00:00
|
|
|
pi.pain.text(x, y, char_type('-'), font);
|
2000-02-10 17:53:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-06 13:49:30 +00:00
|
|
|
case ALLOWBREAK:
|
|
|
|
{
|
|
|
|
// A small vertical line
|
2018-07-19 20:16:40 +00:00
|
|
|
int const asc = theFontMetrics(pi.base.font).xHeight();
|
2017-03-06 13:49:30 +00:00
|
|
|
int const desc = theFontMetrics(pi.base.font).descent('g');
|
|
|
|
int const x0 = x; // x + 1; // FIXME: incline,
|
|
|
|
int const x1 = x; // x - 1; // similar to LibreOffice?
|
|
|
|
int const y0 = y + desc;
|
|
|
|
int const y1 = y - asc / 3;
|
|
|
|
pi.pain.line(x0, y1, x1, y0, Color_special);
|
|
|
|
break;
|
|
|
|
}
|
2001-07-20 13:04:36 +00:00
|
|
|
case LIGATURE_BREAK:
|
2001-07-20 09:38:19 +00:00
|
|
|
{
|
2007-10-25 12:41:02 +00:00
|
|
|
font.setColor(Color_special);
|
2006-10-21 00:16:43 +00:00
|
|
|
pi.pain.text(x, y, char_type('|'), font);
|
2001-07-20 09:38:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
case END_OF_SENTENCE:
|
|
|
|
{
|
2007-10-25 12:41:02 +00:00
|
|
|
font.setColor(Color_special);
|
2006-10-21 00:16:43 +00:00
|
|
|
pi.pain.text(x, y, char_type('.'), font);
|
2000-02-10 17:53:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LDOTS:
|
|
|
|
{
|
2007-10-25 12:41:02 +00:00
|
|
|
font.setColor(Color_special);
|
2007-05-28 22:27:45 +00:00
|
|
|
string ell = ". . . ";
|
|
|
|
docstring dell(ell.begin(), ell.end());
|
2006-08-13 22:54:59 +00:00
|
|
|
pi.pain.text(x, y, dell, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
frontend::FontMetrics const & fm =
|
2006-10-11 17:24:46 +00:00
|
|
|
theFontMetrics(font);
|
2006-10-07 16:15:06 +00:00
|
|
|
|
2018-07-19 21:05:00 +00:00
|
|
|
// There is a \thinspace on each side of the triangle
|
|
|
|
x += fm.em() / 6;
|
|
|
|
// ▹ U+25B9 WHITE RIGHT-POINTING SMALL TRIANGLE
|
|
|
|
// ◃ U+25C3 WHITE LEFT-POINTING SMALL TRIANGLE
|
|
|
|
char_type const c = pi.ltr_pos ? 0x25B9 : 0x25C3;
|
|
|
|
font.setColor(Color_special);
|
|
|
|
pi.pain.text(x, y, c, font);
|
2000-02-29 02:19:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-12-06 11:04:56 +00:00
|
|
|
case SLASH:
|
|
|
|
{
|
|
|
|
font.setColor(Color_special);
|
|
|
|
pi.pain.text(x, y, char_type('/'), font);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NOBREAKDASH:
|
|
|
|
{
|
|
|
|
font.setColor(Color_latex);
|
|
|
|
pi.pain.text(x, y, char_type('-'), font);
|
|
|
|
break;
|
|
|
|
}
|
2015-03-01 10:16:57 +00:00
|
|
|
case PHRASE_LYX:
|
|
|
|
case PHRASE_TEX:
|
|
|
|
case PHRASE_LATEX2E:
|
|
|
|
case PHRASE_LATEX:
|
2016-03-19 16:26:25 +00:00
|
|
|
drawLogo(pi, x, y, kind_);
|
2015-03-01 10:16:57 +00:00
|
|
|
break;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetSpecialChar::write(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:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "softhyphen";
|
2001-07-20 09:38:19 +00:00
|
|
|
break;
|
2017-03-06 13:49:30 +00:00
|
|
|
case ALLOWBREAK:
|
|
|
|
command = "allowbreak";
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
case LIGATURE_BREAK:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "ligaturebreak";
|
2001-07-20 09:38:19 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
case END_OF_SENTENCE:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "endofsentence";
|
2001-07-20 09:38:19 +00:00
|
|
|
break;
|
|
|
|
case LDOTS:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "ldots";
|
2001-07-20 09:38:19 +00:00
|
|
|
break;
|
|
|
|
case MENU_SEPARATOR:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "menuseparator";
|
2001-07-20 09:38:19 +00:00
|
|
|
break;
|
2007-12-06 11:04:56 +00:00
|
|
|
case SLASH:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "breakableslash";
|
2007-12-06 11:04:56 +00:00
|
|
|
break;
|
|
|
|
case NOBREAKDASH:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "nobreakdash";
|
2007-12-06 11:04:56 +00:00
|
|
|
break;
|
2015-03-01 10:16:57 +00:00
|
|
|
case PHRASE_LYX:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "LyX";
|
2015-03-01 10:16:57 +00:00
|
|
|
break;
|
|
|
|
case PHRASE_TEX:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "TeX";
|
2015-03-01 10:16:57 +00:00
|
|
|
break;
|
|
|
|
case PHRASE_LATEX2E:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "LaTeX2e";
|
2015-03-01 10:16:57 +00:00
|
|
|
break;
|
|
|
|
case PHRASE_LATEX:
|
2015-03-23 20:28:04 +00:00
|
|
|
command = "LaTeX";
|
2015-03-01 10:16:57 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetSpecialChar::read(Lexer & lex)
|
2002-03-21 17:09:55 +00:00
|
|
|
{
|
2004-10-05 12:56:22 +00:00
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
string const command = lex.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2015-03-23 20:28:04 +00:00
|
|
|
if (command == "softhyphen")
|
2001-07-23 09:11:14 +00:00
|
|
|
kind_ = HYPHENATION;
|
2017-03-06 13:49:30 +00:00
|
|
|
else if (command == "allowbreak")
|
|
|
|
kind_ = ALLOWBREAK;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "ligaturebreak")
|
2001-07-23 09:11:14 +00:00
|
|
|
kind_ = LIGATURE_BREAK;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "endofsentence")
|
2001-07-23 09:11:14 +00:00
|
|
|
kind_ = END_OF_SENTENCE;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "ldots")
|
2001-07-23 09:11:14 +00:00
|
|
|
kind_ = LDOTS;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "menuseparator")
|
2002-03-21 17:09:55 +00:00
|
|
|
kind_ = MENU_SEPARATOR;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "breakableslash")
|
2007-12-06 11:04:56 +00:00
|
|
|
kind_ = SLASH;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "nobreakdash")
|
2007-12-06 11:04:56 +00:00
|
|
|
kind_ = NOBREAKDASH;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "LyX")
|
2015-03-01 10:16:57 +00:00
|
|
|
kind_ = PHRASE_LYX;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "TeX")
|
2015-03-01 10:16:57 +00:00
|
|
|
kind_ = PHRASE_TEX;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "LaTeX2e")
|
2015-03-01 10:16:57 +00:00
|
|
|
kind_ = PHRASE_LATEX2E;
|
2015-03-23 20:28:04 +00:00
|
|
|
else if (command == "LaTeX")
|
2015-03-01 10:16:57 +00:00
|
|
|
kind_ = PHRASE_LATEX;
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
|
|
|
lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetSpecialChar::latex(otexstream & os,
|
|
|
|
OutputParams const & rp) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2018-07-15 18:56:55 +00:00
|
|
|
bool const rtl = rp.local_font->isRightToLeft();
|
|
|
|
string lswitch = "";
|
|
|
|
string lswitche = "";
|
|
|
|
if (rtl && !rp.use_polyglossia) {
|
|
|
|
lswitch = "\\L{";
|
|
|
|
lswitche = "}";
|
|
|
|
if (rp.local_font->language()->lang() == "arabic_arabi"
|
|
|
|
|| rp.local_font->language()->lang() == "farsi")
|
|
|
|
lswitch = "\\textLR{";
|
|
|
|
}
|
2018-07-19 21:05:00 +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;
|
2017-03-06 13:49:30 +00:00
|
|
|
case ALLOWBREAK:
|
|
|
|
os << "\\LyXZeroWidthSpace" << termcmd;
|
|
|
|
break;
|
2001-07-20 13:04:36 +00:00
|
|
|
case LIGATURE_BREAK:
|
2016-12-16 08:26:01 +00:00
|
|
|
os << "\\textcompwordmark" << termcmd;
|
2001-07-20 09:38:19 +00:00
|
|
|
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:
|
2016-12-16 08:26:01 +00:00
|
|
|
os << "\\ldots" << termcmd;
|
2001-07-20 09:38:19 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
case MENU_SEPARATOR:
|
2018-07-15 18:56:55 +00:00
|
|
|
if (rtl)
|
2016-12-16 08:26:01 +00:00
|
|
|
os << "\\lyxarrow*";
|
2009-01-11 08:31:52 +00:00
|
|
|
else
|
2016-12-16 08:26:01 +00:00
|
|
|
os << "\\lyxarrow";
|
|
|
|
os << termcmd;
|
2001-07-20 09:38:19 +00:00
|
|
|
break;
|
2007-12-06 11:04:56 +00:00
|
|
|
case SLASH:
|
2016-12-16 08:26:01 +00:00
|
|
|
os << "\\slash" << termcmd;
|
2007-12-06 11:04:56 +00:00
|
|
|
break;
|
|
|
|
case NOBREAKDASH:
|
2008-10-12 09:54:39 +00:00
|
|
|
if (rp.moving_arg)
|
|
|
|
os << "\\protect";
|
2007-12-06 11:04:56 +00:00
|
|
|
os << "\\nobreakdash-";
|
|
|
|
break;
|
2015-03-01 10:16:57 +00:00
|
|
|
case PHRASE_LYX:
|
|
|
|
if (rp.moving_arg)
|
|
|
|
os << "\\protect";
|
2018-07-15 18:56:55 +00:00
|
|
|
os << lswitch << "\\LyX" << termcmd << lswitche;
|
2015-03-01 10:16:57 +00:00
|
|
|
break;
|
|
|
|
case PHRASE_TEX:
|
|
|
|
if (rp.moving_arg)
|
|
|
|
os << "\\protect";
|
2018-07-15 18:56:55 +00:00
|
|
|
os << lswitch << "\\TeX" << termcmd << lswitche;
|
2015-03-01 10:16:57 +00:00
|
|
|
break;
|
|
|
|
case PHRASE_LATEX2E:
|
|
|
|
if (rp.moving_arg)
|
|
|
|
os << "\\protect";
|
2018-07-15 18:56:55 +00:00
|
|
|
os << lswitch << "\\LaTeXe" << termcmd << lswitche;
|
2015-03-01 10:16:57 +00:00
|
|
|
break;
|
|
|
|
case PHRASE_LATEX:
|
|
|
|
if (rp.moving_arg)
|
|
|
|
os << "\\protect";
|
2018-07-15 18:56:55 +00:00
|
|
|
os << lswitch << "\\LaTeX" << termcmd << lswitche;
|
2015-03-01 10:16:57 +00:00
|
|
|
break;
|
2000-03-02 02:19:43 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetSpecialChar::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const &, size_t) 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:
|
2007-02-17 11:59:42 +00:00
|
|
|
return 0;
|
2017-03-06 13:49:30 +00:00
|
|
|
case ALLOWBREAK:
|
|
|
|
os.put(0x200b);
|
|
|
|
return 1;
|
2012-01-31 20:49:49 +00:00
|
|
|
case LIGATURE_BREAK:
|
|
|
|
os.put(0x200c);
|
|
|
|
return 1;
|
2002-03-21 17:09:55 +00:00
|
|
|
case END_OF_SENTENCE:
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '.';
|
2007-02-17 11:59:42 +00:00
|
|
|
return 1;
|
2002-03-21 17:09:55 +00:00
|
|
|
case LDOTS:
|
2015-02-01 11:49:41 +00:00
|
|
|
os.put(0x2026);
|
|
|
|
return 1;
|
2002-03-21 17:09:55 +00:00
|
|
|
case MENU_SEPARATOR:
|
|
|
|
os << "->";
|
2007-02-17 11:59:42 +00:00
|
|
|
return 2;
|
2007-12-06 11:04:56 +00:00
|
|
|
case SLASH:
|
|
|
|
os << '/';
|
|
|
|
return 1;
|
|
|
|
case NOBREAKDASH:
|
2012-01-31 20:49:49 +00:00
|
|
|
os.put(0x2011);
|
2007-12-06 11:04:56 +00:00
|
|
|
return 1;
|
2015-03-01 10:16:57 +00:00
|
|
|
case PHRASE_LYX:
|
|
|
|
os << "LyX";
|
|
|
|
return 3;
|
|
|
|
case PHRASE_TEX:
|
|
|
|
os << "TeX";
|
|
|
|
return 3;
|
|
|
|
case PHRASE_LATEX2E:
|
|
|
|
os << "LaTeX2";
|
|
|
|
os.put(0x03b5);
|
|
|
|
return 7;
|
|
|
|
case PHRASE_LATEX:
|
|
|
|
os << "LaTeX";
|
|
|
|
return 5;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetSpecialChar::docbook(odocstream & os, OutputParams const &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2001-10-23 09:42:14 +00:00
|
|
|
switch (kind_) {
|
|
|
|
case HYPHENATION:
|
2017-03-06 13:49:30 +00:00
|
|
|
break;
|
|
|
|
case ALLOWBREAK:
|
|
|
|
os.put(0x200b);
|
|
|
|
break;
|
2001-10-23 09:42:14 +00:00
|
|
|
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:
|
2015-02-01 11:49:41 +00:00
|
|
|
os << "…";
|
2001-10-23 09:42:14 +00:00
|
|
|
break;
|
|
|
|
case MENU_SEPARATOR:
|
|
|
|
os << "&lyxarrow;";
|
|
|
|
break;
|
2007-12-06 11:04:56 +00:00
|
|
|
case SLASH:
|
|
|
|
os << '/';
|
|
|
|
break;
|
|
|
|
case NOBREAKDASH:
|
|
|
|
os << '-';
|
|
|
|
break;
|
2015-03-01 10:16:57 +00:00
|
|
|
case PHRASE_LYX:
|
|
|
|
os << "LyX";
|
|
|
|
break;
|
|
|
|
case PHRASE_TEX:
|
|
|
|
os << "TeX";
|
|
|
|
break;
|
|
|
|
case PHRASE_LATEX2E:
|
|
|
|
os << "LaTeX2";
|
|
|
|
os.put(0x03b5);
|
|
|
|
break;
|
|
|
|
case PHRASE_LATEX:
|
|
|
|
os << "LaTeX";
|
|
|
|
break;
|
2001-10-23 09:42:14 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2009-11-25 22:04:41 +00:00
|
|
|
docstring InsetSpecialChar::xhtml(XHTMLStream & xs, OutputParams const &) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
|
|
|
switch (kind_) {
|
|
|
|
case HYPHENATION:
|
2012-01-31 20:49:49 +00:00
|
|
|
break;
|
2017-03-06 13:49:30 +00:00
|
|
|
case ALLOWBREAK:
|
|
|
|
xs << XHTMLStream::ESCAPE_NONE << "​";
|
|
|
|
break;
|
2009-06-05 17:48:14 +00:00
|
|
|
case LIGATURE_BREAK:
|
2012-01-31 20:49:49 +00:00
|
|
|
xs << XHTMLStream::ESCAPE_NONE << "‌";
|
2009-06-05 17:48:14 +00:00
|
|
|
break;
|
|
|
|
case END_OF_SENTENCE:
|
2009-11-25 22:04:41 +00:00
|
|
|
xs << '.';
|
2009-06-05 17:48:14 +00:00
|
|
|
break;
|
|
|
|
case LDOTS:
|
2010-11-24 15:27:36 +00:00
|
|
|
xs << XHTMLStream::ESCAPE_NONE << "…";
|
2009-06-05 17:48:14 +00:00
|
|
|
break;
|
|
|
|
case MENU_SEPARATOR:
|
2010-11-24 15:27:36 +00:00
|
|
|
xs << XHTMLStream::ESCAPE_NONE << "⇒";
|
2009-06-05 17:48:14 +00:00
|
|
|
break;
|
|
|
|
case SLASH:
|
2010-11-24 15:27:36 +00:00
|
|
|
xs << XHTMLStream::ESCAPE_NONE << "⁄";
|
2009-06-05 17:48:14 +00:00
|
|
|
break;
|
|
|
|
case NOBREAKDASH:
|
2012-01-31 20:49:49 +00:00
|
|
|
xs << XHTMLStream::ESCAPE_NONE << "‑";
|
2009-06-05 17:48:14 +00:00
|
|
|
break;
|
2015-03-01 10:16:57 +00:00
|
|
|
case PHRASE_LYX:
|
|
|
|
xs << "LyX";
|
|
|
|
break;
|
|
|
|
case PHRASE_TEX:
|
|
|
|
xs << "TeX";
|
|
|
|
break;
|
|
|
|
case PHRASE_LATEX2E:
|
|
|
|
xs << "LaTeX2" << XHTMLStream::ESCAPE_NONE << "ε";
|
|
|
|
break;
|
|
|
|
case PHRASE_LATEX:
|
|
|
|
xs << "LaTeX";
|
|
|
|
break;
|
2009-06-05 17:48:14 +00:00
|
|
|
}
|
2009-06-12 17:23:17 +00:00
|
|
|
return docstring();
|
2009-06-05 17:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-15 01:34:04 +00:00
|
|
|
void InsetSpecialChar::toString(odocstream & os) const
|
2005-11-25 14:40:34 +00:00
|
|
|
{
|
2013-01-26 08:53:53 +00:00
|
|
|
switch (kind_) {
|
2017-03-06 13:49:30 +00:00
|
|
|
case ALLOWBREAK:
|
2013-01-26 08:53:53 +00:00
|
|
|
case LIGATURE_BREAK:
|
2017-03-06 13:49:30 +00:00
|
|
|
// Do not output ZERO WIDTH SPACE and ZERO WIDTH NON JOINER here
|
2013-01-26 08:53:53 +00:00
|
|
|
// Spell checker would choke on it.
|
|
|
|
return;
|
|
|
|
default:
|
2013-03-08 19:52:18 +00:00
|
|
|
break;
|
2013-01-26 08:53:53 +00:00
|
|
|
}
|
2013-03-08 19:52:18 +00:00
|
|
|
odocstringstream ods;
|
|
|
|
plaintext(ods, OutputParams(0));
|
|
|
|
os << ods.str();
|
2005-11-25 14:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-04 18:38:47 +00:00
|
|
|
void InsetSpecialChar::forOutliner(docstring & os, size_t const,
|
|
|
|
bool const) const
|
2010-12-20 21:55:09 +00:00
|
|
|
{
|
|
|
|
odocstringstream ods;
|
|
|
|
plaintext(ods, OutputParams(0));
|
|
|
|
os += ods.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetSpecialChar::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2017-03-06 13:49:30 +00:00
|
|
|
if (kind_ == ALLOWBREAK)
|
|
|
|
features.require("lyxzerowidthspace");
|
2007-08-30 18:03:17 +00:00
|
|
|
if (kind_ == MENU_SEPARATOR)
|
2001-11-19 15:34:11 +00:00
|
|
|
features.require("lyxarrow");
|
2007-12-06 11:04:56 +00:00
|
|
|
if (kind_ == NOBREAKDASH)
|
|
|
|
features.require("amsmath");
|
2015-03-01 10:16:57 +00:00
|
|
|
if (kind_ == PHRASE_LYX)
|
|
|
|
features.require("LyX");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-11-13 14:47:35 +00:00
|
|
|
|
|
|
|
|
2016-12-27 11:06:54 +00:00
|
|
|
bool InsetSpecialChar::isChar() const
|
|
|
|
{
|
2017-03-01 15:36:46 +00:00
|
|
|
return kind_ != HYPHENATION && kind_ != LIGATURE_BREAK;
|
2016-12-27 11:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-13 14:47:35 +00:00
|
|
|
bool InsetSpecialChar::isLetter() const
|
|
|
|
{
|
2011-03-18 09:17:09 +00:00
|
|
|
return kind_ == HYPHENATION || kind_ == LIGATURE_BREAK
|
|
|
|
|| kind_ == NOBREAKDASH;
|
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)
|
2017-03-06 13:49:30 +00:00
|
|
|
return kind_ == HYPHENATION || kind_ == ALLOWBREAK
|
|
|
|
|| kind_ == MENU_SEPARATOR || kind_ == SLASH;
|
2002-03-27 00:05:28 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2002-02-13 10:37:28 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|