From f5672a4843eb6b85e61167d0ebd338234346c246 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Wed, 12 Aug 2020 16:25:35 +0200 Subject: [PATCH] Switch font for multipar insets 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 | 14 +++++++------- src/insets/Inset.h | 2 ++ src/insets/InsetTabular.cpp | 12 ++++++++++++ src/insets/InsetTabular.h | 6 ++++-- src/insets/InsetText.h | 2 +- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 58feaf4f25..3a9b03419e 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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; } diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 4ef73db0ac..922d1cd743 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -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 diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index b449ab392e..8458ce4728 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -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 && diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 028da97969..fd942049ba 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -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; } diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index d86bfb75d3..ca09a683c3 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -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_; } ///