]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Whitespace
[lyx.git] / src / Paragraph.cpp
index caaa0288f26f8ec9051e4371a61e5f36314a38cf..710587bb578a4a736420b7eac727032dc30f7b76 100644 (file)
@@ -445,10 +445,10 @@ public:
                        return;
                }
                pos_type endpos = last;
-               owner_->locateWord(first, endpos, WHOLE_WORD);
+               owner_->locateWord(first, endpos, WHOLE_WORD, true);
                if (endpos < last) {
                        endpos = last;
-                       owner_->locateWord(last, endpos, WHOLE_WORD);
+                       owner_->locateWord(last, endpos, WHOLE_WORD, true);
                }
                last = endpos;
        }
@@ -581,18 +581,6 @@ void Paragraph::addChangesToToc(DocIterator const & cdit, Buffer const & buf,
 }
 
 
-void Paragraph::addChangesToBuffer(Buffer const & buf) const
-{
-       d->changes_.updateBuffer(buf);
-}
-
-
-bool Paragraph::isChangeUpdateRequired() const
-{
-       return d->changes_.isUpdateRequired();
-}
-
-
 bool Paragraph::isDeleted(pos_type start, pos_type end) const
 {
        LASSERT(start >= 0 && start <= size(), return false);
@@ -611,6 +599,12 @@ bool Paragraph::isChanged(pos_type start, pos_type end) const
 }
 
 
+bool Paragraph::isChanged() const
+{
+       return d->changes_.isChanged();
+}
+
+
 bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
 {
        // keep the logic here in sync with the logic of eraseChars()
@@ -621,6 +615,11 @@ bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
        return change.inserted() && change.currentAuthor();
 }
 
+Change Paragraph::parEndChange() const
+{
+       return d->changes_.lookup(size());
+}
+
 
 void Paragraph::setChange(Change const & change)
 {
@@ -655,8 +654,8 @@ void Paragraph::setChange(pos_type pos, Change const & change)
 
        // see comment in setChange(Change const &) above
        if (!change.deleted() && pos < size())
-                       if (Inset * inset = getInset(pos))
-                               inset->setChange(change);
+               if (Inset * inset = getInset(pos))
+                       inset->setChange(change);
 }
 
 
@@ -1005,7 +1004,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
        bool close = false;
        odocstream::pos_type const len = os.os().tellp();
 
-       if (inset->forceLTR()
+       if (inset->forceLTR(runparams)
            && running_font.isRightToLeft()
            // ERT is an exception, it should be output with no
            // decorations at all
@@ -1860,8 +1859,9 @@ char_type Paragraph::getUChar(BufferParams const & bparams,
        char_type c = d->text_[pos];
 
        // Return unchanged character in LTR languages
-       // or if we use poylglossia/bidi.
-       if (rp.use_polyglossia || !getFontSettings(bparams, pos).isRightToLeft())
+       // or if we use poylglossia/bidi (XeTeX).
+       if (rp.useBidiPackage()
+           || !getFontSettings(bparams, pos).isRightToLeft())
                return c;
 
        // Without polyglossia/bidi, we need to account for some special cases.
@@ -1880,7 +1880,8 @@ char_type Paragraph::getUChar(BufferParams const & bparams,
        char_type uc = c;
 
        // 1. In the following languages, parentheses need to be reversed.
-       bool const reverseparens = lang == "hebrew";
+       //    Also with polyglodia/luabidi
+       bool const reverseparens = (lang == "hebrew" || rp.use_polyglossia);
 
        // 2. In the following languages, brackets don't need to be reversed.
        bool const reversebrackets = lang != "arabic_arabtex"
@@ -1983,15 +1984,29 @@ depth_type Paragraph::getMaxDepthAfter() const
 }
 
 
-LyXAlignment Paragraph::getAlign() const
+LyXAlignment Paragraph::getAlign(BufferParams const & bparams) const
 {
        if (d->params_.align() == LYX_ALIGN_LAYOUT)
-               return d->layout_->align;
+               return getDefaultAlign(bparams);
        else
                return d->params_.align();
 }
 
 
+LyXAlignment Paragraph::getDefaultAlign(BufferParams const & bparams) const
+{
+       LyXAlignment res = layout().align;
+       if (isRTL(bparams)) {
+               // Swap sides
+               if (res == LYX_ALIGN_LEFT)
+                       res = LYX_ALIGN_RIGHT;
+               else if  (res == LYX_ALIGN_RIGHT)
+                       res = LYX_ALIGN_LEFT;
+       }
+       return res;
+}
+
+
 docstring const & Paragraph::labelString() const
 {
        return d->params_.labelString();
@@ -2231,8 +2246,9 @@ int Paragraph::Private::startTeXParParams(BufferParams const & bparams,
        InsetCode code = ownerCode();
        bool const lastpar = runparams.isLastPar;
        // RTL in classic (PDF)LaTeX (without the Bidi package)
+       // Luabibdi (used by LuaTeX) behaves like classic
        bool const rtl_classic = owner_->getParLanguage(bparams)->rightToLeft()
-               && !runparams.use_polyglossia;
+               && !runparams.useBidiPackage();
 
        switch (curAlign) {
        case LYX_ALIGN_NONE:
@@ -2294,8 +2310,9 @@ bool Paragraph::Private::endTeXParParams(BufferParams const & bparams,
        InsetCode code = ownerCode();
        bool const lastpar = runparams.isLastPar;
        // RTL in classic (PDF)LaTeX (without the Bidi package)
+       // Luabibdi (used by LuaTeX) behaves like classic
        bool const rtl_classic = owner_->getParLanguage(bparams)->rightToLeft()
-               && !runparams.use_polyglossia;
+               && !runparams.useBidiPackage();
 
        switch (curAlign) {
        case LYX_ALIGN_NONE:
@@ -2454,9 +2471,14 @@ void Paragraph::latex(BufferParams const & bparams,
                Change const & change = runparams.inDeletedInset
                        ? runparams.changeOfDeletedInset : lookupChange(i);
 
+               char_type const c = d->text_[i];
+
                // Check whether a display math inset follows
-               if (d->text_[i] == META_INSET
+               if (c == META_INSET
                    && i >= start_pos && (end_pos == -1 || i < end_pos)) {
+                       if (isDeleted(i))
+                               runparams.ctObject = getInset(i)->CtObject(runparams);
+       
                        InsetMath const * im = getInset(i)->asInsetMath();
                        if (im && im->asHullInset()
                            && im->asHullInset()->outerDisplay()) {
@@ -2482,7 +2504,8 @@ void Paragraph::latex(BufferParams const & bparams,
                                                basefont, needPar);
                                        open_font = false;
                                }
-                               basefont = getLayoutFont(bparams, outerfont);
+                               basefont = (body_pos > i) ? getLabelFont(bparams, outerfont)
+                                                         : getLayoutFont(bparams, outerfont);
                                running_font = basefont;
                                column += Changes::latexMarkChange(os, bparams,
                                        Change(Change::INSERTED), change, rp);
@@ -2502,7 +2525,8 @@ void Paragraph::latex(BufferParams const & bparams,
                                                basefont, basefont, needPar);
                                open_font = false;
                        }
-                       basefont = getLayoutFont(bparams, outerfont);
+                       basefont = (body_pos > i) ? getLabelFont(bparams, outerfont)
+                                                 : getLayoutFont(bparams, outerfont);
                        running_font = basefont;
                        column += Changes::latexMarkChange(os, bparams, runningChange,
                                                           change, runparams);
@@ -2568,8 +2592,6 @@ 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 \linewidth, so we have to either disable
                // indentation if the inset starts a paragraph, or start a new
@@ -2588,6 +2610,21 @@ void Paragraph::latex(BufferParams const & bparams,
                     current_font.language() != running_font.language()) &&
                        i != body_pos - 1)
                {
+                       bool const in_ct_deletion = (bparams.output_changes
+                                                    && runningChange == change
+                                                    && change.type == Change::DELETED
+                                                    && !os.afterParbreak());
+                       if (in_ct_deletion) {
+                               // We have to close and then reopen \lyxdeleted,
+                               // as strikeout needs to be on lowest level.
+                               bool needPar = false;
+                               OutputParams rp = runparams;
+                               column += running_font.latexWriteEndChanges(
+                                       os, bparams, rp, basefont,
+                                       basefont, needPar);
+                               os << '}';
+                               column += 1;
+                       }
                        odocstringstream ods;
                        column += current_font.latexWriteStartChanges(ods, bparams,
                                                              runparams, basefont,
@@ -2616,6 +2653,13 @@ void Paragraph::latex(BufferParams const & bparams,
                                   << from_ascii("{}");
                        else
                                os << fontchange;
+                       if (in_ct_deletion) {
+                               // We have to close and then reopen \lyxdeleted,
+                               // as strikeout needs to be on lowest level.
+                               OutputParams rp = runparams;
+                               column += Changes::latexMarkChange(os, bparams,
+                                       Change(Change::UNCHANGED), change, rp);
+                       }
                }
 
                // FIXME: think about end_pos implementation...
@@ -2682,6 +2726,16 @@ void Paragraph::latex(BufferParams const & bparams,
                                                runningChange, style, i, column);
                                if (incremented)
                                        --parInline;
+
+                               if (runparams.ctObject == OutputParams::CT_DISPLAYOBJECT
+                                   || runparams.ctObject == OutputParams::CT_UDISPLAYOBJECT) {
+                                       // Close \lyx*deleted and force its
+                                       // reopening (if needed)
+                                       os << '}';
+                                       column++;
+                                       runningChange = Change(Change::UNCHANGED);
+                                       runparams.ctObject = OutputParams::CT_NORMAL;
+                               }
                        }
                } else if (i >= start_pos && (end_pos == -1 || i < end_pos)) {
                        if (!bparams.useNonTeXFonts)
@@ -2730,7 +2784,7 @@ void Paragraph::latex(BufferParams const & bparams,
                runparams.post_macro = rp.post_macro;
        }
 
-    // Close wrapper for alien script
+       // Close wrapper for alien script
        if (!alien_script.empty()) {
                os << "}";
                alien_script.clear();
@@ -3020,7 +3074,7 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
 
        FontShape  curr_fs   = INHERIT_SHAPE;
        FontFamily curr_fam  = INHERIT_FAMILY;
-       FontSize   curr_size = FONT_SIZE_INHERIT;
+       FontSize   curr_size = INHERIT_SIZE;
 
        string const default_family =
                buf.masterBuffer()->params().fonts_default_family;
@@ -3185,41 +3239,41 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
                if (old_size != curr_size) {
                        if (size_flag) {
                                switch (old_size) {
-                               case FONT_SIZE_TINY:
+                               case TINY_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_TINY));
                                        break;
-                               case FONT_SIZE_SCRIPT:
+                               case SCRIPT_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_SCRIPT));
                                        break;
-                               case FONT_SIZE_FOOTNOTE:
+                               case FOOTNOTE_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_FOOTNOTE));
                                        break;
-                               case FONT_SIZE_SMALL:
+                               case SMALL_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_SMALL));
                                        break;
-                               case FONT_SIZE_LARGE:
+                               case LARGE_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_LARGE));
                                        break;
-                               case FONT_SIZE_LARGER:
+                               case LARGER_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_LARGER));
                                        break;
-                               case FONT_SIZE_LARGEST:
+                               case LARGEST_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_LARGEST));
                                        break;
-                               case FONT_SIZE_HUGE:
+                               case HUGE_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_HUGE));
                                        break;
-                               case FONT_SIZE_HUGER:
+                               case HUGER_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_HUGER));
                                        break;
-                               case FONT_SIZE_INCREASE:
+                               case INCREASE_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_INCREASE));
                                        break;
-                               case FONT_SIZE_DECREASE:
+                               case DECREASE_SIZE:
                                        tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_DECREASE));
                                        break;
-                               case FONT_SIZE_INHERIT:
-                               case FONT_SIZE_NORMAL:
+                               case INHERIT_SIZE:
+                               case NORMAL_SIZE:
                                        break;
                                default:
                                        // the other tags are for internal use
@@ -3229,52 +3283,52 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
                                size_flag = false;
                        }
                        switch (curr_size) {
-                       case FONT_SIZE_TINY:
+                       case TINY_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_TINY));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_SCRIPT:
+                       case SCRIPT_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_SCRIPT));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_FOOTNOTE:
+                       case FOOTNOTE_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_FOOTNOTE));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_SMALL:
+                       case SMALL_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_SMALL));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_LARGE:
+                       case LARGE_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_LARGE));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_LARGER:
+                       case LARGER_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_LARGER));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_LARGEST:
+                       case LARGEST_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_LARGEST));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_HUGE:
+                       case HUGE_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_HUGE));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_HUGER:
+                       case HUGER_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_HUGER));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_INCREASE:
+                       case INCREASE_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_INCREASE));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_DECREASE:
+                       case DECREASE_SIZE:
                                tagsToOpen.push_back(html::FontTag(html::FT_SIZE_DECREASE));
                                size_flag = true;
                                break;
-                       case FONT_SIZE_NORMAL:
-                       case FONT_SIZE_INHERIT:
+                       case NORMAL_SIZE:
+                       case INHERIT_SIZE:
                                break;
                        default:
                                // the other tags are for internal use
@@ -3368,10 +3422,12 @@ bool Paragraph::isLineSeparator(pos_type pos) const
 }
 
 
-bool Paragraph::isWordSeparator(pos_type pos) const
+bool Paragraph::isWordSeparator(pos_type pos, bool const ignore_deleted) const
 {
        if (pos == size())
                return true;
+       if (ignore_deleted && isDeleted(pos))
+               return false;
        if (Inset const * inset = getInset(pos))
                return !inset->isLetter();
        // if we have a hard hyphen (no en- or emdash) or apostrophe
@@ -3975,13 +4031,13 @@ void Paragraph::deregisterWords()
 
 
 void Paragraph::locateWord(pos_type & from, pos_type & to,
-       word_location const loc) const
+       word_location const loc, bool const ignore_deleted) const
 {
        switch (loc) {
        case WHOLE_WORD_STRICT:
                if (from == 0 || from == size()
-                   || isWordSeparator(from)
-                   || isWordSeparator(from - 1)) {
+                   || isWordSeparator(from, ignore_deleted)
+                   || isWordSeparator(from - 1, ignore_deleted)) {
                        to = from;
                        return;
                }
@@ -3989,13 +4045,13 @@ void Paragraph::locateWord(pos_type & from, pos_type & to,
 
        case WHOLE_WORD:
                // If we are already at the beginning of a word, do nothing
-               if (!from || isWordSeparator(from - 1))
+               if (!from || isWordSeparator(from - 1, ignore_deleted))
                        break;
                // fall through
 
        case PREVIOUS_WORD:
                // always move the cursor to the beginning of previous word
-               while (from && !isWordSeparator(from - 1))
+               while (from && !isWordSeparator(from - 1, ignore_deleted))
                        --from;
                break;
        case NEXT_WORD:
@@ -4006,7 +4062,7 @@ void Paragraph::locateWord(pos_type & from, pos_type & to,
                break;
        }
        to = from;
-       while (to < size() && !isWordSeparator(to))
+       while (to < size() && !isWordSeparator(to, ignore_deleted))
                ++to;
 }
 
@@ -4186,7 +4242,7 @@ SpellChecker::Result Paragraph::spellCheck(pos_type & from, pos_type & to,
        if (!d->layout_->spellcheck || !inInset().allowSpellCheck())
                return result;
 
-       locateWord(from, to, WHOLE_WORD);
+       locateWord(from, to, WHOLE_WORD, true);
        if (from == to || from >= size())
                return result;