]> git.lyx.org Git - features.git/commitdiff
Fix bug #6919 by splitting Inset::noFontChange() into inheritFont() and
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 22 Feb 2011 19:41:04 +0000 (19:41 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 22 Feb 2011 19:41:04 +0000 (19:41 +0000)
resetFontEdit(). The former is used for on-screen and export formatting,
and the latter is used for interactive editing.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37761 a592a061-630c-0410-9148-cb99ea01b6c8

15 files changed:
src/Paragraph.cpp
src/Text.h
src/Text2.cpp
src/TextMetrics.cpp
src/insets/Inset.h
src/insets/InsetBox.h
src/insets/InsetFlex.cpp
src/insets/InsetFlex.h
src/insets/InsetFloat.h
src/insets/InsetFootlike.h
src/insets/InsetListings.h
src/insets/InsetNote.h
src/insets/InsetTabular.h
src/mathed/MathMacroTemplate.h
src/rowpainter.cpp

index 7778e4019a6a490c30bf2a88183d29f7c6a2f7e5..0df5e364321dda2f2f0459f6d13455369077244c 100644 (file)
@@ -1091,7 +1091,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->noFontChange()) {
+       if (open_font && !inset->inheritFont()) {
                bool closeLanguage = arabtex
                        || basefont.isRightToLeft() == running_font.isRightToLeft();
                unsigned int count = running_font.latexWriteEndChanges(os,
index 88d107322478d07d57c125d340acc7af741cd88b..f4110e260f5fe820ab2a56de19d862fafd3a4d18 100644 (file)
@@ -66,11 +66,9 @@ public:
                Font const & font, Font const & display_font);
 
        /** Needed to propagate font changes to all text cells of insets
-        *  that are not allowed inside a font change (bug 1973).
+        *  that are not allowed inside a font change (bugs 1973, 6919).
         *  Must not be called if \p pos denotes an ordinary character or an
         *  inset that is alowed inside a font change.
-        *  FIXME: This should be removed, see documentation of noFontChange
-        *  in insetbase.h
         */
        void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
                Font const & font, bool toggleall = false);
index 24a3317cf7cafcf14c7438dcd739b22574ea3d8b..ae82050fce1c5ca7b00cc83a1bf6b98ee3090ce0 100644 (file)
@@ -167,7 +167,7 @@ void Text::setInsetFont(BufferView const & bv, pit_type pit,
                pos_type pos, Font const & font, bool toggleall)
 {
        Inset * const inset = pars_[pit].getInset(pos);
-       LASSERT(inset && inset->noFontChange(), /**/);
+       LASSERT(inset && inset->resetFontEdit(), /**/);
 
        CursorSlice::idx_type endidx = inset->nargs();
        for (CursorSlice cs(*inset); cs.idx() != endidx; ++cs.idx()) {
@@ -345,11 +345,9 @@ void Text::setFont(BufferView const & bv, CursorSlice const & begin,
                pit_type const pit = dit.pit();
                pos_type const pos = dit.pos();
                Inset * inset = pars_[pit].getInset(pos);
-               if (inset && inset->noFontChange()) {
+               if (inset && inset->resetFontEdit()) {
                        // We need to propagate the font change to all
-                       // text cells of the inset (bug 1973).
-                       // FIXME: This should change, see documentation
-                       // of noFontChange in Inset.h
+                       // text cells of the inset (bugs 1973, 6919).
                        setInsetFont(bv, pit, pos, font, toggleall);
                }
                TextMetrics const & tm = bv.textMetrics(this);
index fd576c31b2a254a460999dddede9be56606a9b37..4ca0592e74fa8e7779c2c9561b34d8ba077735f9 100644 (file)
@@ -396,8 +396,6 @@ bool TextMetrics::redoParagraph(pit_type const pit)
        }
 
        // redo insets
-       // FIXME: We should always use getFont(), see documentation of
-       // noFontChange() in Inset.h.
        Font const bufferfont = buffer.params().getFont();
        InsetList::const_iterator ii = par.insetList().begin();
        InsetList::const_iterator iend = par.insetList().end();
@@ -418,8 +416,8 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                Dimension dim;
                int const w = max_width_ - leftMargin(max_width_, pit, ii->pos)
                        - right_margin;
-               Font const & font = ii->inset->noFontChange() ?
-                       bufferfont : displayFont(pit, ii->pos);
+               Font const & font = ii->inset->inheritFont() ?
+                       displayFont(pit, ii->pos) : bufferfont;
                MacroContext mc(&buffer, parPos);
                MetricsInfo mi(bv_, font.fontInfo(), w, mc);
                ii->inset->metrics(mi, dim);
index e62da465e9f35556e0f4d5d19a8820a4bec67f72..c4375b6fffadc39d2de24cbf34f83bb62e636951 100644 (file)
@@ -520,14 +520,29 @@ public:
        /// returns whether this inset is allowed in other insets of given mode
        virtual bool allowedIn(mode_type) const { return true; }
        /**
-        * Is this inset allowed within a font change?
-        *
-        * FIXME: noFontChange means currently that the font change is closed
-        * in LaTeX before the inset, and that the contents of the inset
-        * will be in default font. This should be changed so that the inset
-        * changes the font again.
+        * The font is inherited from the parent for LaTeX export if this
+        * method returns true. No open font changes are closed in front of
+        * the inset for LaTeX export, and the font is inherited for all other
+        * exports as well as on screen.
+        * If this method returns false all open font changes are closed in
+        * front of the inset for LaTeX export. The default font is used
+        * inside the inset for all exports and on screen.
+        */
+       virtual bool inheritFont() const { return true; }
+       /**
+        * If this method returns true all explicitly set font attributes
+        * are reset during editing operations.
+        * For copy/paste the operations the language is never changed, since
+        * the language of a given text never changes if the text is
+        * formatted differently, while other font attribues like size may
+        * need to change if the text is copied from one environment to
+        * another one.
+        * If it returns false no font attribute is reset.
+        * The default implementation returns the negation of inheritFont(),
+        * since inherited inset font attributes do not need to be changed,
+        * and non-inherited ones need to be set explicitly.
         */
-       virtual bool noFontChange() const { return false; }
+       virtual bool resetFontEdit() const { return !inheritFont(); }
 
        /// set the change for the entire inset
        virtual void setChange(Change const &) {}
index 57c1f795f4840c2d3ab0b534eba1250b5b77caca..922a92f51126b17051bf45200b372e5420915177 100644 (file)
@@ -108,8 +108,10 @@ private:
        bool forcePlainLayout(idx_type = 0) const;
        ///
        bool neverIndent() const { return true; }
-       ///
-       bool noFontChange() const { return true; }
+       /** returns false if, when outputing LaTeX, font changes should
+           be closed before generating this inset. This is needed for
+           insets that may contain several paragraphs */
+       bool inheritFont() const { return false; }
        ///
        void latex(otexstream &, OutputParams const &) const;
        ///
index cf3741263c7f4edb77738b46924842681ee7008d..44651cc026816ac99ac1807d68e88c9fdd76d810 100644 (file)
@@ -56,6 +56,14 @@ InsetLayout const & InsetFlex::getLayout() const
 }
 
 
+bool InsetFlex::resetFontEdit() const
+{
+       if (getLayout().resetsFont())
+               return true;
+       return InsetCollapsable::resetFontEdit();
+}
+
+
 InsetLayout::InsetDecoration InsetFlex::decoration() const
 {
        InsetLayout::InsetDecoration const dec = getLayout().decoration();
index 922f7c566d709489c1a6e9fed3b5610173f2f535..bae49b26c0fc9ec7ca38dc11032e9fc1556f1c10 100644 (file)
@@ -30,12 +30,14 @@ public:
        InsetLayout const & getLayout() const;
        ///
        InsetCode lyxCode() const { return FLEX_CODE; }
+       ///
+       bool resetFontEdit() const;
        /// Default looks
        InsetLayout::InsetDecoration decoration() const;
        ///
        void write(std::ostream &) const;
        /// should paragraph indendation be ommitted in any case?
-       bool neverIndent() const { return true; }       
+       bool neverIndent() const { return true; }
        ///
        bool hasSettings() const { return false; }
        ///
index 9bfc120bb54d8f5bef3f6fcaa3f6f51ac9e007f4..3c9a717473cf87bb4d646aaa29ecda04478f37e2 100644 (file)
@@ -90,10 +90,10 @@ private:
        docstring xhtml(XHTMLStream &, OutputParams const &) const;
        ///
        bool insetAllowed(InsetCode) const;
-       /** returns true if, when outputing LaTeX, font changes should
+       /** returns false if, when outputing LaTeX, font changes should
            be closed before generating this inset. This is needed for
            insets that may contain several paragraphs */
-       bool noFontChange() const { return true; }
+       bool inheritFont() const { return false; }
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
        // Update the counters of this inset and of its contents
index 4fe2d9eddac055ca5821c62f5b8597ce6725ef17..f16f355a963b09d44adee31689717c95065892c3 100644 (file)
@@ -35,10 +35,10 @@ private:
        void write(std::ostream & os) const;
        ///
        bool insetAllowed(InsetCode) const;
-       /** returns true if, when outputing LaTeX, font changes should
+       /** returns false if, when outputing LaTeX, font changes should
            be closed before generating this inset. This is needed for
            insets that may contain several paragraphs */
-       bool noFontChange() const { return true; }
+       bool inheritFont() const { return false; }
 };
 
 
index 3741f6d0dbd3a1ead79934a9c3b329f7c60ef500..18125dc3bb6f0a765eb4cc2a27b4667f809a73e0 100644 (file)
@@ -40,8 +40,8 @@ public:
 private:
        ///
        bool isLabeled() const { return true; }
-       ///
-       bool noFontChange() const { return true; }
+       /// false is needed since listings do their own font handling.
+       bool inheritFont() const { return false; }
        ///
        InsetCode lyxCode() const { return LISTINGS_CODE; }
        /// lstinline is inlined, normal listing is displayed
index 24f9a66542e94149778bbb1e06044c51274b432e..04435a0b40358b1209e5de6ee5f068abe858b1ce 100644 (file)
@@ -63,8 +63,10 @@ private:
        docstring name() const;
        ///
        DisplayType display() const;
-       ///
-       bool noFontChange() const { return params_.type != InsetNoteParams::Note; }
+       /** returns false if, when outputing LaTeX, font changes should
+           be closed before generating this inset. This is needed for
+           insets that may contain several paragraphs */
+       bool inheritFont() const { return params_.type == InsetNoteParams::Note; }
        /// Is the content of this inset part of the output document?
        bool producesOutput() const
                { return params_.type == InsetNoteParams::Greyedout; }
index 8d1c56c0dceba0c90a12778f13d179858bf148bf..00124eab7ad73c075be10455028c80c3dfff9368 100644 (file)
@@ -803,10 +803,10 @@ public:
        bool allowSpellCheck() const { return true; }
        ///
        bool canTrackChanges() const { return true; }
-       /** returns true if, when outputing LaTeX, font changes should
+       /** returns false if, when outputing LaTeX, font changes should
            be closed before generating this inset. This is needed for
            insets that may contain several paragraphs */
-       bool noFontChange() const { return true; }
+       bool inheritFont() const { return false; }
        ///
        DisplayType display() const;
        ///
index be3b7ee5f2e17bd1943c019979d9b8c9051faf5b..0efbb24a84b1114c6cff4894821c3ced201748fd 100644 (file)
@@ -58,7 +58,7 @@ public:
        ///
        int plaintext(odocstream &, OutputParams const &) const;
        ///
-       bool noFontChange() const { return true; }
+       bool inheritFont() const { return false; }
 
        ///
        docstring name() const;
index 21c1d9d3fccb6657b1d59af1c06aa36dfed64a25..12fb486a054becf9686801d0c78c5af91dc0608e 100644 (file)
@@ -125,11 +125,8 @@ void RowPainter::paintInset(Inset const * inset, pos_type const pos)
        // requires a full repaint
        bool pi_full_repaint = pi_.full_repaint;
 
-       // FIXME: We should always use font, see documentation of
-       // noFontChange() in Inset.h.
-       pi_.base.font = inset->noFontChange() ?
-               pi_.base.bv->buffer().params().getFont().fontInfo() :
-               font.fontInfo();
+       pi_.base.font = inset->inheritFont() ? font.fontInfo() :
+               pi_.base.bv->buffer().params().getFont().fontInfo();
        pi_.ltr_pos = (bidi_.level(pos) % 2 == 0);
        pi_.change_ = change_.changed() ? change_ : par_.lookupChange(pos);