]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Assure correct spacing of colored items in mathed
[lyx.git] / src / Paragraph.cpp
index 5cb17228793d7fc4e5343cf6ba194a6ccb24722d..f2d97fe7c97cb9dbc60eac15e39e056391b14ec8 100644 (file)
@@ -84,14 +84,6 @@ using namespace lyx::support;
 
 namespace lyx {
 
-namespace {
-
-/// Inset identifier (above 0x10ffff, for ucs-4)
-char_type const META_INSET = 0x200001;
-
-} // namespace
-
-
 /////////////////////////////////////////////////////////////////////
 //
 // SpellResultRange
@@ -274,9 +266,9 @@ private:
        Ranges ranges_;
        /// the area of the paragraph with pending spell check
        FontSpan refresh_;
-       bool needs_refresh_;
        /// spell state cache version number
        SpellChecker::ChangeNumber current_change_number_;
+       bool needs_refresh_;
 
 
        void correctRangesAfterPos(pos_type pos, int offset)
@@ -460,7 +452,7 @@ public:
        {
                int numskips = 0;
                while (it != et && it->first < start) {
-                       int skip = it->last - it->first + 1;
+                       long skip = it->last - it->first + 1;
                        start += skip;
                        numskips += skip;
                        ++it;
@@ -487,9 +479,6 @@ public:
        ///
        FontList fontlist_;
 
-       ///
-       int id_;
-
        ///
        ParagraphParameters params_;
 
@@ -514,11 +503,13 @@ public:
        Layout const * layout_;
        ///
        SpellCheckerState speller_state_;
+       ///
+       int id_;
 };
 
 
 Paragraph::Private::Private(Paragraph * owner, Layout const & layout)
-       : owner_(owner), inset_owner_(nullptr), id_(-1), begin_of_body_(0), layout_(&layout)
+       : owner_(owner), inset_owner_(nullptr), begin_of_body_(0), layout_(&layout), id_(-1)
 {
        text_.reserve(100);
 }
@@ -531,17 +522,16 @@ int Paragraph::Private::make_id()
        // LFUN_PARAGRAPH_GOTO to switch to a different buffer, for instance in the
        // outliner.
        // (thread-safe)
-       static atomic_uint next_id(0);
+       static int next_id(0);
        return next_id++;
 }
 
 
 Paragraph::Private::Private(Private const & p, Paragraph * owner)
        : owner_(owner), inset_owner_(p.inset_owner_), fontlist_(p.fontlist_),
-         id_(make_id()),
          params_(p.params_), changes_(p.changes_), insetlist_(p.insetlist_),
          begin_of_body_(p.begin_of_body_), text_(p.text_), words_(p.words_),
-         layout_(p.layout_)
+         layout_(p.layout_), id_(make_id())
 {
        requestSpellCheck(p.text_.size());
 }
@@ -549,11 +539,11 @@ Paragraph::Private::Private(Private const & p, Paragraph * owner)
 
 Paragraph::Private::Private(Private const & p, Paragraph * owner,
        pos_type beg, pos_type end)
-       : owner_(owner), inset_owner_(p.inset_owner_), id_(make_id()),
+       : owner_(owner), inset_owner_(p.inset_owner_),
          params_(p.params_), changes_(p.changes_),
          insetlist_(p.insetlist_, beg, end),
          begin_of_body_(p.begin_of_body_), words_(p.words_),
-         layout_(p.layout_)
+         layout_(p.layout_), id_(make_id())
 {
        if (beg >= pos_type(p.text_.size()))
                return;
@@ -2403,8 +2393,9 @@ void Paragraph::latex(BufferParams const & bparams,
        pos_type body_pos = beginOfBody();
        unsigned int column = 0;
 
-       // If we are inside an inset, the real outerfont is local_font
-       Font const real_outerfont = (runparams.local_font != nullptr)
+       // If we are inside an non inheritFont() inset, the real outerfont is local_font
+       Font const real_outerfont = (!inInset().inheritFont()
+                                    && runparams.local_font != nullptr)
                        ? Font(runparams.local_font->fontInfo()) : outerfont;
 
        if (body_pos > 0) {
@@ -2568,7 +2559,7 @@ void Paragraph::latex(BufferParams const & bparams,
                ++column;
 
                // Fully instantiated font
-               Font const current_font = getFont(bparams, i, real_outerfont);
+               Font const current_font = getFont(bparams, i, outerfont);
 
                Font const last_font = running_font;
                bool const in_ct_deletion = (bparams.output_changes
@@ -3027,11 +3018,11 @@ void doFontSwitchDocBook(vector<xml::FontTag> & tagsToOpen,
 
 class OptionalFontType {
 public:
-       bool has_value;
        xml::FontTypes ft;
+       bool has_value;
 
-       OptionalFontType(): has_value(false), ft(xml::FT_EMPH) {} // A possible value at random for ft.
-       OptionalFontType(xml::FontTypes ft): has_value(true), ft(ft) {}
+       OptionalFontType(): ft(xml::FT_EMPH), has_value(false) {} // A possible value at random for ft.
+       OptionalFontType(xml::FontTypes ft): ft(ft), has_value(true) {}
 };
 
 OptionalFontType fontShapeToXml(FontShape fs)
@@ -3058,13 +3049,10 @@ OptionalFontType fontFamilyToXml(FontFamily fm)
        switch (fm) {
        case ROMAN_FAMILY:
                return {xml::FT_ROMAN};
-               break;
        case SANS_FAMILY:
                return {xml::FT_SANS};
-               break;
        case TYPEWRITER_FAMILY:
                return {xml::FT_TYPE};
-               break;
        case INHERIT_FAMILY:
                return {};
        default:
@@ -3111,6 +3099,10 @@ OptionalFontType fontSizeToXml(FontSize fs)
 
 struct DocBookFontState
 {
+       FontShape  curr_fs   = INHERIT_SHAPE;
+       FontFamily curr_fam  = INHERIT_FAMILY;
+       FontSize   curr_size = INHERIT_SIZE;
+
        // track whether we have opened these tags
        bool emph_flag = false;
        bool bold_flag = false;
@@ -3126,16 +3118,12 @@ struct DocBookFontState
        bool faml_flag = false;
        // size tags
        bool size_flag = false;
-
-       FontShape  curr_fs   = INHERIT_SHAPE;
-       FontFamily curr_fam  = INHERIT_FAMILY;
-       FontSize   curr_size = INHERIT_SIZE;
 };
 
 std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwitch(FontInfo const & font_old,
                                                                                           Font const & font,
                                                                                           std::string const & default_family,
-                                                                                          DocBookFontState fs)
+                                                                                          DocBookFontState fs)
 {
        vector<xml::FontTag> tagsToOpen;
        vector<xml::EndFontTag> tagsToClose;
@@ -3160,6 +3148,11 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
        if (font_old.strikeout() != curstate)
                doFontSwitchDocBook(tagsToOpen, tagsToClose, fs.sout_flag, curstate, xml::FT_SOUT);
 
+       // xout
+       curstate = font.fontInfo().xout();
+       if (font_old.xout() != curstate)
+               doFontSwitchDocBook(tagsToOpen, tagsToClose, fs.xout_flag, curstate, xml::FT_XOUT);
+
        // double underbar
        curstate = font.fontInfo().uuline();
        if (font_old.uuline() != curstate)
@@ -3182,16 +3175,14 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
        if (old_fs != fs.curr_fs) {
                if (fs.shap_flag) {
                        OptionalFontType tag = fontShapeToXml(old_fs);
-                       if (tag.has_value) {
+                       if (tag.has_value)
                                tagsToClose.push_back(docbookEndFontTag(tag.ft));
-                       }
                        fs.shap_flag = false;
                }
 
                OptionalFontType tag = fontShapeToXml(fs.curr_fs);
-               if (tag.has_value) {
+               if (tag.has_value)
                        tagsToOpen.push_back(docbookStartFontTag(tag.ft));
-               }
        }
 
        // Font family
@@ -3200,9 +3191,8 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
        if (old_fam != fs.curr_fam) {
                if (fs.faml_flag) {
                        OptionalFontType tag = fontFamilyToXml(old_fam);
-                       if (tag.has_value) {
+                       if (tag.has_value)
                                tagsToClose.push_back(docbookEndFontTag(tag.ft));
-                       }
                        fs.faml_flag = false;
                }
                switch (fs.curr_fam) {
@@ -3241,9 +3231,8 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
        if (old_size != fs.curr_size) {
                if (fs.size_flag) {
                        OptionalFontType tag = fontSizeToXml(old_size);
-                       if (tag.has_value) {
+                       if (tag.has_value)
                                tagsToClose.push_back(docbookEndFontTag(tag.ft));
-                       }
                        fs.size_flag = false;
                }
 
@@ -3254,10 +3243,10 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
                }
        }
 
-       return std::tuple(tagsToOpen, tagsToClose);
+       return std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>>(tagsToOpen, tagsToClose);
 }
 
-}// anonymous namespace
+} // anonymous namespace
 
 
 void Paragraph::simpleDocBookOnePar(Buffer const & buf,
@@ -3291,26 +3280,24 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 
                Font const font = getFont(buf.masterBuffer()->params(), i, outerfont);
 
-               if (start_paragraph) {
-                       // Determine which tags should be opened or closed.
-                       tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs);
+               // Determine which tags should be opened or closed.
+               tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs);
 
-                       // FIXME XHTML
-                       // Other such tags? What about the other text ranges?
+               // FIXME XHTML
+               // Other such tags? What about the other text ranges?
 
-                       vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
-                       vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
-                       for (; cit != cen; ++cit)
-                               xs << *cit;
+               vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
+               vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
+               for (; cit != cen; ++cit)
+                       xs << *cit;
 
-                       vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
-                       vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
-                       for (; sit != sen; ++sit)
-                               xs << *sit;
+               vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
+               vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
+               for (; sit != sen; ++sit)
+                       xs << *sit;
 
-                       tagsToClose.clear();
-                       tagsToOpen.clear();
-               }
+               tagsToClose.clear();
+               tagsToOpen.clear();
 
                if (Inset const * inset = getInset(i)) {
                        if (!runparams.for_toc || inset->isInToc()) {