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 1995 Matthias Ettrich
|
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
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 "insetquotes.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxfont.h"
|
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Quotes. Used for the various quotes. German, English, French,
|
|
|
|
|
// Danish, Polish, all either double or single.
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
extern LyXRC * lyxrc;
|
|
|
|
|
extern BufferView * current_view;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// codes used to read/write quotes to LyX files
|
1999-10-02 16:21:10 +00:00
|
|
|
|
static char const * const language_char = "esgpfa";
|
|
|
|
|
static char const * const side_char = "lr" ;
|
1999-11-15 10:58:38 +00:00
|
|
|
|
static char const * const times_char = "sd";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// List of known quote chars
|
1999-10-02 16:21:10 +00:00
|
|
|
|
static char const * const quote_char = ",'`<>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-15 10:58:38 +00:00
|
|
|
|
// Index of chars used for the quote. Index is [side, language]
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int quote_index[2][6] =
|
|
|
|
|
{ { 2, 1, 0, 0, 3, 4 }, // "'',,<>"
|
|
|
|
|
{ 1, 1, 2, 1, 4, 3 } }; // "`'`'><"
|
|
|
|
|
|
|
|
|
|
// Corresponding LaTeX code, for double and single quotes.
|
1999-11-15 10:58:38 +00:00
|
|
|
|
static char const * const latex_quote_t1[2][5] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ { "\\quotesinglbase{}", "'", "`",
|
|
|
|
|
"\\guilsinglleft{}", "\\guilsinglright{}" },
|
|
|
|
|
{ ",,", "''", "``", "<<", ">>" } };
|
|
|
|
|
|
1999-11-15 10:58:38 +00:00
|
|
|
|
static char const * const latex_quote_ot1[2][5] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ { "\\quotesinglbase{}", "'", "`",
|
|
|
|
|
"\\guilsinglleft{}", "\\guilsinglright{}" },
|
|
|
|
|
{ "\\quotedblbase{}", "''", "``",
|
|
|
|
|
"\\guillemotleft{}", "\\guillemotright{}" } };
|
|
|
|
|
|
1999-11-15 10:58:38 +00:00
|
|
|
|
static char const * const latex_quote_babel[2][5] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ { "\\glq{}", "'", "`", "\\flq{}", "\\frq{}" },
|
|
|
|
|
{ "\\glqq{}", "''", "``", "\\flqq{}", "\\frqq{}" } };
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
InsetQuotes::InsetQuotes(string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
|
ParseString(str);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InsetQuotes::InsetQuotes(InsetQuotes::quote_language l,
|
|
|
|
|
InsetQuotes::quote_side s,
|
|
|
|
|
InsetQuotes::quote_times t)
|
|
|
|
|
: language(l), side(s), times(t)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
InsetQuotes::InsetQuotes(char c, BufferParams const & params)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
: language(params.quotes_language), times(params.quotes_times)
|
|
|
|
|
{
|
|
|
|
|
// Decide whether left or right
|
|
|
|
|
switch(c) {
|
|
|
|
|
case ' ': case '(': case '{': case '[': case '-': case ':':
|
1999-11-15 10:58:38 +00:00
|
|
|
|
case LyXParagraph::META_HFILL:
|
|
|
|
|
case LyXParagraph::META_PROTECTED_SEPARATOR:
|
|
|
|
|
case LyXParagraph::META_NEWLINE:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
side = InsetQuotes::LeftQ; // left quote
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
side = InsetQuotes::RightQ; // right quote
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
void InsetQuotes::ParseString(string const & s)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
string str(s);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if (str.length() != 3) {
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
|
" bad string length." << endl;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
str = "eld";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-15 10:58:38 +00:00
|
|
|
|
for (i= 0;i<6;i++) {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if (str[0] == language_char[i]) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
language = (InsetQuotes::quote_language)i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-15 10:58:38 +00:00
|
|
|
|
if (i>= 6) {
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
|
" bad language specification." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
language = InsetQuotes::EnglishQ;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-15 10:58:38 +00:00
|
|
|
|
for (i= 0;i<2;i++) {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if (str[1] == side_char[i]) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
side = (InsetQuotes::quote_side)i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-15 10:58:38 +00:00
|
|
|
|
if (i>= 2) {
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
|
" bad side specification." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
side = InsetQuotes::LeftQ;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-15 10:58:38 +00:00
|
|
|
|
for (i= 0;i<2;i++) {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if (str[2] == times_char[i]) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
times = (InsetQuotes::quote_times)i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-15 10:58:38 +00:00
|
|
|
|
if (i>= 2) {
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
|
" bad times specification." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
times = InsetQuotes::DoubleQ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string InsetQuotes::DispString() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string disp;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
disp += quote_char[quote_index[side][language]];
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (times == InsetQuotes::DoubleQ)
|
|
|
|
|
disp += disp;
|
|
|
|
|
|
|
|
|
|
if (lyxrc->font_norm == "iso8859-1")
|
|
|
|
|
if (disp == "<<")
|
|
|
|
|
disp = '<EFBFBD>';
|
|
|
|
|
else if (disp == ">>")
|
|
|
|
|
disp = '<EFBFBD>';
|
|
|
|
|
|
|
|
|
|
return disp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
int InsetQuotes::Ascent(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
return font.maxAscent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
int InsetQuotes::Descent(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
return font.maxDescent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
int InsetQuotes::Width(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string text = DispString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int w = 0;
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
for (string::size_type i = 0; i < text.length(); ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (text[i] == ' ')
|
|
|
|
|
w += font.width('i');
|
|
|
|
|
else if (i == 0 || text[i] != text[i-1])
|
|
|
|
|
w += font.width(text[i]);
|
|
|
|
|
else
|
|
|
|
|
w += font.width(',');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXFont InsetQuotes::ConvertFont(LyXFont font)
|
|
|
|
|
{
|
|
|
|
|
/* quotes-insets cannot be latex of any kind */
|
|
|
|
|
font.setLatex(LyXFont::OFF);
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void InsetQuotes::Draw(LyXFont font, LyXScreen & scr,
|
|
|
|
|
int baseline, float & x)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string text = DispString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-10-07 19:15:53 +00:00
|
|
|
|
scr.drawString(font, text, baseline, int(x));
|
|
|
|
|
x += Width(font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void InsetQuotes::Write(FILE * file)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string text;
|
|
|
|
|
text += language_char[language];
|
|
|
|
|
text += side_char[side];
|
|
|
|
|
text += times_char[times];
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fprintf(file, "Quotes %s", text.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void InsetQuotes::Read(LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
ParseString(lex.GetString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
int InsetQuotes::Latex(FILE * file, signed char /*fragile*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string quote;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int res = Latex(quote, 0);
|
|
|
|
|
fprintf(file, "%s", quote.c_str());
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
int InsetQuotes::Latex(string & file, signed char /*fragile*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-15 10:58:38 +00:00
|
|
|
|
string doclang =
|
1999-11-09 22:53:41 +00:00
|
|
|
|
current_view->buffer()->GetLanguage();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int quoteind = quote_index[side][language];
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string qstr;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
if (lyxrc->fontenc == "T1") {
|
|
|
|
|
qstr = latex_quote_t1[times][quoteind];
|
|
|
|
|
}
|
|
|
|
|
else if (doclang == "default") {
|
|
|
|
|
qstr = latex_quote_ot1[times][quoteind];
|
|
|
|
|
}
|
|
|
|
|
else if (language == InsetQuotes::FrenchQ
|
|
|
|
|
&& times == InsetQuotes::DoubleQ
|
|
|
|
|
&& doclang == "frenchb") {
|
|
|
|
|
if (side == InsetQuotes::LeftQ)
|
|
|
|
|
qstr = "\\og{}";
|
|
|
|
|
else
|
|
|
|
|
qstr = " \\fg{}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
qstr = latex_quote_babel[times][quoteind];
|
|
|
|
|
|
|
|
|
|
// protect against !` and ?` ligatures.
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if ((suffixIs(file, '?') || suffixIs(file, '!'))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& qstr[0] == '`')
|
|
|
|
|
qstr = "{}" + qstr;
|
|
|
|
|
|
|
|
|
|
file += qstr;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
int InsetQuotes::Linuxdoc(string & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
file += "\"";
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
int InsetQuotes::DocBook(string & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if(times == InsetQuotes::DoubleQ) {
|
|
|
|
|
if (side == InsetQuotes::LeftQ)
|
1999-10-02 14:01:04 +00:00
|
|
|
|
file += "“";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-10-02 14:01:04 +00:00
|
|
|
|
file += "”";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (side == InsetQuotes::LeftQ)
|
1999-10-02 14:01:04 +00:00
|
|
|
|
file += "‘";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-10-02 14:01:04 +00:00
|
|
|
|
file += "’";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void InsetQuotes::Validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
char type = quote_char[quote_index[side][language]];
|
|
|
|
|
|
1999-11-09 22:53:41 +00:00
|
|
|
|
if (current_view->buffer()->GetLanguage() == "default"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& lyxrc->fontenc != "T1") {
|
|
|
|
|
if (times == InsetQuotes::SingleQ)
|
|
|
|
|
switch (type) {
|
|
|
|
|
case ',': features.quotesinglbase = true; break;
|
|
|
|
|
case '<': features.guilsinglleft = true; break;
|
|
|
|
|
case '>': features.guilsinglright = true; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
switch (type) {
|
|
|
|
|
case ',': features.quotedblbase = true; break;
|
|
|
|
|
case '<': features.guillemotleft = true; break;
|
|
|
|
|
case '>': features.guillemotright = true; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
Inset * InsetQuotes::Clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
return new InsetQuotes(language, side, times);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inset::Code InsetQuotes::LyxCode() const
|
|
|
|
|
{
|
|
|
|
|
return Inset::QUOTE_CODE;
|
|
|
|
|
}
|