]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Consistent output of breakable/non-breakable dashes on all TeX engines.
[lyx.git] / src / Paragraph.cpp
index 3da74d7ff7e777b94b2debe3fd44cb0bae7bc7aa..a6c72c310e0b22a07b1251132133a1d02899041a 100644 (file)
@@ -71,8 +71,8 @@
 using namespace std;
 using namespace lyx::support;
 
-// gcc < 4.8.0 and msvc < 2015 do not support C++11 thread_local
-#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 8
+// OSX clang, gcc < 4.8.0, and msvc < 2015 do not support C++11 thread_local
+#if defined(__APPLE__) || (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 8)
 #define THREAD_LOCAL_STATIC static __thread
 #elif defined(_MSC_VER) && (_MSC_VER < 1900)
 #define THREAD_LOCAL_STATIC static __declspec(thread)
@@ -87,7 +87,7 @@ namespace {
 /// Inset identifier (above 0x10ffff, for ucs-4)
 char_type const META_INSET = 0x200001;
 
-}
+} // namespace
 
 
 /////////////////////////////////////////////////////////////////////
@@ -397,7 +397,7 @@ public:
        typedef SkipPositions::const_iterator SkipPositionsIterator;
 
        void appendSkipPosition(SkipPositions & skips, pos_type const pos) const;
-       
+
        Language * getSpellLanguage(pos_type const from) const;
 
        Language * locateSpellRange(pos_type & from, pos_type & to,
@@ -412,7 +412,7 @@ public:
        }
 
        bool ignoreWord(docstring const & word) const ;
-       
+
        void setMisspelled(pos_type from, pos_type to, SpellChecker::Result state)
        {
                pos_type textsize = owner_->size();
@@ -1247,8 +1247,8 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
                }
                break;
        case '\"':
-               os << "\\char34" << termcmd;
-               column += 9;
+               os << "\\textquotedbl" << termcmd;
+               column += 14;
                break;
 
        case '$': case '&':
@@ -1289,7 +1289,10 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
 
        case 0x2013:
        case 0x2014:
-               if (bparams.use_dash_ligatures && !bparams.useNonTeXFonts) {
+               // XeTeX's dash behaviour is determined via a global setting
+               if (bparams.use_dash_ligatures
+                   && owner_->getFontSettings(bparams, i).fontInfo().family() != TYPEWRITER_FAMILY
+                   && (!bparams.useNonTeXFonts || runparams.flavor != OutputParams::XETEX)) {
                        if (c == 0x2013) {
                                // en-dash
                                os << "--";
@@ -1417,6 +1420,14 @@ bool Paragraph::Private::latexSpecialT3(char_type const c, otexstream & os,
                os << "\\textvertline" << termcmd;
                column += 14;
                return true;
+       case 0x2013:
+               os << "\\textendash" << termcmd;
+               column += 12;
+               return true;
+       case 0x2014:
+               os << "\\textemdash" << termcmd;
+               column += 12;
+               return true;
        default:
                return false;
        }
@@ -1425,11 +1436,11 @@ bool Paragraph::Private::latexSpecialT3(char_type const c, otexstream & os,
 
 void Paragraph::Private::validate(LaTeXFeatures & features) const
 {
+       Buffer const & buf = inset_owner_->buffer();
+       BufferParams const & bp = features.runparams().is_child
+               ? buf.masterParams() : buf.params();
        if (layout_->inpreamble && inset_owner_) {
                bool const is_command = layout_->latextype == LATEX_COMMAND;
-               Buffer const & buf = inset_owner_->buffer();
-               BufferParams const & bp = features.runparams().is_child
-                       ? buf.masterParams() : buf.params();
                Font f;
                // Using a string stream here circumvents the encoding
                // switching machinery of odocstream. Therefore the
@@ -1490,6 +1501,16 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
        for (; icit != iend; ++icit) {
                if (icit->inset) {
                        features.inDeletedInset(owner_->isDeleted(icit->pos));
+                       if (icit->inset->lyxCode() == FOOT_CODE) {
+                               // FIXME: an item inset would make things much easier.
+                               if ((layout_->latextype == LATEX_LIST_ENVIRONMENT
+                                    || (layout_->latextype == LATEX_ITEM_ENVIRONMENT
+                                        && layout_->margintype == MARGIN_FIRST_DYNAMIC))
+                                   && (icit->pos < begin_of_body_
+                                       || (icit->pos == begin_of_body_
+                                           && (icit->pos == 0 || text_[icit->pos - 1] != ' '))))
+                                       features.saveNoteEnv("description");
+                       }
                        icit->inset->validate(features);
                        features.inDeletedInset(false);
                        if (layout_->needprotect &&
@@ -1500,7 +1521,21 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
 
        // then the contents
        for (pos_type i = 0; i < int(text_.size()) ; ++i) {
-               BufferEncodings::validate(text_[i], features);
+               char_type c = text_[i];
+               if (c == 0x0022) {
+                       if (features.runparams().isFullUnicode() && bp.useNonTeXFonts)
+                               features.require("textquotedblp");
+                       else if (bp.main_font_encoding() != "T1"
+                                || ((&owner_->getFontSettings(bp, i))->language()->internalFontEncoding()))
+                               features.require("textquotedbl");
+               }
+               if (!bp.use_dash_ligatures
+                   && (c == 0x2013 || c == 0x2014)
+                   && bp.useNonTeXFonts
+                   && features.runparams().flavor == OutputParams::XETEX)
+                       // XeTeX's dash behaviour is determined via a global setting
+                       features.require("xetexdashbreakstate");
+               BufferEncodings::validate(c, features);
        }
 }
 
@@ -1569,7 +1604,7 @@ void flushString(ostream & os, docstring & s)
        s.erase();
 }
 
-}
+} // namespace
 
 
 void Paragraph::write(ostream & os, BufferParams const & bparams,
@@ -2200,7 +2235,7 @@ bool corrected_env(otexstream & os, string const & suffix, string const & env,
        return true;
 }
 
-} // namespace anon
+} // namespace
 
 
 int Paragraph::Private::startTeXParParams(BufferParams const & bparams,
@@ -2445,6 +2480,8 @@ void Paragraph::latex(BufferParams const & bparams,
                runparams.wasDisplayMath = runparams.inDisplayMath;
                runparams.inDisplayMath = false;
                bool deleted_display_math = false;
+               Change const & change = runparams.inDeletedInset
+                       ? runparams.changeOfDeletedInset : lookupChange(i);
 
                // Check whether a display math inset follows
                if (d->text_[i] == META_INSET
@@ -2459,11 +2496,28 @@ void Paragraph::latex(BufferParams const & bparams,
                                // cannot set it here because it is a counter.
                                deleted_display_math = isDeleted(i);
                        }
+                       if (bparams.output_changes && deleted_display_math
+                           && runningChange == change
+                           && change.type == Change::DELETED
+                           && !os.afterParbreak()) {
+                               // A display math in the same paragraph follows.
+                               // We have to close and then reopen \lyxdeleted,
+                               // otherwise the math will be shifted up.
+                               OutputParams rp = runparams;
+                               if (open_font) {
+                                       bool needPar = false;
+                                       column += running_font.latexWriteEndChanges(
+                                               os, bparams, rp, basefont,
+                                               basefont, needPar);
+                                       open_font = false;
+                               }
+                               basefont = getLayoutFont(bparams, outerfont);
+                               running_font = basefont;
+                               column += Changes::latexMarkChange(os, bparams,
+                                       Change(Change::INSERTED), change, rp);
+                       }
                }
 
-               Change const & change = runparams.inDeletedInset
-                       ? runparams.changeOfDeletedInset : lookupChange(i);
-
                if (bparams.output_changes && runningChange != change) {
                        if (open_font) {
                                bool needPar = false;
@@ -2514,6 +2568,7 @@ void Paragraph::latex(BufferParams const & bparams,
                bool const using_begin_end = runparams.use_polyglossia ||
                                                !lang_end_command.empty();
                if (!running_lang.empty() &&
+                   (!using_begin_end || running_lang == openLanguageName()) &&
                    current_font.language()->encoding()->package() == Encoding::CJK) {
                                string end_tag = subst(lang_end_command,
                                                        "$$lang",
@@ -2540,7 +2595,7 @@ void Paragraph::latex(BufferParams const & bparams,
                char_type const c = d->text_[i];
 
                // A display math inset inside an ulem command will be output
-               // as a box of width \columnwidth, so we have to either disable
+               // as a box of width \linewidth, so we have to either disable
                // indentation if the inset starts a paragraph, or start a new
                // line to accommodate such box. This has to be done before
                // writing any font changing commands.
@@ -2928,7 +2983,7 @@ void doFontSwitch(vector<html::FontTag> & tagsToOpen,
                flag = false;
        }
 }
-}
+} // namespace
 
 
 docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
@@ -2967,13 +3022,13 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
        FontShape  curr_fs   = INHERIT_SHAPE;
        FontFamily curr_fam  = INHERIT_FAMILY;
        FontSize   curr_size = FONT_SIZE_INHERIT;
-       
-       string const default_family = 
-               buf.masterBuffer()->params().fonts_default_family;              
+
+       string const default_family =
+               buf.masterBuffer()->params().fonts_default_family;
 
        vector<html::FontTag> tagsToOpen;
        vector<html::EndFontTag> tagsToClose;
-       
+
        // parsing main loop
        for (pos_type i = initial; i < size(); ++i) {
                // let's not show deleted material in the output
@@ -2996,7 +3051,7 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
                curstate = font.fontInfo().underbar();
                if (font_old.underbar() != curstate)
                        doFontSwitch(tagsToOpen, tagsToClose, ubar_flag, curstate, html::FT_UBAR);
-       
+
                // strikeout
                curstate = font.fontInfo().strikeout();
                if (font_old.strikeout() != curstate)
@@ -3627,7 +3682,7 @@ int Paragraph::fixBiblio(Buffer const & buffer)
                                         InsetCommandParams(BIBITEM_CODE));
 
        Font font(inherit_font, buffer.params().language);
-       insertInset(0, inset, font, Change(track_changes ? Change::INSERTED 
+       insertInset(0, inset, font, Change(track_changes ? Change::INSERTED
                                                   : Change::UNCHANGED));
 
        return 1;
@@ -3664,7 +3719,7 @@ InsetList const & Paragraph::insetList() const
 }
 
 
-void Paragraph::setBuffer(Buffer & b)
+void Paragraph::setInsetBuffers(Buffer & b)
 {
        d->insetlist_.setBuffer(b);
 }
@@ -3862,13 +3917,13 @@ void Paragraph::locateWord(pos_type & from, pos_type & to,
                        to = from;
                        return;
                }
-               // no break here, we go to the next
+               // fall through
 
        case WHOLE_WORD:
                // If we are already at the beginning of a word, do nothing
                if (!from || isWordSeparator(from - 1))
                        break;
-               // no break here, we go to the next
+               // fall through
 
        case PREVIOUS_WORD:
                // always move the cursor to the beginning of previous word