]> git.lyx.org Git - features.git/commitdiff
Switch font for multipar insets
authorEnrico Forestieri <forenr@lyx.org>
Wed, 12 Aug 2020 14:25:35 +0000 (16:25 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 12 Aug 2020 14:25:35 +0000 (16:25 +0200)
Use font switches for insets that allow paragraph breaks rather
than insets that do not inherit outer font settings. No change of
behavior is intended with respect to the current status, but this
will allow a simple and effective fix for #10263.

src/Paragraph.cpp
src/insets/Inset.h
src/insets/InsetTabular.cpp
src/insets/InsetTabular.h
src/insets/InsetText.h

index 58feaf4f25753dd519de5f689857b8716ff4b308..3a9b03419eb11a016ade75bf4b779412b7170766 100644 (file)
@@ -1039,7 +1039,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
        // ArabTeX, though, cannot handle this special behavior, it seems.
        bool arabtex = basefont.language()->lang() == "arabic_arabtex"
                || running_font.language()->lang() == "arabic_arabtex";
-       if (open_font && !inset->inheritFont()) {
+       if (open_font && (!inset->inheritFont() || inset->allowMultiPar())) {
                bool closeLanguage = arabtex
                        || basefont.isRightToLeft() == running_font.isRightToLeft();
                unsigned int count = running_font.latexWriteStartChanges(os, bparams,
@@ -2563,14 +2563,14 @@ void Paragraph::latex(BufferParams const & bparams,
                                             && runningChange == change
                                             && change.type == Change::DELETED
                                             && !os.afterParbreak());
-               bool const non_inherit_inset =
-                               (c == META_INSET && getInset(i) && !getInset(i)->inheritFont());
+               bool const multipar_inset =
+                       (c == META_INSET && getInset(i) && getInset(i)->allowMultiPar());
 
                // Do we need to close the previous font?
                if (open_font &&
                    ((current_font != running_font
                      || current_font.language() != running_font.language())
-                    || (non_inherit_inset
+                    || (multipar_inset
                         && (current_font == prev_font
                             || current_font.language() == prev_font.language()))))
                {
@@ -2658,7 +2658,7 @@ void Paragraph::latex(BufferParams const & bparams,
                                column += 1;
                        }
                        otexstringstream ots;
-                       if (!non_inherit_inset) {
+                       if (!multipar_inset) {
                                column += current_font.latexWriteStartChanges(ots, bparams,
                                                                              runparams, basefont, last_font, false,
                                                                              needsCProtection(runparams.moving_arg));
@@ -2754,13 +2754,13 @@ void Paragraph::latex(BufferParams const & bparams,
                                        }
                                }
                                // We need to restore these after insets with
-                               // inheritFont() false
+                               // allowMultiPar() true
                                Font const save_running_font = running_font;
                                Font const save_basefont = basefont;
                                d->latexInset(bparams, os, rp, running_font,
                                                basefont, real_outerfont, open_font,
                                                runningChange, style, i, column);
-                               if (non_inherit_inset) {
+                               if (multipar_inset) {
                                        running_font = save_running_font;
                                        basefont = save_basefont;
                                }
index 4ef73db0acbcfb1aacc7a4d45813cf916b1e0a3e..922d1cd743137a97d55eeb1454e5bc46fe9c053c 100644 (file)
@@ -592,6 +592,8 @@ public:
        virtual bool asciiOnly() const { return false; }
        /// returns whether this inset is allowed in other insets of given mode
        virtual bool allowedIn(mode_type) const { return true; }
+       /// returns whether paragraph breaks can occur inside this inset
+       virtual bool allowMultiPar() const  { return false; }
        /**
         * The font is inherited from the parent for LaTeX export if this
         * method returns true. No open font changes are closed in front of
index b449ab392ef530d963cd59ff7a19ab4a93e93457..8458ce47285d0449566a37a614e990a38ad3a486 100644 (file)
@@ -4366,6 +4366,18 @@ bool InsetTabular::insetAllowed(InsetCode code) const
 }
 
 
+bool InsetTabular::allowMultiPar() const
+{
+       for (Tabular::col_type c = 0; c < tabular.ncols(); ++c) {
+               for (Tabular::row_type r = 0; r < tabular.nrows(); ++r) {
+                       if (tabular.cellInset(r,c)->allowMultiPar())
+                               return true;
+               }
+       }
+       return false;
+}
+
+
 bool InsetTabular::allowsCaptionVariation(std::string const & newtype) const
 {
        return tabular.is_long_tabular &&
index 028da979694400dacf9ba5bf24e235d823f534ed..fd942049ba6d07c53d86acfb84610443196ca07b 100644 (file)
@@ -83,6 +83,8 @@ public:
        void metrics(MetricsInfo &, Dimension &) const;
        /// Needs to be same as InsetTabular
        bool inheritFont() const { return false; }
+       /// Can the cell contain several paragraphs?
+       bool allowMultiPar() const { return !isMultiRow && (!isMultiColumn || isFixedWidth); }
 private:
        /// unimplemented
        InsetTableCell();
@@ -135,8 +137,6 @@ private:
        virtual bool forceLocalFontSwitch() const;
        /// Is the width forced to some value?
        bool hasFixedWidth() const { return isFixedWidth; }
-       /// Can the cell contain several paragraphs?
-       bool allowMultiPar() const { return !isMultiRow && (!isMultiColumn || isFixedWidth); }
 };
 
 
@@ -979,6 +979,8 @@ public:
            insets that may contain several paragraphs */
        bool inheritFont() const { return false; }
        ///
+       bool allowMultiPar() const;
+       ///
        bool allowsCaptionVariation(std::string const &) const;
        //
        bool isTable() const { return true; }
index d86bfb75d339456def755b311329633fed9f575a..ca09a683c31549851dd419c2a5f26e788e367d26 100644 (file)
@@ -161,7 +161,7 @@ public:
        ///
        virtual bool isMacroScope() const { return false; }
        ///
-       virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
+       bool allowMultiPar() const { return getLayout().isMultiPar(); }
        ///
        bool isInTitle() const { return intitle_context_; }
        ///