]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetQuotes.cpp
Does not compile on older gcc.
[lyx.git] / src / insets / InsetQuotes.cpp
index 515d24119d959a93526a64f6a43b6cacfb766181..b90f1c27dda850ae94e035260994dc5ec9ba11f2 100644 (file)
 #include "LyXRC.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
-#include "output_xhtml.h"
 #include "Paragraph.h"
 #include "ParIterator.h"
 #include "texstream.h"
+#include "xml.h"
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
@@ -111,10 +111,9 @@ InsetQuotesParams::QuoteStyle InsetQuotesParams::getQuoteStyle(string const & s,
                str = "eld";
        }
 
-       int i;
-
        // '.' wildcard means: keep current style
        if (!allow_wildcards || str[0] != '.') {
+               int i;
                for (i = 0; i < stylescount(); ++i) {
                        if (str[0] == style_char[i]) {
                                res = QuoteStyle(i);
@@ -144,10 +143,9 @@ InsetQuotesParams::QuoteSide InsetQuotesParams::getQuoteSide(string const & s,
                str = "eld";
        }
 
-       int i;
-
        // '.' wildcard means: keep current side
        if (!allow_wildcards || str[1] != '.') {
+               int i;
                for (i = 0; i < 2; ++i) {
                        if (str[1] == side_char[i]) {
                                res = InsetQuotesParams::QuoteSide(i);
@@ -177,10 +175,9 @@ InsetQuotesParams::QuoteLevel InsetQuotesParams::getQuoteLevel(string const & s,
                str = "eld";
        }
 
-       int i;
-
        // '.' wildcard means: keep current level
        if (!allow_wildcards || str[2] != '.') {
+               int i;
                for (i = 0; i < 2; ++i) {
                        if (str[2] == level_char[i]) {
                                res = InsetQuotesParams::QuoteLevel(i);
@@ -353,7 +350,7 @@ docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op,
        case 0x2019: {// '
                if (op == "int")
                        // This macro is redefined in rtl mode
-                       res = rtl ? "\\textquoteright" : "\\textquoteleft";
+                       res = rtl ? "\\textquoteleft" : "\\textquoteright";
                else
                        res = "'";
                break;
@@ -361,7 +358,7 @@ docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op,
        case 0x2018: {// `
                if (op == "int")
                        // This macro is redefined in rtl mode
-                       res = rtl ? "\\textquoteleft" : "\\textquoteright";
+                       res = rtl ? "\\textquoteright" : "\\textquoteleft";
                else
                        res = "`";
                break;
@@ -396,7 +393,7 @@ docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op,
        case 0x201d: {// ''
                if (op == "int")
                        // This macro is redefined in rtl mode
-                       res = rtl ? "\\textquotedblright" : "\\textquotedblleft";
+                       res = rtl ? "\\textquotedblleft" : "\\textquotedblright";
                else
                        res = "''";
                break;
@@ -404,7 +401,7 @@ docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op,
        case 0x201c: {// ``
                if (op == "int")
                        // This macro is redefined in rtl mode
-                       res = rtl ? "\\textquotedblleft" : "\\textquotedblright";
+                       res = rtl ? "\\textquotedblright" : "\\textquotedblleft";
                else
                        res = "``";
                break;
@@ -433,7 +430,7 @@ docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op,
        }
        // The following are fakes
        // This is just to get something symbolic
-       // in encodings where this chars would not be used ayway
+       // in encodings where this chars would not be used anyway
        case 0x300c: // LEFT CORNER BRACKET
                res = "\\ensuremath{\\lceil}";
                break;
@@ -539,6 +536,13 @@ docstring InsetQuotesParams::getHTMLQuote(char_type c) const
 }
 
 
+docstring InsetQuotesParams::getXMLQuote(char_type c) const
+{
+       // Directly output the character Unicode form.
+       return from_ascii("&#" + to_string(c) + ";");
+}
+
+
 map<string, docstring> InsetQuotesParams::getTypes() const
 {
        map<string, docstring> res;
@@ -588,9 +592,9 @@ docstring const InsetQuotesParams::getGuiLabel(QuoteStyle const & qs, bool langd
 }
 
 
-docstring const InsetQuotesParams::getShortGuiLabel(docstring const string)
+docstring const InsetQuotesParams::getShortGuiLabel(docstring const & str)
 {
-       std::string const s = to_ascii(string);
+       string const s = to_ascii(str);
        QuoteStyle const style = getQuoteStyle(s);
        QuoteSide const side = getQuoteSide(s);
        QuoteLevel const level = getQuoteLevel(s);
@@ -883,6 +887,10 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
                        qstr = from_ascii("\\og");
                else
                        qstr = from_ascii("\\fg");
+       } else if (runparams.use_hyperref && runparams.moving_arg) {
+               // Use internal commands in headings with hyperref
+               // (ligatures not featured in PDF strings)
+               qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_);
        } else if (fontenc_ == "T1"
                   && !runparams.local_font->language()->internalFontEncoding()) {
                // Quotation marks for T1 font encoding
@@ -945,10 +953,12 @@ int InsetQuotes::plaintext(odocstringstream & os,
 }
 
 
-docstring InsetQuotes::getQuoteEntity() const {
+docstring InsetQuotes::getQuoteEntity(bool isHTML) const {
        InsetQuotesParams::QuoteStyle style =
                        (style_ == InsetQuotesParams::DynamicQuotes) ? global_style_ : style_;
-       docstring res = quoteparams.getHTMLQuote(quoteparams.getQuoteChar(style, level_, side_));
+       docstring res = isHTML ? quoteparams.getHTMLQuote(quoteparams.getQuoteChar(style, level_, side_)) :
+                                       quoteparams.getXMLQuote(quoteparams.getQuoteChar(style, level_, side_));
+
        // in French, thin spaces are added inside double guillemets
        if (prefixIs(context_lang_, "fr")
            && level_ == InsetQuotesParams::PrimaryQuotes
@@ -957,25 +967,24 @@ docstring InsetQuotes::getQuoteEntity() const {
                || style == InsetQuotesParams::SwissQuotes)) {
                // THIN SPACE (U+2009)
                docstring const thin_space = from_ascii("&#x2009;");
-               if (side_ == InsetQuotesParams::OpeningQuote)
+               if (side_ == InsetQuotesParams::OpeningQuote) // Open quote: space after
                        res += thin_space;
-               else
+               else // Close quote: space before
                        res = thin_space + res;
        }
        return res;
 }
 
 
-int InsetQuotes::docbook(odocstream & os, OutputParams const &) const
+void InsetQuotes::docbook(XMLStream & xs, OutputParams const &) const
 {
-       os << getQuoteEntity();
-       return 0;
+       xs << XMLStream::ESCAPE_NONE << getQuoteEntity(false);
 }
 
 
-docstring InsetQuotes::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetQuotes::xhtml(XMLStream & xs, OutputParams const &) const
 {
-       xs << XHTMLStream::ESCAPE_NONE << getQuoteEntity();
+       xs << XMLStream::ESCAPE_NONE << getQuoteEntity(true);
        return docstring();
 }
 
@@ -992,7 +1001,7 @@ void InsetQuotes::forOutliner(docstring & os, size_t const, bool const) const
 }
 
 
-void InsetQuotes::updateBuffer(ParIterator const & it, UpdateType /* utype*/)
+void InsetQuotes::updateBuffer(ParIterator const & it, UpdateType /* utype*/, bool const /*deleted*/)
 {
        BufferParams const & bp = buffer().masterBuffer()->params();
        Font const & font = it.paragraph().getFontSettings(bp, it.pos());