2 * \file InsetQuotes.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "InsetQuotes.h"
17 #include "BufferParams.h"
18 #include "BufferView.h"
20 #include "Dimension.h"
23 #include "FuncStatus.h"
24 #include "FuncRequest.h"
26 #include "LaTeXFeatures.h"
28 #include "MetricsInfo.h"
29 #include "Paragraph.h"
30 #include "ParIterator.h"
31 #include "texstream.h"
34 #include "frontends/FontMetrics.h"
35 #include "frontends/Painter.h"
37 #include "support/debug.h"
38 #include "support/docstring.h"
39 #include "support/docstream.h"
40 #include "support/gettext.h"
41 #include "support/Lexer.h"
42 #include "support/lstrings.h"
43 #include "support/textutils.h"
48 using namespace lyx::support;
54 /* codes used to read/write quotes to LyX files
56 * e ``english'' (`inner quotation')
57 * s ''swedish'' ('inner quotation')
58 * g ,,german`` (,inner quotation`)
59 * p ,,polish'' (,inner quotation')
60 * c <<swiss>> (<inner quotation>)
61 * a >>danish<< (>inner quotation<)
62 * q "plain" ('inner quotation')
63 * b `british' (``inner quotation'')
64 * w >>swedishg>> ('inner quotation') ["g" = Guillemets]
65 * f <<french>> (``inner quotation'')
66 * i <<frenchin>> (<<inner quotation>>) ["in" = Imprimerie Nationale]
67 * r <<russian>> (,,inner quotation``)
68 * j [U+300C]cjk[U+300D] ([U+300E]inner quotation[U+300F]) [CORNER BRACKETS]
69 * k [U+300A]cjkangle[U+300B] ([U+3008]inner quotation[U+3009]) [ANGLE BRACKETS]
70 * h ,,hungarian'' (>>inner quotation<<)
71 * d ''hebrew,, ('inner quotation,)
72 * x dynamic style (inherits document settings)
75 char const * const style_char = "esgpcaqbwfirjkhdx";
76 char const * const side_char = "lr" ;
77 char const * const level_char = "sd";
82 /////////////////////////////////////////////////////////////////////
86 ///////////////////////////////////////////////////////////////////////
88 InsetQuotesParams quoteparams;
91 int InsetQuotesParams::stylescount() const
93 return strlen(style_char);
97 char InsetQuotesParams::getStyleChar(QuoteStyle const & style) const
99 return style_char[static_cast<int>(style)];
103 QuoteStyle InsetQuotesParams::getQuoteStyle(string const & s,
104 bool const allow_wildcards, QuoteStyle fb) const
109 if (str.length() != 3) {
110 LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
111 " bad string length.");
115 // '.' wildcard means: keep current style
116 if (!allow_wildcards || str[0] != '.') {
118 for (i = 0; i < stylescount(); ++i) {
119 if (str[0] == style_char[i]) {
124 if (i >= stylescount()) {
125 LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
126 " bad style specification.");
127 res = QuoteStyle::English;
135 QuoteSide InsetQuotesParams::getQuoteSide(string const & s,
136 bool const allow_wildcards, QuoteSide fb) const
141 if (str.length() != 3) {
142 LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
143 " bad string length.");
147 // '.' wildcard means: keep current side
148 if (!allow_wildcards || str[1] != '.') {
150 for (i = 0; i < 2; ++i) {
151 if (str[1] == side_char[i]) {
157 LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
158 " bad side specification.");
159 res = QuoteSide::Opening;
167 QuoteLevel InsetQuotesParams::getQuoteLevel(string const & s,
168 bool const allow_wildcards, QuoteLevel fb) const
173 if (str.length() != 3) {
174 LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
175 " bad string length.");
179 // '.' wildcard means: keep current level
180 if (!allow_wildcards || str[2] != '.') {
182 for (i = 0; i < 2; ++i) {
183 if (str[2] == level_char[i]) {
189 LYXERR0("ERROR (InsetQuotes::InsetQuotes):"
190 " bad level specification.");
191 res = QuoteLevel::Primary;
199 char_type InsetQuotesParams::getQuoteChar(QuoteStyle const & style, QuoteLevel const & level,
200 QuoteSide const & side, bool const rtl) const
202 // main opening quotation mark
203 char_type left_primary;
204 // main closing quotation mark
205 char_type right_primary;
206 // secondary (inner, 'single') opening quotation mark
207 char_type left_secondary;
208 // secondary (inner, 'single') closing quotation mark
209 char_type right_secondary;
212 case QuoteStyle::English: {
213 left_primary = 0x201c; // ``
214 right_primary = 0x201d; // ''
215 left_secondary = 0x2018; // `
216 right_secondary = 0x2019; // '
219 case QuoteStyle::Swedish: {
220 left_primary = 0x201d; // ''
221 right_primary = 0x201d; // ''
222 left_secondary = 0x2019; // '
223 right_secondary = 0x2019; // '
226 case QuoteStyle::German: {
227 left_primary = 0x201e; // ,,
228 right_primary = 0x201c; // ``
229 left_secondary = 0x201a; // ,
230 right_secondary = 0x2018; // `
233 case QuoteStyle::Polish: {
234 left_primary = 0x201e; // ,,
235 right_primary = 0x201d; // ''
236 left_secondary = 0x201a; // ,
237 right_secondary = 0x2019; // '
240 case QuoteStyle::Swiss: {
241 left_primary = 0x00ab; // <<
242 right_primary = 0x00bb; // >>
243 left_secondary = 0x2039; // <
244 right_secondary = 0x203a; // >
247 case QuoteStyle::Danish: {
248 left_primary = 0x00bb; // >>
249 right_primary = 0x00ab; // <<
250 left_secondary = 0x203a; // >
251 right_secondary = 0x2039; // <
254 case QuoteStyle::Plain: {
255 left_primary = 0x0022; // "
256 right_primary = 0x0022; // "
257 left_secondary = 0x0027; // '
258 right_secondary = 0x0027; // '
261 case QuoteStyle::British: {
262 left_primary = 0x2018; // `
263 right_primary = 0x2019; // '
264 left_secondary = 0x201c; // ``
265 right_secondary = 0x201d; // ''
268 case QuoteStyle::SwedishG: {
269 left_primary = 0x00bb; // >>
270 right_primary = 0x00bb; // >>
271 left_secondary = 0x2019; // '
272 right_secondary = 0x2019; // '
275 case QuoteStyle::French: {
276 left_primary = 0x00ab; // <<
277 right_primary = 0x00bb; // >>
278 left_secondary = 0x201c; // ``
279 right_secondary = 0x201d; // ''
282 case QuoteStyle::FrenchIN:{
283 left_primary = 0x00ab; // <<
284 right_primary = 0x00bb; // >>
285 left_secondary = 0x00ab; // <<
286 right_secondary = 0x00bb; // >>
289 case QuoteStyle::Russian:{
290 left_primary = 0x00ab; // <<
291 right_primary = 0x00bb; // >>
292 left_secondary = 0x201e; // ,,
293 right_secondary = 0x201c; // ``
296 case QuoteStyle::CJK:{
297 left_primary = 0x300c; // LEFT CORNER BRACKET
298 right_primary = 0x300d; // RIGHT CORNER BRACKET
299 left_secondary = 0x300e; // LEFT WHITE CORNER BRACKET
300 right_secondary = 0x300f; // RIGHT WHITE CORNER BRACKET
303 case QuoteStyle::CJKAngle:{
304 left_primary = 0x300a; // LEFT DOUBLE ANGLE BRACKET
305 right_primary = 0x300b; // RIGHT DOUBLE ANGLE BRACKET
306 left_secondary = 0x3008; // LEFT ANGLE BRACKET
307 right_secondary = 0x3009; // RIGHT ANGLE BRACKET
310 case QuoteStyle::Hungarian: {
311 left_primary = 0x201e; // ,,
312 right_primary = 0x201d; // ''
313 left_secondary = 0x00bb; // >>
314 right_secondary = 0x00ab; // <<
317 case QuoteStyle::Hebrew: {
318 left_primary = 0x201d; // ''
319 right_primary = 0x201e; // ,,
320 left_secondary = 0x2019; // '
321 right_secondary = 0x201a; // ,
324 case QuoteStyle::Dynamic:
327 left_primary = 0x003f; // ?
328 right_primary = 0x003f; // ?
329 left_secondary = 0x003f; // ?
330 right_secondary = 0x003f; // ?
335 case QuoteLevel::Secondary:
337 return (side == QuoteSide::Closing) ? left_secondary : right_secondary;
338 return (side == QuoteSide::Opening) ? left_secondary : right_secondary;
339 case QuoteLevel::Primary:
341 return (side == QuoteSide::Closing) ? left_primary : right_primary;
342 return (side == QuoteSide::Opening) ? left_primary : right_primary;
352 docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op,
353 bool const rtl) const
362 res = "\\quotesinglbase";
367 // This macro is redefined in rtl mode
368 res = rtl ? "\\textquoteleft" : "\\textquoteright";
375 // This macro is redefined in rtl mode
376 res = rtl ? "\\textquoteright" : "\\textquoteleft";
385 res = "\\guilsinglleft";
392 res = "\\guilsinglright";
395 case 0x0027: {// ' (plain)
396 res = "\\textquotesingle";
402 else if (op == "babel")
405 res = "\\quotedblbase";
410 // This macro is redefined in rtl mode
411 res = rtl ? "\\textquotedblleft" : "\\textquotedblright";
418 // This macro is redefined in rtl mode
419 res = rtl ? "\\textquotedblright" : "\\textquotedblleft";
427 else if (op == "babel")
430 res = "\\guillemotleft";
436 else if (op == "babel")
439 res = "\\guillemotright";
443 res = "\\textquotedbl";
446 // The following are fakes
447 // This is just to get something symbolic
448 // in encodings where this chars would not be used anyway
449 case 0x300c: // LEFT CORNER BRACKET
450 res = "\\ensuremath{\\lceil}";
452 case 0x300d: // RIGHT CORNER BRACKET
453 res = "\\ensuremath{\\rfloor}";
455 case 0x300e: // LEFT WHITE CORNER BRACKET
456 res = "\\ensuremath{\\llceil}";
458 case 0x300f: // RIGHT WHITE CORNER BRACKET
459 res = "\\ensuremath{\\rrfloor}";
461 case 0x300a: // LEFT DOUBLE ANGLE BRACKET
462 res = "\\ensuremath{\\langle\\kern-2.5pt\\langle}";
464 case 0x300b: // RIGHT DOUBLE ANGLE BRACKET
465 res = "\\ensuremath{\\rangle\\kern-2.5pt\\rangle}";
467 case 0x3008: // LEFT ANGLE BRACKET
468 res = "\\ensuremath{\\langle}";
470 case 0x3009: // RIGHT ANGLE BRACKET
471 res = "\\ensuremath{\\rangle}";
477 return from_ascii(res);
481 docstring InsetQuotesParams::getXMLQuote(char_type c) const
483 // Directly output the character Unicode form.
484 return from_ascii("&#" + to_string(c) + ";");
488 map<string, docstring> InsetQuotesParams::getTypes() const
490 map<string, docstring> res;
498 // get all quote types
499 for (sty = 0; sty < stylescount(); ++sty) {
500 style = QuoteStyle(sty);
501 if (style == QuoteStyle::Dynamic)
503 for (sid = 0; sid < 2; ++sid) {
504 side = QuoteSide(sid);
505 for (lev = 0; lev < 2; ++lev) {
506 type += style_char[static_cast<int>(style)];
507 type += side_char[sid];
508 level = QuoteLevel(lev);
509 type += level_char[lev];
510 res[type] = docstring(1, getQuoteChar(style, level, side));
519 docstring const InsetQuotesParams::getGuiLabel(QuoteStyle const & qs, bool langdef) const
521 docstring const styledesc =
522 bformat(_("%1$souter%2$s and %3$sinner%4$s[[quotation marks]]"),
523 docstring(1, getQuoteChar(qs, QuoteLevel::Primary, QuoteSide::Opening)),
524 docstring(1, getQuoteChar(qs, QuoteLevel::Primary, QuoteSide::Closing)),
525 docstring(1, getQuoteChar(qs, QuoteLevel::Secondary, QuoteSide::Opening)),
526 docstring(1, getQuoteChar(qs, QuoteLevel::Secondary, QuoteSide::Closing))
532 return bformat(_("%1$s[[quot. mark description]] (language default)"),
537 docstring const InsetQuotesParams::getShortGuiLabel(docstring const & str) const
539 string const s = to_ascii(str);
540 QuoteStyle const style = getQuoteStyle(s);
541 QuoteSide const side = getQuoteSide(s);
542 QuoteLevel const level = getQuoteLevel(s);
544 return (side == QuoteSide::Opening) ?
545 bformat(_("%1$stext"),
546 docstring(1, getQuoteChar(style, level, side))) :
547 bformat(_("text%1$s"),
548 docstring(1, getQuoteChar(style, level, side)));
552 /////////////////////////////////////////////////////////////////////
556 ///////////////////////////////////////////////////////////////////////
558 InsetQuotes::InsetQuotes(Buffer * buf, string const & str)
562 global_style_ = buf->masterBuffer()->params().quotes_style;
563 fontspec_ = buf->masterBuffer()->params().useNonTeXFonts;
570 InsetQuotes::InsetQuotes(Buffer * buf, char_type c, QuoteLevel level,
571 string const & side, string const & style)
572 : Inset(buf), level_(level)
574 bool dynamic = false;
576 global_style_ = buf->masterBuffer()->params().quotes_style;
577 dynamic = buf->masterBuffer()->params().dynamic_quotes;
578 fontspec_ = buf->masterBuffer()->params().useNonTeXFonts;
581 style_ = dynamic ? QuoteStyle::Dynamic : global_style_;
583 style_ = getStyle(style);
585 if (side == "left" || side == "opening")
586 side_ = QuoteSide::Opening;
587 else if (side == "right" || side == "closing")
588 side_ = QuoteSide::Closing;
594 docstring InsetQuotes::layoutName() const
596 return from_ascii("Quotes");
600 void InsetQuotes::setSide(char_type c)
602 // Decide whether opening or closing quote
603 if (lyx::isSpace(c) || isOpenPunctuation(c))
604 side_ = QuoteSide::Opening;// opening quote
606 side_ = QuoteSide::Closing;// closing quote
610 void InsetQuotes::parseString(string const & s, bool const allow_wildcards)
612 style_ = quoteparams.getQuoteStyle(s, allow_wildcards, style_);
613 side_ = quoteparams.getQuoteSide(s, allow_wildcards, side_);
614 level_ = quoteparams.getQuoteLevel(s, allow_wildcards, level_);
618 QuoteStyle InsetQuotes::getStyle(string const & s)
620 QuoteStyle qs = QuoteStyle::English;
623 qs = QuoteStyle::English;
624 else if (s == "swedish")
625 qs = QuoteStyle::Swedish;
626 else if (s == "german")
627 qs = QuoteStyle::German;
628 else if (s == "polish")
629 qs = QuoteStyle::Polish;
630 else if (s == "swiss")
631 qs = QuoteStyle::Swiss;
632 else if (s == "danish")
633 qs = QuoteStyle::Danish;
634 else if (s == "plain")
635 qs = QuoteStyle::Plain;
636 else if (s == "british")
637 qs = QuoteStyle::British;
638 else if (s == "swedishg")
639 qs = QuoteStyle::SwedishG;
640 else if (s == "french")
641 qs = QuoteStyle::French;
642 else if (s == "frenchin")
643 qs = QuoteStyle::FrenchIN;
644 else if (s == "russian")
645 qs = QuoteStyle::Russian;
647 qs = QuoteStyle::CJK;
648 else if (s == "cjkangle")
649 qs = QuoteStyle::CJKAngle;
650 else if (s == "hungarian")
651 qs = QuoteStyle::Hungarian;
652 else if (s == "hebrew")
653 qs = QuoteStyle::Hebrew;
654 else if (s == "dynamic")
655 qs = QuoteStyle::Dynamic;
661 docstring InsetQuotes::displayString() const
663 // In PassThru, we use straight quotes
665 return (level_ == QuoteLevel::Primary) ?
666 from_ascii("\"") : from_ascii("'");
669 (style_ == QuoteStyle::Dynamic) ? global_style_ : style_;
671 docstring retdisp = docstring(1, quoteparams.getQuoteChar(style, level_, side_, rtl_));
673 // in French, thin spaces are added inside double guillemets
674 if (prefixIs(context_lang_, "fr")
675 && level_ == QuoteLevel::Primary
676 && (style == QuoteStyle::Swiss
677 || style == QuoteStyle::French
678 || style == QuoteStyle::FrenchIN)) {
679 // THIN SPACE (U+2009)
680 char_type const thin_space = 0x2009;
681 if (side_ == QuoteSide::Opening)
682 retdisp += thin_space;
684 retdisp = thin_space + retdisp;
691 void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const
693 FontInfo & font = mi.base.font;
694 frontend::FontMetrics const & fm = theFontMetrics(font);
695 dim.asc = fm.maxAscent();
696 dim.des = fm.maxDescent();
697 dim.wid = fm.width(displayString());
701 void InsetQuotes::draw(PainterInfo & pi, int x, int y) const
703 FontInfo font = pi.base.font;
704 if (style_ == QuoteStyle::Dynamic)
705 font.setPaintColor(Color_special);
707 font.setPaintColor(pi.textColor(font.realColor()));
708 pi.pain.text(x, y, displayString(), font);
712 string InsetQuotes::getType() const
715 text += style_char[static_cast<int>(style_)];
716 text += side_char[static_cast<int>(side_)];
717 text += level_char[static_cast<int>(level_)];
722 void InsetQuotes::write(ostream & os) const
724 os << "Quotes " << getType();
728 void InsetQuotes::read(Lexer & lex)
730 lex.setContext("InsetQuotes::read");
732 parseString(lex.getString());
733 lex >> "\\end_inset";
737 void InsetQuotes::doDispatch(Cursor & cur, FuncRequest & cmd)
739 switch (cmd.action()) {
740 case LFUN_INSET_MODIFY: {
741 string const first_arg = cmd.getArg(0);
742 bool const change_type = first_arg == "changetype";
745 // this will not be handled higher up
749 cur.recordUndoInset(this);
750 parseString(cmd.getArg(1), true);
751 cur.forceBufferUpdate();
755 Inset::doDispatch(cur, cmd);
761 bool InsetQuotes::getStatus(Cursor & cur, FuncRequest const & cmd,
762 FuncStatus & flag) const
764 switch (cmd.action()) {
766 case LFUN_INSET_MODIFY: {
767 string const first_arg = cmd.getArg(0);
768 if (first_arg == "changetype") {
769 string const type = cmd.getArg(1);
770 flag.setOnOff(type == getType());
771 flag.setEnabled(!pass_thru_);
774 return Inset::getStatus(cur, cmd, flag);
778 return Inset::getStatus(cur, cmd, flag);
783 void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
786 (style_ == QuoteStyle::Dynamic) ? global_style_ : style_;
787 char_type quotechar = quoteparams.getQuoteChar(style, level_, side_, rtl_);
790 // In pass-thru context, we output plain quotes
791 if (runparams.pass_thru || runparams.find_effective())
792 qstr = (level_ == QuoteLevel::Primary) ? from_ascii("\"") : from_ascii("'");
793 else if (style == QuoteStyle::Plain && fontspec_) {
794 // For XeTeX and LuaTeX,we need to disable mapping to get straight
795 // quotes. We define our own commands that do this
796 qstr = (level_ == QuoteLevel::Primary) ?
797 from_ascii("\\textquotedblplain") : from_ascii("\\textquotesingleplain");
799 else if (runparams.use_polyglossia) {
800 // For polyglossia, we directly output the respective unicode chars
801 // (spacing and kerning is then handled respectively)
802 qstr = docstring(1, quotechar);
804 // The CJK marks are not yet covered by utf8 inputenc (we don't have the entry in
805 // unicodesymbols, since we don't want to add fake synbols there).
806 else if (style == QuoteStyle::CJK || style == QuoteStyle::CJKAngle) {
807 if (runparams.encoding && runparams.encoding->name() != "utf8"
808 && runparams.encoding->encodable(quotechar))
809 qstr = docstring(1, quotechar);
811 qstr = quoteparams.getLaTeXQuote(quotechar, "int");
813 else if ((style == QuoteStyle::Swiss
814 || style == QuoteStyle::French
815 || style == QuoteStyle::FrenchIN)
816 && level_ == QuoteLevel::Primary
817 && prefixIs(getLocalOrDefaultLang(runparams)->code(), "fr")) {
818 // Specific guillemets of French babel
819 // including correct French spacing
820 if (side_ == QuoteSide::Opening)
821 qstr = from_ascii("\\og");
823 qstr = from_ascii("\\fg");
824 } else if (runparams.use_hyperref && runparams.moving_arg) {
825 // Use internal commands in headings with hyperref
826 // (ligatures not featured in PDF strings)
827 qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_);
828 } else if (runparams.main_fontenc == "T1"
829 && !getLocalOrDefaultLang(runparams)->internalFontEncoding()) {
830 // Quotation marks for T1 font encoding
832 qstr = quoteparams.getLaTeXQuote(quotechar, "t1");
833 } else if (getLocalOrDefaultLang(runparams)->internalFontEncoding()) {
834 // Quotation marks for internal font encodings
835 // (ligatures not featured)
836 qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_);
837 #ifdef DO_USE_DEFAULT_LANGUAGE
838 } else if ((doclang == "default"
840 } else if ((!runparams.use_babel
842 || (runparams.main_fontenc != "T1" && runparams.main_fontenc != "OT1"))
843 || runparams.isFullUnicode()) {
844 // Standard quotation mark macros
845 // These are also used by babel
846 // without fontenc (XeTeX/LuaTeX)
847 qstr = quoteparams.getLaTeXQuote(quotechar, "ot1");
849 // Babel shorthand quotation marks (for T1/OT1)
850 qstr = quoteparams.getLaTeXQuote(quotechar, "babel");
853 if (!runparams.pass_thru) {
854 // Guard against unwanted ligatures with preceding text
855 char_type const lastchar = os.lastChar();
856 // LuaTeX does not respect {} as ligature breaker by design,
857 // see https://tex.stackexchange.com/q/349725/19291
858 docstring const nolig =
859 (runparams.flavor == Flavor::LuaTeX
860 || runparams.flavor == Flavor::DviLuaTeX) ?
861 from_ascii("\\/") : from_ascii("{}");
862 // !` ?` => !{}` ?{}`
863 if (prefixIs(qstr, from_ascii("`"))
864 && (lastchar == '!' || lastchar == '?'))
866 // ``` ''' ,,, <<< >>>
867 // => `{}`` '{}'' ,{},, <{}<< >{}>>
868 if (contains(from_ascii(",'`<>"), lastchar)
869 && prefixIs(qstr, lastchar))
875 if (prefixIs(qstr, from_ascii("\\")) && !suffixIs(qstr, '}'))
876 // properly terminate the command depending on the context
881 int InsetQuotes::plaintext(odocstringstream & os,
882 OutputParams const & op, size_t) const
884 if (!op.find_effective()) {
885 docstring const str = displayString();
890 if (level_ == QuoteLevel::Primary)
891 os << from_ascii("\"");
893 os << from_ascii("'");
899 docstring InsetQuotes::getQuoteXMLEntity() const {
901 (style_ == QuoteStyle::Dynamic) ? global_style_ : style_;
902 docstring res = quoteparams.getXMLQuote(quoteparams.getQuoteChar(style, level_, side_));
904 // in French, thin spaces are added inside double guillemets
905 if (prefixIs(context_lang_, "fr")
906 && level_ == QuoteLevel::Primary
907 && (style == QuoteStyle::French
908 || style == QuoteStyle::FrenchIN
909 || style == QuoteStyle::Swiss)) {
910 // THIN SPACE (U+2009)
911 docstring const thin_space = from_ascii(" ");
912 if (side_ == QuoteSide::Opening) // Open quote: space after
914 else // Close quote: space before
915 res = thin_space + res;
921 void InsetQuotes::docbook(XMLStream & xs, OutputParams const &) const
923 xs << XMLStream::ESCAPE_NONE << getQuoteXMLEntity();
927 docstring InsetQuotes::xhtml(XMLStream & xs, OutputParams const &) const
929 xs << XMLStream::ESCAPE_NONE << getQuoteXMLEntity();
934 void InsetQuotes::toString(odocstream & os) const
936 os << displayString();
940 void InsetQuotes::forOutliner(docstring & os, size_t const, bool const) const
942 os += displayString();
946 void InsetQuotes::updateBuffer(ParIterator const & it, UpdateType /* utype*/, bool const /*deleted*/)
948 BufferParams const & bp = buffer().masterBuffer()->params();
949 Font const & font = it.paragraph().getFontSettings(bp, it.pos());
950 pass_thru_ = it.paragraph().isPassThru();
951 context_lang_ = font.language()->code();
952 internal_fontenc_ = font.language()->internalFontEncoding();
953 global_style_ = bp.quotes_style;
954 fontspec_ = bp.useNonTeXFonts;
955 rtl_ = font.isRightToLeft();
959 void InsetQuotes::validate(LaTeXFeatures & features) const
962 (style_ == QuoteStyle::Dynamic) ? global_style_ : style_;
963 char_type type = quoteparams.getQuoteChar(style, level_, side_);
965 // Handle characters that are not natively supported by
966 // specific font encodings (we roll our own definitions)
967 #ifdef DO_USE_DEFAULT_LANGUAGE
968 if (features.bufferParams().language->lang() == "default"
970 if (!features.useBabel()
972 && !features.runparams().isFullUnicode()
973 && features.runparams().main_fontenc != "T1") {
976 features.require("quotesinglbase");
979 features.require("guilsinglleft");
982 features.require("guilsinglright");
985 features.require("quotedblbase");
988 features.require("guillemotleft");
991 features.require("guillemotright");
997 // Handle straight quotation marks. These need special care
998 // in most output formats
1001 if (features.runparams().isFullUnicode() && fontspec_)
1002 features.require("textquotesinglep");
1004 features.require("textcomp");
1008 if (features.runparams().isFullUnicode() && fontspec_)
1009 features.require("textquotedblp");
1010 else if (features.runparams().main_fontenc != "T1" || internal_fontenc_)
1011 features.require("textquotedbl");
1014 // we fake these from math (also for utf8 inputenc
1015 // currently; see above)
1016 case 0x300e: // LEFT WHITE CORNER BRACKET
1017 case 0x300f: // RIGHT WHITE CORNER BRACKET
1018 if (!features.runparams().encoding
1019 || features.runparams().encoding->name() == "utf8"
1020 || !features.runparams().encoding->encodable(type))
1021 features.require("stmaryrd");
1029 string InsetQuotes::contextMenuName() const
1031 return "context-quote";
1035 pair<int, int> InsetQuotes::isWords() const
1038 // In PassThru, we use straight quotes otherwise we need to check for French
1041 QuoteStyle style = (style_ == QuoteStyle::Dynamic) ? global_style_ : style_;
1043 // in French, thin spaces are added inside double guillemets
1044 if (level_ == QuoteLevel::Primary
1045 && (style == QuoteStyle::Swiss
1046 || style == QuoteStyle::French
1047 || style == QuoteStyle::FrenchIN)
1048 && prefixIs(context_lang_, "fr")) {
1049 // space added by default for all formats
1054 //one or two characters from the statistics perspective
1055 return std::pair<int,int>(length, 0);