2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetQuotes.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 Jean-Marc Lasgouttes
|
2016-12-24 09:13:51 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
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 "InsetQuotes.h"
|
2001-12-13 11:35:25 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2007-10-28 18:51:54 +00:00
|
|
|
#include "BufferView.h"
|
2016-12-17 11:58:33 +00:00
|
|
|
#include "Cursor.h"
|
2007-11-03 18:50:54 +00:00
|
|
|
#include "Dimension.h"
|
2016-12-26 13:03:48 +00:00
|
|
|
#include "Encoding.h"
|
2010-03-31 19:38:05 +00:00
|
|
|
#include "Font.h"
|
2016-12-17 11:58:33 +00:00
|
|
|
#include "FuncStatus.h"
|
|
|
|
#include "FuncRequest.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Language.h"
|
2003-05-22 22:44:30 +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 "LyXRC.h"
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "OutputParams.h"
|
2009-11-19 23:02:47 +00:00
|
|
|
#include "output_xhtml.h"
|
2016-12-10 10:53:42 +00:00
|
|
|
#include "Paragraph.h"
|
|
|
|
#include "ParIterator.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2003-08-26 16:36:53 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2003-05-22 22:44:30 +00:00
|
|
|
#include "frontends/Painter.h"
|
2003-08-26 16:36:53 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstring.h"
|
2007-11-28 22:12:03 +00:00
|
|
|
#include "support/docstream.h"
|
2016-12-24 09:13:51 +00:00
|
|
|
#include "support/gettext.h"
|
2003-05-19 17:03:12 +00:00
|
|
|
#include "support/lstrings.h"
|
2016-12-27 11:06:54 +00:00
|
|
|
#include "support/textutils.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2016-12-24 09:13:51 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2003-07-28 15:45:41 +00:00
|
|
|
/* codes used to read/write quotes to LyX files
|
2016-12-24 09:13:51 +00:00
|
|
|
* available styles:
|
|
|
|
* e ``english'' (`inner quotation')
|
|
|
|
* s ''swedish'' ('inner quotation')
|
|
|
|
* g ,,german`` (,inner quotation`)
|
|
|
|
* p ,,polish'' (,inner quotation')
|
2016-12-24 13:27:00 +00:00
|
|
|
* c <<swiss>> (<inner quotation>)
|
2016-12-24 09:13:51 +00:00
|
|
|
* a >>danish<< (>inner quotation<)
|
|
|
|
* q "plain" ('inner quotation')
|
2016-12-24 13:27:00 +00:00
|
|
|
* b `british' (``inner quotation'')
|
|
|
|
* w >>swedishg>> ('inner quotation') ["g" = Guillemets]
|
|
|
|
* f <<french>> (``inner quotation'')
|
|
|
|
* i <<frenchin>> (<<inner quotation>>) ["in" = Imprimerie Nationale]
|
|
|
|
* r <<russian>> (,,inner quotation``)
|
2016-12-26 13:03:48 +00:00
|
|
|
* j [U+300C]cjk[U+300D] ([U+300E]inner quotation[U+300F]) [CORNER BRACKETS]
|
|
|
|
* k [U+300A]cjkangle[U+300B] ([U+3008]inner quotation[U+3009]) [ANGLE BRACKETS]
|
2016-12-25 11:19:02 +00:00
|
|
|
* x dynamic style (inherits document settings)
|
2003-07-28 15:45:41 +00:00
|
|
|
*/
|
|
|
|
|
2016-12-26 13:03:48 +00:00
|
|
|
char const * const style_char = "esgpcaqbwfirjkx";
|
2001-03-20 01:22:46 +00:00
|
|
|
char const * const side_char = "lr" ;
|
2016-12-20 16:55:43 +00:00
|
|
|
char const * const level_char = "sd";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2001-03-20 01:22:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2016-12-24 09:13:51 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetQuotesParams
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
InsetQuotesParams quoteparams;
|
|
|
|
|
|
|
|
|
|
|
|
int InsetQuotesParams::stylescount() const
|
|
|
|
{
|
|
|
|
return strlen(style_char);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-05 13:25:36 +00:00
|
|
|
char InsetQuotesParams::getStyleChar(QuoteStyle const & style) const
|
|
|
|
{
|
|
|
|
return style_char[style];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetQuotesParams::QuoteStyle InsetQuotesParams::getQuoteStyle(string const & s,
|
|
|
|
bool const allow_wildcards, QuoteStyle fb)
|
|
|
|
{
|
|
|
|
QuoteStyle res = fb;
|
|
|
|
|
|
|
|
string str = s;
|
|
|
|
if (str.length() != 3) {
|
|
|
|
LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
" bad string length.");
|
|
|
|
str = "eld";
|
|
|
|
}
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// '.' wildcard means: keep current style
|
|
|
|
if (!allow_wildcards || str[0] != '.') {
|
|
|
|
for (i = 0; i < stylescount(); ++i) {
|
|
|
|
if (str[0] == style_char[i]) {
|
|
|
|
res = QuoteStyle(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= stylescount()) {
|
|
|
|
LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
" bad style specification.");
|
|
|
|
res = EnglishQuotes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetQuotesParams::QuoteSide InsetQuotesParams::getQuoteSide(string const & s,
|
|
|
|
bool const allow_wildcards, QuoteSide fb)
|
|
|
|
{
|
|
|
|
QuoteSide res = fb;
|
|
|
|
|
|
|
|
string str = s;
|
|
|
|
if (str.length() != 3) {
|
|
|
|
LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
" bad string length.");
|
|
|
|
str = "eld";
|
|
|
|
}
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// '.' wildcard means: keep current side
|
|
|
|
if (!allow_wildcards || str[1] != '.') {
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
if (str[1] == side_char[i]) {
|
|
|
|
res = InsetQuotesParams::QuoteSide(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= 2) {
|
|
|
|
LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
" bad side specification.");
|
|
|
|
res = OpeningQuote;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetQuotesParams::QuoteLevel InsetQuotesParams::getQuoteLevel(string const & s,
|
|
|
|
bool const allow_wildcards, QuoteLevel fb)
|
|
|
|
{
|
|
|
|
QuoteLevel res = fb;
|
|
|
|
|
|
|
|
string str = s;
|
|
|
|
if (str.length() != 3) {
|
|
|
|
LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
" bad string length.");
|
|
|
|
str = "eld";
|
|
|
|
}
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// '.' wildcard means: keep current level
|
|
|
|
if (!allow_wildcards || str[2] != '.') {
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
if (str[2] == level_char[i]) {
|
|
|
|
res = InsetQuotesParams::QuoteLevel(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= 2) {
|
|
|
|
LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
|
|
|
|
" bad level specification.");
|
|
|
|
res = InsetQuotesParams::PrimaryQuotes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-24 09:13:51 +00:00
|
|
|
char_type InsetQuotesParams::getQuoteChar(QuoteStyle const & style, QuoteLevel const & level,
|
|
|
|
QuoteSide const & side) const
|
|
|
|
{
|
|
|
|
// main opening quotation mark
|
|
|
|
char_type left_primary;
|
|
|
|
// main closing quotation mark
|
|
|
|
char_type right_primary;
|
|
|
|
// secondary (inner, 'single') opening quotation mark
|
|
|
|
char_type left_secondary;
|
|
|
|
// secondary (inner, 'single') closing quotation mark
|
|
|
|
char_type right_secondary;
|
|
|
|
|
|
|
|
switch (style) {
|
|
|
|
case EnglishQuotes: {
|
|
|
|
left_primary = 0x201c; // ``
|
|
|
|
right_primary = 0x201d; // ''
|
|
|
|
left_secondary = 0x2018; // `
|
|
|
|
right_secondary = 0x2019; // '
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SwedishQuotes: {
|
|
|
|
left_primary = 0x201d; // ''
|
|
|
|
right_primary = 0x201d; // ''
|
|
|
|
left_secondary = 0x2019; // '
|
|
|
|
right_secondary = 0x2019; // '
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GermanQuotes: {
|
|
|
|
left_primary = 0x201e; // ,,
|
|
|
|
right_primary = 0x201c; // ``
|
|
|
|
left_secondary = 0x201a; // ,
|
|
|
|
right_secondary = 0x2018; // `
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PolishQuotes: {
|
|
|
|
left_primary = 0x201e; // ,,
|
|
|
|
right_primary = 0x201d; // ''
|
|
|
|
left_secondary = 0x201a; // ,
|
|
|
|
right_secondary = 0x2019; // '
|
|
|
|
break;
|
|
|
|
}
|
2016-12-24 13:27:00 +00:00
|
|
|
case SwissQuotes: {
|
2016-12-24 09:13:51 +00:00
|
|
|
left_primary = 0x00ab; // <<
|
|
|
|
right_primary = 0x00bb; // >>
|
|
|
|
left_secondary = 0x2039; // <
|
|
|
|
right_secondary = 0x203a; // >
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DanishQuotes: {
|
|
|
|
left_primary = 0x00bb; // >>
|
|
|
|
right_primary = 0x00ab; // <<
|
|
|
|
left_secondary = 0x203a; // >
|
|
|
|
right_secondary = 0x2039; // <
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PlainQuotes: {
|
|
|
|
left_primary = 0x0022; // "
|
|
|
|
right_primary = 0x0022; // "
|
|
|
|
left_secondary = 0x0027; // '
|
|
|
|
right_secondary = 0x0027; // '
|
|
|
|
break;
|
|
|
|
}
|
2016-12-24 13:27:00 +00:00
|
|
|
case BritishQuotes: {
|
|
|
|
left_primary = 0x2018; // `
|
|
|
|
right_primary = 0x2019; // '
|
|
|
|
left_secondary = 0x201c; // ``
|
|
|
|
right_secondary = 0x201d; // ''
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SwedishGQuotes: {
|
|
|
|
left_primary = 0x00bb; // >>
|
|
|
|
right_primary = 0x00bb; // >>
|
|
|
|
left_secondary = 0x2019; // '
|
|
|
|
right_secondary = 0x2019; // '
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FrenchQuotes: {
|
|
|
|
left_primary = 0x00ab; // <<
|
|
|
|
right_primary = 0x00bb; // >>
|
|
|
|
left_secondary = 0x201c; // ``
|
|
|
|
right_secondary = 0x201d; // ''
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FrenchINQuotes:{
|
|
|
|
left_primary = 0x00ab; // <<
|
|
|
|
right_primary = 0x00bb; // >>
|
|
|
|
left_secondary = 0x00ab; // <<
|
|
|
|
right_secondary = 0x00bb; // >>
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RussianQuotes:{
|
|
|
|
left_primary = 0x00ab; // <<
|
|
|
|
right_primary = 0x00bb; // >>
|
|
|
|
left_secondary = 0x201e; // ,,
|
|
|
|
right_secondary = 0x201c; // ``
|
|
|
|
break;
|
|
|
|
}
|
2016-12-26 13:03:48 +00:00
|
|
|
case CJKQuotes:{
|
|
|
|
left_primary = 0x300c; // LEFT CORNER BRACKET
|
|
|
|
right_primary = 0x300d; // RIGHT CORNER BRACKET
|
|
|
|
left_secondary = 0x300e; // LEFT WHITE CORNER BRACKET
|
|
|
|
right_secondary = 0x300f; // RIGHT WHITE CORNER BRACKET
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CJKAngleQuotes:{
|
|
|
|
left_primary = 0x300a; // LEFT DOUBLE ANGLE BRACKET
|
|
|
|
right_primary = 0x300b; // RIGHT DOUBLE ANGLE BRACKET
|
|
|
|
left_secondary = 0x3008; // LEFT ANGLE BRACKET
|
|
|
|
right_secondary = 0x3009; // RIGHT ANGLE BRACKET
|
|
|
|
break;
|
|
|
|
}
|
2016-12-25 11:19:02 +00:00
|
|
|
case DynamicQuotes:
|
2016-12-24 09:13:51 +00:00
|
|
|
default:
|
|
|
|
// should not happen
|
|
|
|
left_primary = 0x003f; // ?
|
|
|
|
right_primary = 0x003f; // ?
|
|
|
|
left_secondary = 0x003f; // ?
|
|
|
|
right_secondary = 0x003f; // ?
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (level) {
|
2016-12-24 13:27:00 +00:00
|
|
|
case SecondaryQuotes:
|
|
|
|
return (side == OpeningQuote) ? left_secondary : right_secondary;
|
|
|
|
case PrimaryQuotes:
|
|
|
|
return (side == OpeningQuote) ? left_primary : right_primary;
|
2016-12-24 09:13:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// should not happen
|
|
|
|
return 0x003f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op) const
|
|
|
|
{
|
|
|
|
string res;
|
|
|
|
|
|
|
|
switch (c){
|
|
|
|
case 0x201a: {// ,
|
|
|
|
if (op == "babel")
|
|
|
|
res = "\\glq";
|
|
|
|
else
|
|
|
|
res = "\\quotesinglbase";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x2019: {// '
|
|
|
|
if (op == "int")
|
|
|
|
res = "\\textquoteleft";
|
|
|
|
else
|
|
|
|
res = "'";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x2018: {// `
|
|
|
|
if (op == "int")
|
|
|
|
res = "\\textquoteright";
|
|
|
|
else
|
|
|
|
res = "`";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x2039: {// <
|
|
|
|
if (op == "babel")
|
|
|
|
res = "\\flq";
|
|
|
|
else
|
|
|
|
res = "\\guilsinglleft";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x203a: {// >
|
|
|
|
if (op == "babel")
|
|
|
|
res = "\\frq";
|
|
|
|
else
|
|
|
|
res = "\\guilsinglright";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x0027: {// ' (plain)
|
2017-05-11 16:08:11 +00:00
|
|
|
res = "\\textquotesingle";
|
2017-05-11 19:41:12 +00:00
|
|
|
break;
|
2016-12-24 09:13:51 +00:00
|
|
|
}
|
|
|
|
case 0x201e: {// ,,
|
|
|
|
if (op == "t1")
|
|
|
|
res = ",,";
|
|
|
|
else if (op == "babel")
|
|
|
|
res = "\\glqq";
|
|
|
|
else
|
|
|
|
res = "\\quotedblbase";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x201d: {// ''
|
|
|
|
if (op == "int")
|
|
|
|
res = "\\textquotedblleft";
|
|
|
|
else
|
|
|
|
res = "''";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x201c: {// ``
|
|
|
|
if (op == "int")
|
|
|
|
res = "\\textquotedblright";
|
|
|
|
else
|
|
|
|
res = "``";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x00ab: {// <<
|
|
|
|
if (op == "t1")
|
|
|
|
res = "<<";
|
|
|
|
else if (op == "babel")
|
|
|
|
res = "\\flqq";
|
|
|
|
else
|
|
|
|
res = "\\guillemotleft";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x00bb: {// >>
|
|
|
|
if (op == "t1")
|
|
|
|
res = ">>";
|
|
|
|
else if (op == "babel")
|
|
|
|
res = "\\frqq";
|
|
|
|
else
|
|
|
|
res = "\\guillemotright";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x0022: {// "
|
2017-05-11 16:08:11 +00:00
|
|
|
res = "\\textquotedbl";
|
2017-05-11 19:41:12 +00:00
|
|
|
break;
|
2016-12-24 09:13:51 +00:00
|
|
|
}
|
2016-12-26 13:03:48 +00:00
|
|
|
// The following are fakes
|
|
|
|
// This is just to get something symbolic
|
|
|
|
// in encodings where this chars would not be used ayway
|
|
|
|
case 0x300c: // LEFT CORNER BRACKET
|
|
|
|
res = "\\ensuremath{\\lceil}";
|
|
|
|
break;
|
|
|
|
case 0x300d: // RIGHT CORNER BRACKET
|
|
|
|
res = "\\ensuremath{\\rfloor}";
|
|
|
|
break;
|
|
|
|
case 0x300e: // LEFT WHITE CORNER BRACKET
|
|
|
|
res = "\\ensuremath{\\llceil}";
|
|
|
|
break;
|
|
|
|
case 0x300f: // RIGHT WHITE CORNER BRACKET
|
|
|
|
res = "\\ensuremath{\\rrfloor}";
|
|
|
|
break;
|
|
|
|
case 0x300a: // LEFT DOUBLE ANGLE BRACKET
|
|
|
|
res = "\\ensuremath{\\langle\\kern-2.5pt\\langle}";
|
|
|
|
break;
|
|
|
|
case 0x300b: // RIGHT DOUBLE ANGLE BRACKET
|
|
|
|
res = "\\ensuremath{\\rangle\\kern-2.5pt\\rangle}";
|
|
|
|
break;
|
|
|
|
case 0x3008: // LEFT ANGLE BRACKET
|
|
|
|
res = "\\ensuremath{\\langle}";
|
|
|
|
break;
|
|
|
|
case 0x3009: // RIGHT ANGLE BRACKET
|
|
|
|
res = "\\ensuremath{\\rangle}";
|
|
|
|
break;
|
2016-12-24 09:13:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2016-12-24 09:13:51 +00:00
|
|
|
return from_ascii(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetQuotesParams::getHTMLQuote(char_type c) const
|
|
|
|
{
|
|
|
|
string res;
|
|
|
|
|
|
|
|
switch (c){
|
|
|
|
case 0x201a: // ,
|
|
|
|
res = "‚";
|
|
|
|
break;
|
|
|
|
case 0x2019: // '
|
|
|
|
res = "’";
|
|
|
|
break;
|
|
|
|
case 0x2018: // `
|
|
|
|
res = "‘";
|
|
|
|
break;
|
|
|
|
case 0x2039: // <
|
|
|
|
res = "‹";
|
|
|
|
break;
|
|
|
|
case 0x203a: // >
|
|
|
|
res = "›";
|
|
|
|
break;
|
|
|
|
case 0x0027: // ' (plain)
|
|
|
|
res = "'";
|
|
|
|
break;
|
|
|
|
case 0x201e: // ,,
|
|
|
|
res = "„";
|
|
|
|
break;
|
|
|
|
case 0x201d: // ''
|
|
|
|
res = "”";
|
|
|
|
break;
|
|
|
|
case 0x201c: // ``
|
|
|
|
res = "“";
|
|
|
|
break;
|
|
|
|
case 0x00ab: // <<
|
|
|
|
res = "«";
|
|
|
|
break;
|
|
|
|
case 0x00bb: // >>
|
|
|
|
res = "»";
|
|
|
|
break;
|
|
|
|
case 0x0022: // "
|
|
|
|
res = """;
|
|
|
|
break;
|
2016-12-26 13:03:48 +00:00
|
|
|
case 0x300c: // LEFT CORNER BRACKET
|
|
|
|
res = "「";
|
|
|
|
break;
|
|
|
|
case 0x300d: // RIGHT CORNER BRACKET
|
|
|
|
res = "」";
|
|
|
|
break;
|
|
|
|
case 0x300e: // LEFT WHITE CORNER BRACKET
|
|
|
|
res = "『";
|
|
|
|
break;
|
|
|
|
case 0x300f: // RIGHT WHITE CORNER BRACKET
|
|
|
|
res = "』";
|
|
|
|
break;
|
|
|
|
case 0x300a: // LEFT DOUBLE ANGLE BRACKET
|
|
|
|
res = "《";
|
|
|
|
break;
|
|
|
|
case 0x300b: // RIGHT DOUBLE ANGLE BRACKET
|
|
|
|
res = "》";
|
|
|
|
break;
|
|
|
|
case 0x3008: // LEFT ANGLE BRACKET
|
|
|
|
res = "〈";
|
|
|
|
break;
|
|
|
|
case 0x3009: // RIGHT ANGLE BRACKET
|
|
|
|
res = "〉";
|
|
|
|
break;
|
2016-12-24 09:13:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2016-12-24 09:13:51 +00:00
|
|
|
return from_ascii(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
map<string, docstring> InsetQuotesParams::getTypes() const
|
|
|
|
{
|
|
|
|
map<string, docstring> res;
|
|
|
|
|
|
|
|
int sty, sid, lev;
|
|
|
|
QuoteStyle style;
|
|
|
|
QuoteSide side;
|
|
|
|
QuoteLevel level;
|
|
|
|
string type;
|
|
|
|
|
|
|
|
// get all quote types
|
|
|
|
for (sty = 0; sty < stylescount(); ++sty) {
|
|
|
|
style = QuoteStyle(sty);
|
2016-12-25 11:19:02 +00:00
|
|
|
if (style == DynamicQuotes)
|
|
|
|
continue;
|
2016-12-24 09:13:51 +00:00
|
|
|
for (sid = 0; sid < 2; ++sid) {
|
|
|
|
side = QuoteSide(sid);
|
|
|
|
for (lev = 0; lev < 2; ++lev) {
|
|
|
|
type += style_char[style];
|
|
|
|
type += side_char[sid];
|
|
|
|
level = QuoteLevel(lev);
|
|
|
|
type += level_char[lev];
|
|
|
|
res[type] = docstring(1, getQuoteChar(style, level, side));
|
|
|
|
type.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-05 13:25:36 +00:00
|
|
|
docstring const InsetQuotesParams::getGuiLabel(QuoteStyle const & qs, bool langdef)
|
2016-12-24 09:13:51 +00:00
|
|
|
{
|
2017-01-05 13:25:36 +00:00
|
|
|
docstring const styledesc =
|
|
|
|
bformat(_("%1$souter%2$s and %3$sinner%4$s[[quotation marks]]"),
|
|
|
|
docstring(1, getQuoteChar(qs, PrimaryQuotes, OpeningQuote)),
|
|
|
|
docstring(1, getQuoteChar(qs, PrimaryQuotes, ClosingQuote)),
|
|
|
|
docstring(1, getQuoteChar(qs, SecondaryQuotes, OpeningQuote)),
|
|
|
|
docstring(1, getQuoteChar(qs, SecondaryQuotes, ClosingQuote))
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!langdef)
|
|
|
|
return styledesc;
|
|
|
|
|
|
|
|
return bformat(_("%1$s[[quot. mark description]] (language default)"),
|
|
|
|
styledesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring const InsetQuotesParams::getShortGuiLabel(docstring const string)
|
|
|
|
{
|
|
|
|
std::string const s = to_ascii(string);
|
|
|
|
QuoteStyle const style = getQuoteStyle(s);
|
|
|
|
QuoteSide const side = getQuoteSide(s);
|
|
|
|
QuoteLevel const level = getQuoteLevel(s);
|
|
|
|
|
|
|
|
return (side == OpeningQuote) ?
|
|
|
|
bformat(_("%1$stext"),
|
|
|
|
docstring(1, getQuoteChar(style, level, side))) :
|
|
|
|
bformat(_("text%1$s"),
|
|
|
|
docstring(1, getQuoteChar(style, level, side)));
|
2016-12-24 09:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetQuotes
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-03-01 16:02:20 +00:00
|
|
|
InsetQuotes::InsetQuotes(Buffer * buf, string const & str)
|
2017-07-03 17:53:14 +00:00
|
|
|
: Inset(buf),
|
2017-03-01 16:02:20 +00:00
|
|
|
style_(InsetQuotesParams::EnglishQuotes), side_(InsetQuotesParams::OpeningQuote),
|
2017-08-10 09:47:52 +00:00
|
|
|
pass_thru_(false), internal_fontenc_(false)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2016-12-26 13:41:14 +00:00
|
|
|
if (buf) {
|
2016-12-25 11:19:02 +00:00
|
|
|
global_style_ = buf->masterBuffer()->params().quotes_style;
|
2016-12-26 13:41:14 +00:00
|
|
|
fontspec_ = buf->masterBuffer()->params().useNonTeXFonts;
|
|
|
|
}
|
|
|
|
else {
|
2016-12-25 11:19:02 +00:00
|
|
|
global_style_ = InsetQuotesParams::EnglishQuotes;
|
2016-12-26 13:41:14 +00:00
|
|
|
fontspec_ = false;
|
|
|
|
}
|
2016-12-25 11:19:02 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
parseString(str);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-18 08:54:37 +00:00
|
|
|
|
2016-12-24 09:13:51 +00:00
|
|
|
InsetQuotes::InsetQuotes(Buffer * buf, char_type c, InsetQuotesParams::QuoteLevel level,
|
2016-12-20 16:55:43 +00:00
|
|
|
string const & side, string const & style)
|
2017-08-10 09:47:52 +00:00
|
|
|
: Inset(buf), level_(level), pass_thru_(false), fontspec_(false), internal_fontenc_(false)
|
2004-02-20 10:32:44 +00:00
|
|
|
{
|
2016-12-25 11:19:02 +00:00
|
|
|
bool dynamic = false;
|
2016-12-07 14:37:03 +00:00
|
|
|
if (buf) {
|
2016-12-25 11:19:02 +00:00
|
|
|
global_style_ = buf->masterBuffer()->params().quotes_style;
|
2017-02-25 11:49:49 +00:00
|
|
|
fontenc_ = buf->masterBuffer()->params().main_font_encoding();
|
2016-12-25 11:19:02 +00:00
|
|
|
dynamic = buf->masterBuffer()->params().dynamic_quotes;
|
2016-12-26 13:41:14 +00:00
|
|
|
fontspec_ = buf->masterBuffer()->params().useNonTeXFonts;
|
2016-12-07 14:37:03 +00:00
|
|
|
} else {
|
2016-12-25 11:19:02 +00:00
|
|
|
global_style_ = InsetQuotesParams::EnglishQuotes;
|
2016-12-07 14:37:03 +00:00
|
|
|
fontenc_ = lyxrc.fontenc;
|
2016-12-26 13:41:14 +00:00
|
|
|
fontspec_ = false;
|
2016-12-07 14:37:03 +00:00
|
|
|
}
|
2016-12-25 11:19:02 +00:00
|
|
|
if (style.empty())
|
|
|
|
style_ = dynamic ? InsetQuotesParams::DynamicQuotes : global_style_;
|
|
|
|
else
|
|
|
|
style_ = getStyle(style);
|
2016-06-09 14:42:24 +00:00
|
|
|
|
2016-12-24 13:27:00 +00:00
|
|
|
if (side == "left" || side == "opening")
|
|
|
|
side_ = InsetQuotesParams::OpeningQuote;
|
|
|
|
else if (side == "right" || side == "closing")
|
|
|
|
side_ = InsetQuotesParams::ClosingQuote;
|
2016-12-16 10:23:22 +00:00
|
|
|
else
|
|
|
|
setSide(c);
|
2004-02-20 10:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 22:33:04 +00:00
|
|
|
docstring InsetQuotes::layoutName() const
|
2007-11-01 22:17:22 +00:00
|
|
|
{
|
|
|
|
return from_ascii("Quotes");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-15 00:02:41 +00:00
|
|
|
void InsetQuotes::setSide(char_type c)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2016-12-24 13:27:00 +00:00
|
|
|
// Decide whether opening or closing quote
|
2016-12-27 11:06:54 +00:00
|
|
|
if (lyx::isSpace(c) || isOpenPunctuation(c))
|
2016-12-24 13:27:00 +00:00
|
|
|
side_ = InsetQuotesParams::OpeningQuote;// opening quote
|
2016-12-27 11:06:54 +00:00
|
|
|
else
|
2016-12-24 13:27:00 +00:00
|
|
|
side_ = InsetQuotesParams::ClosingQuote;// closing quote
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-18 09:29:35 +00:00
|
|
|
void InsetQuotes::parseString(string const & s, bool const allow_wildcards)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2017-01-05 13:25:36 +00:00
|
|
|
style_ = quoteparams.getQuoteStyle(s, allow_wildcards, style_);
|
|
|
|
side_ = quoteparams.getQuoteSide(s, allow_wildcards, side_);
|
|
|
|
level_ = quoteparams.getQuoteLevel(s, allow_wildcards, level_);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-18 08:54:37 +00:00
|
|
|
|
2016-12-24 09:13:51 +00:00
|
|
|
InsetQuotesParams::QuoteStyle InsetQuotes::getStyle(string const & s)
|
2016-12-16 10:23:22 +00:00
|
|
|
{
|
2016-12-24 09:13:51 +00:00
|
|
|
InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::EnglishQuotes;
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2016-12-16 10:23:22 +00:00
|
|
|
if (s == "english")
|
2016-12-24 09:13:51 +00:00
|
|
|
qs = InsetQuotesParams::EnglishQuotes;
|
2016-12-16 10:23:22 +00:00
|
|
|
else if (s == "swedish")
|
2016-12-24 09:13:51 +00:00
|
|
|
qs = InsetQuotesParams::SwedishQuotes;
|
2016-12-16 10:23:22 +00:00
|
|
|
else if (s == "german")
|
2016-12-24 09:13:51 +00:00
|
|
|
qs = InsetQuotesParams::GermanQuotes;
|
2016-12-16 10:23:22 +00:00
|
|
|
else if (s == "polish")
|
2016-12-24 09:13:51 +00:00
|
|
|
qs = InsetQuotesParams::PolishQuotes;
|
2016-12-24 13:27:00 +00:00
|
|
|
else if (s == "swiss")
|
|
|
|
qs = InsetQuotesParams::SwissQuotes;
|
2016-12-16 10:23:22 +00:00
|
|
|
else if (s == "danish")
|
2016-12-24 09:13:51 +00:00
|
|
|
qs = InsetQuotesParams::DanishQuotes;
|
2016-12-21 14:17:30 +00:00
|
|
|
else if (s == "plain")
|
2016-12-24 09:13:51 +00:00
|
|
|
qs = InsetQuotesParams::PlainQuotes;
|
2016-12-24 13:27:00 +00:00
|
|
|
else if (s == "british")
|
|
|
|
qs = InsetQuotesParams::BritishQuotes;
|
|
|
|
else if (s == "swedishg")
|
|
|
|
qs = InsetQuotesParams::SwedishGQuotes;
|
|
|
|
else if (s == "french")
|
|
|
|
qs = InsetQuotesParams::FrenchQuotes;
|
|
|
|
else if (s == "frenchin")
|
|
|
|
qs = InsetQuotesParams::FrenchINQuotes;
|
2016-12-26 09:47:28 +00:00
|
|
|
else if (s == "russian")
|
|
|
|
qs = InsetQuotesParams::RussianQuotes;
|
2016-12-26 13:03:48 +00:00
|
|
|
else if (s == "cjk")
|
|
|
|
qs = InsetQuotesParams::CJKQuotes;
|
|
|
|
else if (s == "cjkangle")
|
|
|
|
qs = InsetQuotesParams::CJKAngleQuotes;
|
2016-12-25 11:19:02 +00:00
|
|
|
else if (s == "dynamic")
|
|
|
|
qs = InsetQuotesParams::DynamicQuotes;
|
2016-12-16 10:23:22 +00:00
|
|
|
|
2016-12-20 16:55:43 +00:00
|
|
|
return qs;
|
2016-12-16 10:23:22 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2008-03-15 00:02:41 +00:00
|
|
|
docstring InsetQuotes::displayString() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2016-12-12 17:08:20 +00:00
|
|
|
// In PassThru, we use straight quotes
|
|
|
|
if (pass_thru_)
|
2016-12-24 13:27:00 +00:00
|
|
|
return (level_ == InsetQuotesParams::PrimaryQuotes) ?
|
2016-12-24 09:13:51 +00:00
|
|
|
from_ascii("\"") : from_ascii("'");
|
2016-12-10 10:53:42 +00:00
|
|
|
|
2016-12-25 11:19:02 +00:00
|
|
|
InsetQuotesParams::QuoteStyle style =
|
|
|
|
(style_ == InsetQuotesParams::DynamicQuotes) ? global_style_ : style_;
|
|
|
|
|
|
|
|
docstring retdisp = docstring(1, quoteparams.getQuoteChar(style, level_, side_));
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2016-12-10 13:57:25 +00:00
|
|
|
// in French, thin spaces are added inside double guillemets
|
|
|
|
if (prefixIs(context_lang_, "fr")
|
2016-12-24 13:27:00 +00:00
|
|
|
&& level_ == InsetQuotesParams::PrimaryQuotes
|
2016-12-25 11:19:02 +00:00
|
|
|
&& (style == InsetQuotesParams::SwissQuotes
|
|
|
|
|| style == InsetQuotesParams::FrenchQuotes
|
|
|
|
|| style == InsetQuotesParams::FrenchINQuotes)) {
|
2016-07-18 10:17:01 +00:00
|
|
|
// THIN SPACE (U+2009)
|
|
|
|
char_type const thin_space = 0x2009;
|
2016-12-24 13:27:00 +00:00
|
|
|
if (side_ == InsetQuotesParams::OpeningQuote)
|
2016-07-18 10:17:01 +00:00
|
|
|
retdisp += thin_space;
|
2001-07-20 09:38:19 +00:00
|
|
|
else
|
2016-07-18 10:17:01 +00:00
|
|
|
retdisp = thin_space + retdisp;
|
2001-07-20 09:38:19 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2006-10-21 19:27:02 +00:00
|
|
|
return retdisp;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo & font = mi.base.font;
|
2016-07-18 10:17:01 +00:00
|
|
|
frontend::FontMetrics const & fm = theFontMetrics(font);
|
2006-10-07 16:15:06 +00:00
|
|
|
dim.asc = fm.maxAscent();
|
|
|
|
dim.des = fm.maxDescent();
|
2016-07-18 10:17:01 +00:00
|
|
|
dim.wid = fm.width(displayString());
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
void InsetQuotes::draw(PainterInfo & pi, int x, int y) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2012-04-29 10:31:31 +00:00
|
|
|
FontInfo font = pi.base.font;
|
2016-12-25 11:19:02 +00:00
|
|
|
if (style_ == InsetQuotesParams::DynamicQuotes)
|
|
|
|
font.setPaintColor(Color_special);
|
|
|
|
else
|
|
|
|
font.setPaintColor(pi.textColor(font.realColor()));
|
2016-07-18 10:17:01 +00:00
|
|
|
pi.pain.text(x, y, displayString(), font);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2016-12-18 08:54:37 +00:00
|
|
|
|
2016-12-17 11:58:33 +00:00
|
|
|
string InsetQuotes::getType() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string text;
|
2016-12-20 16:55:43 +00:00
|
|
|
text += style_char[style_];
|
2001-07-20 09:38:19 +00:00
|
|
|
text += side_char[side_];
|
2016-12-20 16:55:43 +00:00
|
|
|
text += level_char[level_];
|
2016-12-17 11:58:33 +00:00
|
|
|
return text;
|
|
|
|
}
|
2016-12-18 08:54:37 +00:00
|
|
|
|
|
|
|
|
2016-12-17 11:58:33 +00:00
|
|
|
void InsetQuotes::write(ostream & os) const
|
|
|
|
{
|
|
|
|
os << "Quotes " << getType();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetQuotes::read(Lexer & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetQuotes::read");
|
2004-10-05 12:56:22 +00:00
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
parseString(lex.getString());
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> "\\end_inset";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-17 11:58:33 +00:00
|
|
|
void InsetQuotes::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
|
|
|
switch (cmd.action()) {
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
string const first_arg = cmd.getArg(0);
|
|
|
|
bool const change_type = first_arg == "changetype";
|
|
|
|
if (!change_type) {
|
|
|
|
// not for us
|
|
|
|
// this will not be handled higher up
|
|
|
|
cur.undispatched();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cur.recordUndoInset(this);
|
2016-12-18 09:29:35 +00:00
|
|
|
parseString(cmd.getArg(1), true);
|
2016-12-17 11:58:33 +00:00
|
|
|
cur.buffer()->updateBuffer();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
Inset::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetQuotes::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
|
|
|
switch (cmd.action()) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
string const first_arg = cmd.getArg(0);
|
|
|
|
if (first_arg == "changetype") {
|
|
|
|
string const type = cmd.getArg(1);
|
|
|
|
flag.setOnOff(type == getType());
|
|
|
|
flag.setEnabled(!pass_thru_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return Inset::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Inset::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2016-12-25 11:19:02 +00:00
|
|
|
InsetQuotesParams::QuoteStyle style =
|
|
|
|
(style_ == InsetQuotesParams::DynamicQuotes) ? global_style_ : style_;
|
|
|
|
char_type quotechar = quoteparams.getQuoteChar(style, level_, side_);
|
2016-12-15 09:26:42 +00:00
|
|
|
docstring qstr;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2016-12-12 17:08:20 +00:00
|
|
|
// In pass-thru context, we output plain quotes
|
|
|
|
if (runparams.pass_thru)
|
2016-12-24 13:27:00 +00:00
|
|
|
qstr = (level_ == InsetQuotesParams::PrimaryQuotes) ? from_ascii("\"") : from_ascii("'");
|
2016-12-26 13:41:14 +00:00
|
|
|
else if (style == InsetQuotesParams::PlainQuotes && fontspec_) {
|
2016-12-21 14:17:30 +00:00
|
|
|
// For XeTeX and LuaTeX,we need to disable mapping to get straight
|
|
|
|
// quotes. We define our own commands that do this
|
2016-12-24 13:27:00 +00:00
|
|
|
qstr = (level_ == InsetQuotesParams::PrimaryQuotes) ?
|
2016-12-21 14:17:30 +00:00
|
|
|
from_ascii("\\textquotedblplain") : from_ascii("\\textquotesingleplain");
|
|
|
|
}
|
2016-12-15 09:41:10 +00:00
|
|
|
else if (runparams.use_polyglossia) {
|
2017-07-03 17:53:14 +00:00
|
|
|
// For polyglossia, we directly output the respective unicode chars
|
2016-12-15 09:41:10 +00:00
|
|
|
// (spacing and kerning is then handled respectively)
|
2016-12-24 09:13:51 +00:00
|
|
|
qstr = docstring(1, quotechar);
|
2016-12-15 09:41:10 +00:00
|
|
|
}
|
2016-12-26 13:03:48 +00:00
|
|
|
else if (style == InsetQuotesParams::CJKQuotes || style == InsetQuotesParams::CJKAngleQuotes) {
|
|
|
|
if (runparams.encoding && runparams.encoding->encodable(quotechar))
|
|
|
|
qstr = docstring(1, quotechar);
|
|
|
|
else
|
|
|
|
qstr = quoteparams.getLaTeXQuote(quotechar, "int");
|
|
|
|
}
|
2016-12-25 11:19:02 +00:00
|
|
|
else if ((style == InsetQuotesParams::SwissQuotes
|
|
|
|
|| style == InsetQuotesParams::FrenchQuotes
|
|
|
|
|| style == InsetQuotesParams::FrenchINQuotes)
|
2016-12-24 13:27:00 +00:00
|
|
|
&& level_ == InsetQuotesParams::PrimaryQuotes
|
2016-12-15 09:41:10 +00:00
|
|
|
&& prefixIs(runparams.local_font->language()->code(), "fr")) {
|
2016-12-10 16:25:04 +00:00
|
|
|
// Specific guillemets of French babel
|
|
|
|
// including correct French spacing
|
2016-12-24 13:27:00 +00:00
|
|
|
if (side_ == InsetQuotesParams::OpeningQuote)
|
2016-12-15 09:26:42 +00:00
|
|
|
qstr = from_ascii("\\og");
|
2002-03-21 17:09:55 +00:00
|
|
|
else
|
2016-12-15 09:26:42 +00:00
|
|
|
qstr = from_ascii("\\fg");
|
2016-12-12 17:08:20 +00:00
|
|
|
} else if (fontenc_ == "T1"
|
2016-12-15 09:41:10 +00:00
|
|
|
&& !runparams.local_font->language()->internalFontEncoding()) {
|
2016-12-10 16:25:04 +00:00
|
|
|
// Quotation marks for T1 font encoding
|
|
|
|
// (using ligatures)
|
2016-12-24 09:13:51 +00:00
|
|
|
qstr = quoteparams.getLaTeXQuote(quotechar, "t1");
|
2016-12-12 17:08:20 +00:00
|
|
|
} else if (runparams.local_font->language()->internalFontEncoding()) {
|
|
|
|
// Quotation marks for internal font encodings
|
|
|
|
// (ligatures not featured)
|
2016-12-24 09:13:51 +00:00
|
|
|
qstr = quoteparams.getLaTeXQuote(quotechar, "int");
|
2001-02-25 10:22:54 +00:00
|
|
|
#ifdef DO_USE_DEFAULT_LANGUAGE
|
2000-07-15 23:51:46 +00:00
|
|
|
} else if (doclang == "default") {
|
2001-02-25 10:22:54 +00:00
|
|
|
#else
|
2016-12-10 16:25:04 +00:00
|
|
|
} else if (!runparams.use_babel || runparams.isFullUnicode()) {
|
2001-02-25 10:22:54 +00:00
|
|
|
#endif
|
2016-12-10 16:25:04 +00:00
|
|
|
// Standard quotation mark macros
|
2016-12-15 09:41:10 +00:00
|
|
|
// These are also used by babel
|
|
|
|
// without fontenc (XeTeX/LuaTeX)
|
2016-12-24 09:13:51 +00:00
|
|
|
qstr = quoteparams.getLaTeXQuote(quotechar, "ot1");
|
2002-03-21 17:09:55 +00:00
|
|
|
} else {
|
2016-12-10 16:25:04 +00:00
|
|
|
// Babel shorthand quotation marks (for T1/OT1)
|
2016-12-24 09:13:51 +00:00
|
|
|
qstr = quoteparams.getLaTeXQuote(quotechar, "babel");
|
2001-07-20 09:38:19 +00:00
|
|
|
}
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2016-12-12 17:08:20 +00:00
|
|
|
if (!runparams.pass_thru) {
|
2016-12-15 09:26:42 +00:00
|
|
|
// Guard against unwanted ligatures with preceding text
|
2016-12-10 10:53:42 +00:00
|
|
|
char_type const lastchar = os.lastChar();
|
2016-12-15 09:26:42 +00:00
|
|
|
// !` ?` => !{}` ?{}`
|
|
|
|
if (prefixIs(qstr, from_ascii("`"))
|
|
|
|
&& (lastchar == '!' || lastchar == '?'))
|
|
|
|
os << "{}";
|
|
|
|
// ``` ''' ,,, <<< >>>
|
|
|
|
// => `{}`` '{}'' ,{},, <{}<< >{}>>
|
|
|
|
if (contains(from_ascii(",'`<>"), lastchar)
|
|
|
|
&& prefixIs(qstr, lastchar))
|
|
|
|
os << "{}";
|
2011-08-05 11:23:00 +00:00
|
|
|
}
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2016-12-15 09:26:42 +00:00
|
|
|
os << qstr;
|
2016-12-12 17:00:28 +00:00
|
|
|
|
2016-12-26 13:03:48 +00:00
|
|
|
if (prefixIs(qstr, from_ascii("\\")) && !suffixIs(qstr, '}'))
|
2016-12-12 14:57:42 +00:00
|
|
|
// properly terminate the command depending on the context
|
|
|
|
os << termcmd;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
int InsetQuotes::plaintext(odocstringstream & os,
|
2013-03-08 19:52:18 +00:00
|
|
|
OutputParams const &, size_t) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
2008-03-15 00:02:41 +00:00
|
|
|
docstring const str = displayString();
|
2007-02-17 11:30:58 +00:00
|
|
|
os << str;
|
|
|
|
return str.size();
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-09 22:24:13 +00:00
|
|
|
docstring InsetQuotes::getQuoteEntity() const {
|
2016-12-25 11:19:02 +00:00
|
|
|
InsetQuotesParams::QuoteStyle style =
|
|
|
|
(style_ == InsetQuotesParams::DynamicQuotes) ? global_style_ : style_;
|
|
|
|
docstring res = quoteparams.getHTMLQuote(quoteparams.getQuoteChar(style, level_, side_));
|
2016-12-10 15:13:02 +00:00
|
|
|
// in French, thin spaces are added inside double guillemets
|
|
|
|
if (prefixIs(context_lang_, "fr")
|
2016-12-24 13:27:00 +00:00
|
|
|
&& level_ == InsetQuotesParams::PrimaryQuotes
|
2016-12-25 11:19:02 +00:00
|
|
|
&& (style == InsetQuotesParams::FrenchQuotes
|
|
|
|
|| style == InsetQuotesParams::FrenchINQuotes
|
|
|
|
|| style == InsetQuotesParams::SwissQuotes)) {
|
2016-12-10 15:13:02 +00:00
|
|
|
// THIN SPACE (U+2009)
|
|
|
|
docstring const thin_space = from_ascii(" ");
|
2016-12-24 13:27:00 +00:00
|
|
|
if (side_ == InsetQuotesParams::OpeningQuote)
|
2016-12-10 15:13:02 +00:00
|
|
|
res += thin_space;
|
|
|
|
else
|
|
|
|
res = thin_space + res;
|
|
|
|
}
|
|
|
|
return res;
|
2015-02-09 22:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetQuotes::docbook(odocstream & os, OutputParams const &) const
|
|
|
|
{
|
|
|
|
os << getQuoteEntity();
|
2000-03-06 02:42:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2015-02-14 10:32:39 +00:00
|
|
|
docstring InsetQuotes::xhtml(XHTMLStream & xs, OutputParams const &) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
2015-02-09 22:24:13 +00:00
|
|
|
xs << XHTMLStream::ESCAPE_NONE << getQuoteEntity();
|
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 InsetQuotes::toString(odocstream & os) const
|
2005-11-25 14:40:34 +00:00
|
|
|
{
|
2008-03-15 00:02:41 +00:00
|
|
|
os << displayString();
|
2005-11-25 14:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-04 18:38:47 +00:00
|
|
|
void InsetQuotes::forOutliner(docstring & os, size_t const, bool const) const
|
2010-12-20 21:55:09 +00:00
|
|
|
{
|
|
|
|
os += displayString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-10 10:53:42 +00:00
|
|
|
void InsetQuotes::updateBuffer(ParIterator const & it, UpdateType /* utype*/)
|
|
|
|
{
|
|
|
|
BufferParams const & bp = buffer().masterBuffer()->params();
|
|
|
|
pass_thru_ = it.paragraph().isPassThru();
|
|
|
|
context_lang_ = it.paragraph().getFontSettings(bp, it.pos()).language()->code();
|
2017-08-10 09:47:52 +00:00
|
|
|
internal_fontenc_ = it.paragraph().getFontSettings(bp, it.pos()).language()->internalFontEncoding();
|
2017-02-25 11:49:49 +00:00
|
|
|
fontenc_ = bp.main_font_encoding();
|
2016-12-25 11:19:02 +00:00
|
|
|
global_style_ = bp.quotes_style;
|
2016-12-26 13:41:14 +00:00
|
|
|
fontspec_ = bp.useNonTeXFonts;
|
2016-12-10 10:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
void InsetQuotes::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2016-12-25 11:19:02 +00:00
|
|
|
InsetQuotesParams::QuoteStyle style =
|
|
|
|
(style_ == InsetQuotesParams::DynamicQuotes) ? global_style_ : style_;
|
|
|
|
char_type type = quoteparams.getQuoteChar(style, level_, side_);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2016-12-24 09:13:51 +00:00
|
|
|
// Handle characters that are not natively supported by
|
|
|
|
// specific font encodings (we roll our own definitions)
|
2001-07-23 09:11:14 +00:00
|
|
|
#ifdef DO_USE_DEFAULT_LANGUAGE
|
2002-03-21 17:09:55 +00:00
|
|
|
if (features.bufferParams().language->lang() == "default"
|
2001-07-23 09:11:14 +00:00
|
|
|
#else
|
2015-09-20 19:39:59 +00:00
|
|
|
if (!features.useBabel()
|
2001-07-23 09:11:14 +00:00
|
|
|
#endif
|
2016-12-21 14:17:30 +00:00
|
|
|
&& !features.runparams().isFullUnicode() && fontenc_ != "T1") {
|
2016-12-24 09:13:51 +00:00
|
|
|
switch (type) {
|
|
|
|
case 0x201a:
|
|
|
|
features.require("quotesinglbase");
|
2016-12-21 14:17:30 +00:00
|
|
|
break;
|
2016-12-24 09:13:51 +00:00
|
|
|
case 0x2039:
|
|
|
|
features.require("guilsinglleft");
|
|
|
|
break;
|
|
|
|
case 0x203a:
|
|
|
|
features.require("guilsinglright");
|
|
|
|
break;
|
|
|
|
case 0x201e:
|
|
|
|
features.require("quotedblbase");
|
|
|
|
break;
|
|
|
|
case 0x00ab:
|
|
|
|
features.require("guillemotleft");
|
|
|
|
break;
|
|
|
|
case 0x00bb:
|
|
|
|
features.require("guillemotright");
|
2016-12-21 14:17:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-12-24 09:13:51 +00:00
|
|
|
}
|
|
|
|
// Handle straight quotation marks. These need special care
|
|
|
|
// in most output formats
|
|
|
|
switch (type) {
|
|
|
|
case 0x0027: {
|
2016-12-26 13:41:14 +00:00
|
|
|
if (features.runparams().isFullUnicode() && fontspec_)
|
2016-12-24 09:13:51 +00:00
|
|
|
features.require("textquotesinglep");
|
|
|
|
else
|
|
|
|
features.require("textcomp");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x0022: {
|
2016-12-26 13:41:14 +00:00
|
|
|
if (features.runparams().isFullUnicode() && fontspec_)
|
2016-12-24 09:13:51 +00:00
|
|
|
features.require("textquotedblp");
|
2017-08-10 09:47:52 +00:00
|
|
|
else if (fontenc_ != "T1" || internal_fontenc_)
|
2016-12-24 09:13:51 +00:00
|
|
|
features.require("textquotedbl");
|
|
|
|
break;
|
|
|
|
}
|
2016-12-26 13:03:48 +00:00
|
|
|
// we fake these from math
|
|
|
|
case 0x300e: // LEFT WHITE CORNER BRACKET
|
|
|
|
case 0x300f: // RIGHT WHITE CORNER BRACKET
|
|
|
|
if (!features.runparams().encoding
|
|
|
|
|| !features.runparams().encoding->encodable(type))
|
|
|
|
features.require("stmaryrd");
|
|
|
|
break;
|
2016-12-24 09:13:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-12-21 14:17:30 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-17 11:58:33 +00:00
|
|
|
|
|
|
|
string InsetQuotes::contextMenuName() const
|
|
|
|
{
|
|
|
|
return "context-quote";
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|