]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetQuotes.cpp
Fix bug #12795
[lyx.git] / src / insets / InsetQuotes.cpp
index d503e8bf9a2b35003fe4133189b4cf760d0ea54a..f5823605543455e820e7fec88a828ced16348efa 100644 (file)
@@ -470,79 +470,6 @@ docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op,
 }
 
 
-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 = "&lsaquo;";
-               break;
-       case 0x203a: // >
-               res = "&rsaquo;";
-               break;
-       case 0x0027: // ' (plain)
-               res = "&#x27;";
-               break;
-       case 0x201e: // ,,
-               res = "&bdquo;";
-               break;
-       case 0x201d: // ''
-               res = "&rdquo;";
-               break;
-       case 0x201c: // ``
-               res = "&ldquo;";
-               break;
-       case 0x00ab: // <<
-               res = "&laquo;";
-               break;
-       case 0x00bb: // >>
-               res = "&raquo;";
-               break;
-       case 0x0022: // "
-               res = "&quot;";
-               break;
-       case 0x300c: // LEFT CORNER BRACKET
-               res = "&#x300c;";
-               break;
-       case 0x300d: // RIGHT CORNER BRACKET
-               res = "&#x300d;";
-               break;
-       case 0x300e: // LEFT WHITE CORNER BRACKET
-               res = "&#x300e;";
-               break;
-       case 0x300f: // RIGHT WHITE CORNER BRACKET
-               res = "&#x300f;";
-               break;
-       case 0x300a: // LEFT DOUBLE ANGLE BRACKET
-               res = "&#x300a;";
-               break;
-       case 0x300b: // RIGHT DOUBLE ANGLE BRACKET
-               res = "&#x300b;";
-               break;
-       case 0x3008: // LEFT ANGLE BRACKET
-               res = "&#x3008;";
-               break;
-       case 0x3009: // RIGHT ANGLE BRACKET
-               res = "&#x3009;";
-               break;
-       default:
-               break;
-       }
-
-       return from_ascii(res);
-}
-
-
 docstring InsetQuotesParams::getXMLQuote(char_type c) const
 {
        // Directly output the character Unicode form.
@@ -639,11 +566,8 @@ InsetQuotes::InsetQuotes(Buffer * buf, char_type c, QuoteLevel level,
        bool dynamic = false;
        if (buf) {
                global_style_ = buf->masterBuffer()->params().quotes_style;
-               fontenc_ = buf->masterBuffer()->params().main_font_encoding();
                dynamic = buf->masterBuffer()->params().dynamic_quotes;
                fontspec_ = buf->masterBuffer()->params().useNonTeXFonts;
-       } else {
-               fontenc_ = "OT1";
        }
        if (style.empty())
                style_ = dynamic ? QuoteStyle::Dynamic : global_style_;
@@ -854,7 +778,7 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
        docstring qstr;
 
        // In pass-thru context, we output plain quotes
-       if (runparams.pass_thru)
+       if (runparams.pass_thru || runparams.find_effective())
                qstr = (level_ == QuoteLevel::Primary) ? from_ascii("\"") : from_ascii("'");
        else if (style == QuoteStyle::Plain && fontspec_) {
                // For XeTeX and LuaTeX,we need to disable mapping to get straight
@@ -891,7 +815,7 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
                // Use internal commands in headings with hyperref
                // (ligatures not featured in PDF strings)
                qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_);
-       } else if (fontenc_ == "T1"
+       } else if (runparams.main_fontenc == "T1"
                   && !runparams.local_font->language()->internalFontEncoding()) {
                // Quotation marks for T1 font encoding
                // (using ligatures)
@@ -905,7 +829,7 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
 #else
        } else if ((!runparams.use_babel
 #endif
-                  || (fontenc_ != "T1" && fontenc_ != "OT1"))
+                  || (runparams.main_fontenc != "T1" && runparams.main_fontenc != "OT1"))
                   || runparams.isFullUnicode()) {
                // Standard quotation mark macros
                // These are also used by babel
@@ -945,19 +869,27 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
 
 
 int InsetQuotes::plaintext(odocstringstream & os,
-        OutputParams const &, size_t) const
+        OutputParams const & op, size_t) const
 {
-       docstring const str = displayString();
-       os << str;
-       return str.size();
+       if (!op.find_effective()) {
+               docstring const str = displayString();
+               os << str;
+               return str.size();
+       }
+       else {
+               if (level_ == QuoteLevel::Primary)
+                       os << from_ascii("\"");
+               else
+                       os << from_ascii("'");
+               return 1;
+       }
 }
 
 
-docstring InsetQuotes::getQuoteEntity(bool isHTML) const {
+docstring InsetQuotes::getQuoteXMLEntity() const {
        QuoteStyle style =
                        (style_ == QuoteStyle::Dynamic) ? global_style_ : style_;
-       docstring res = isHTML ? quoteparams.getHTMLQuote(quoteparams.getQuoteChar(style, level_, side_)) :
-                                       quoteparams.getXMLQuote(quoteparams.getQuoteChar(style, level_, side_));
+       docstring res = quoteparams.getXMLQuote(quoteparams.getQuoteChar(style, level_, side_));
 
        // in French, thin spaces are added inside double guillemets
        if (prefixIs(context_lang_, "fr")
@@ -978,13 +910,13 @@ docstring InsetQuotes::getQuoteEntity(bool isHTML) const {
 
 void InsetQuotes::docbook(XMLStream & xs, OutputParams const &) const
 {
-       xs << XMLStream::ESCAPE_NONE << getQuoteEntity(false);
+       xs << XMLStream::ESCAPE_NONE << getQuoteXMLEntity();
 }
 
 
 docstring InsetQuotes::xhtml(XMLStream & xs, OutputParams const &) const
 {
-       xs << XMLStream::ESCAPE_NONE << getQuoteEntity(true);
+       xs << XMLStream::ESCAPE_NONE << getQuoteXMLEntity();
        return docstring();
 }
 
@@ -1008,7 +940,6 @@ void InsetQuotes::updateBuffer(ParIterator const & it, UpdateType /* utype*/, bo
        pass_thru_ = it.paragraph().isPassThru();
        context_lang_ = font.language()->code();
        internal_fontenc_ = font.language()->internalFontEncoding();
-       fontenc_ = bp.main_font_encoding();
        global_style_ = bp.quotes_style;
        fontspec_ = bp.useNonTeXFonts;
        rtl_ = font.isRightToLeft();
@@ -1028,7 +959,8 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
 #else
        if (!features.useBabel()
 #endif
-           && !features.runparams().isFullUnicode() && fontenc_ != "T1") {
+           && !features.runparams().isFullUnicode()
+           && features.runparams().main_fontenc != "T1") {
                switch (type) {
                case 0x201a:
                        features.require("quotesinglbase");
@@ -1065,7 +997,7 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
        case 0x0022: {
                if (features.runparams().isFullUnicode() && fontspec_)
                        features.require("textquotedblp");
-               else if (fontenc_ != "T1" || internal_fontenc_)
+               else if (features.runparams().main_fontenc != "T1" || internal_fontenc_)
                        features.require("textquotedbl");
                break;
        }
@@ -1089,4 +1021,28 @@ string InsetQuotes::contextMenuName() const
        return "context-quote";
 }
 
+
+pair<int, int> InsetQuotes::isWords() const
+{
+       int length = 1;
+       // In PassThru, we use straight quotes otherwise we need to check for French
+       if (!pass_thru_) {
+
+               QuoteStyle style = (style_ == QuoteStyle::Dynamic) ? global_style_ : style_;
+
+               // in French, thin spaces are added inside double guillemets
+               if (level_ == QuoteLevel::Primary
+                   && (style == QuoteStyle::Swiss
+                       || style == QuoteStyle::French
+                       || style == QuoteStyle::FrenchIN)
+                   && prefixIs(context_lang_, "fr")) {
+                       // space added by default for all formats
+                       length++;
+               }
+       }
+
+       //one or two characters from the statistics perspective
+       return std::pair<int,int>(length, 0);
+}
+
 } // namespace lyx