]> git.lyx.org Git - lyx.git/commitdiff
Replace hardcoded inheritFont() with InheritFont InsetLayout tag
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 22 Jul 2023 21:27:09 +0000 (23:27 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 22 Jul 2023 21:38:53 +0000 (23:38 +0200)
Each removed inheritFont method is replaced by a 'InheritFont false'
line in the relevant InsetLayout entry.

Add code to layout2layout that does this automatically when the entry
is missing.

The case of InsetScript is special, since the inheritFont() was not
needed here: the default is indeed true.

Fixes bug #12238.

lib/layouts/stdinsets.inc
lib/scripts/layout2layout.py
src/TextClass.cpp
src/insets/InsetBox.h
src/insets/InsetFloat.h
src/insets/InsetFootlike.h
src/insets/InsetListings.h
src/insets/InsetNote.h
src/insets/InsetScript.h
src/insets/InsetTabular.h

index 4a7cfc308f45a3b53f4b43983cf8c91244b0671f..8fafff8caf7e6e662585a4c11d82bb3d86bceae0 100644 (file)
@@ -4,7 +4,7 @@
 #
 # Detailed format description is available in the customization manual
 
-Format 100
+Format 101
 
 Provides stdinsets 1
 
@@ -19,6 +19,7 @@ InsetLayout Marginal
        LabelString           Margin
        LatexType             command
        LatexName             marginpar
+       InheritFont           false
        Font
          Size                Small
        EndFont
@@ -52,6 +53,7 @@ InsetLayout Foot
        LatexType             Command
        LatexName             footnote
        Counter               footnote
+       InheritFont           false
        Font
          Size                Small
        EndFont
@@ -138,6 +140,7 @@ InsetLayout Note:Comment
        LatexName             comment
        Requires              verbatim
        BgColor               commentbg
+       InheritFont           false
        LabelFont
          Color               comment
          Size                Small
@@ -179,6 +182,7 @@ InsetLayout Note:Greyedout
        LatexName             lyxgreyedout
        Requires              color,lyxgreyedout
        BgColor               greyedoutbg
+       InheritFont           false
        Font
          Size                Normal
          Color               greyedouttext
@@ -351,6 +355,7 @@ InsetLayout Listings
        LabelString           Listings[[inset]]
        LatexType             none
        Decoration            minimalistic
+       InheritFont           false
        Font
          Color               foreground
          Family              typewriter
@@ -462,6 +467,7 @@ InsetLayout IndexMacro:subentry
 End
 
 InsetLayout Box
+       InheritFont           false
        LabelFont
          Color               foreground
          Size                Small
@@ -572,6 +578,7 @@ End
 
 InsetLayout Float
        LaTeXType             environment
+       InheritFont           false
        LabelFont
          Color               collapsible
          Size                Small
@@ -800,6 +807,7 @@ InsetLayout PrintNomencl
 End
 
 InsetLayout Tabular
+       InheritFont false
        HTMLStyle
                table {
                        border-collapse: collapse;
index 46a433cc229c21b36d5b3e5852c92e3976df3a39..54f705910b42b45a9611e00d1370d840a37d2192 100644 (file)
@@ -478,8 +478,9 @@ def convert(lines, end_format):
     re_trimLabelStringAppendix  = re.compile(b'^(\\s*LabelStringAppendix\\s+)"\\s*(.*?)\\s*"\\s*$')
     re_trimEndLabelString = re.compile(b'^(\\s*EndLabelString\\s+)"\\s*(.*?)\\s*"\\s*$')
     re_trimLabelCounter = re.compile(b'^(\\s*LabelCounter\\s+)"\\s*(.*?)\\s*"\\s*$')
-
-
+    # for format 100
+    re_InsetLayout100 = re.compile(b'^\\s*InsetLayout\\s+\\"?(Box|Float|Foot|Marginal|Listings|Note:Comment|Note:Greyedout|Tabular)(:\\S*)?\\"?\\s*$', re.IGNORECASE)
+    re_InheritFont = re.compile(b'^(\\s*)InheritFont(\\s+)(\\S+)$', re.IGNORECASE)
     # counters for sectioning styles (hardcoded in 1.3)
     counters = {b"part"          : b"\\Roman{part}",
                 b"chapter"       : b"\\arabic{chapter}",
@@ -586,7 +587,36 @@ def convert(lines, end_format):
                 i += 1
             continue
 
-        if 87 <= format <= 101:
+        if format == 100:
+            # InheritFont has been introduced and defaults to true. Some insets had
+            # an hardcoded inheritFont') method returning true. We removed them, so
+            # we want to introduce the correct tag if it is not already there.
+            match = re_InsetLayout100.match(lines[i])
+            if not match:
+                i += 1
+                continue
+
+            inheritfont_found = False
+            inherited = False
+            while i < len(lines):
+                match = re_InheritFont.match(lines[i])
+                if match:
+                    inheritfont_found = True
+                else:
+                    match = re_CopyStyle.match(lines[i])
+                    if match:
+                        inherited = True
+                    else:
+                        match = re_End.match(lines[i])
+                        if match:
+                            break
+                i += 1
+            if not inheritfont_found and not inherited:
+                lines.insert(i, b"\tInheritFont false")
+
+            continue
+
+        if 87 <= format <= 99:
             # nothing to do.
             i += 1
             continue
index b4b1ce99dff9aedfa83094cc6c8e659fb1601df2..4dd9ae091c653c7558cd37b5dc6efa4a201e9c3f 100644 (file)
@@ -59,7 +59,7 @@ namespace lyx {
 // You should also run the development/tools/updatelayouts.py script,
 // to update the format of all of our layout files.
 //
-int const LAYOUT_FORMAT = 100; // forenr: add inset label color
+int const LAYOUT_FORMAT = 101; // lasgouttes: add InheritFont tag
 
 
 // Layout format for the current lyx file format. Controls which format is
index cc80da3ecd219a8de3426f344313d2febd0b3c90..f15896cb33779f8ccca941e4562d15f3469da057 100644 (file)
@@ -127,8 +127,6 @@ public:
        ///
        bool neverIndent() const override { return true; }
        ///
-       bool inheritFont() const override { return false; }
-       ///
        void latex(otexstream &, OutputParams const &) const override;
        ///
        int plaintext(odocstringstream & ods, OutputParams const & op,
index 20ee6452e8660f415fad2403261581a401a2b2a6..50c698a43e1410b5b6ee8065ee5c69d84afaa6d8 100644 (file)
@@ -105,8 +105,6 @@ private:
        ///
        bool insetAllowed(InsetCode) const override;
        ///
-       bool inheritFont() const override { return false; }
-       ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
        ///
        bool hasSubCaptions(ParIterator const & it) const override;
index e0a3fd31d075dfe07f4c4313b21a62fbe4fef6e5..a2f9939d7f347716e3fbf2a37400f97d0640a1e4 100644 (file)
@@ -31,10 +31,6 @@ private:
        void write(std::ostream & os) const override;
        ///
        bool insetAllowed(InsetCode) const override;
-       /** returns false if, when outputting LaTeX, font changes should
-           be closed before generating this inset. This is needed for
-           insets that may contain several paragraphs */
-       bool inheritFont() const override { return false; }
 };
 
 
index d75f96851e95c0aeda8d021f600388fc3c9c3644..c72865cd9038ef761a411ff23cce42c8d892e7a9 100644 (file)
@@ -43,8 +43,6 @@ public:
 private:
        ///
        bool isLabeled() const override { return true; }
-       /// false is needed since listings do their own font handling.
-       bool inheritFont() const override { return false; }
        ///
        InsetCode lyxCode() const override { return LISTINGS_CODE; }
        /// lstinline is inlined, normal listing is displayed
index 32bb26bbf663f5fcf368d8f94d8c58d0bcf3e196..94a07906e5258e2631c85667ad937a126ca4597a 100644 (file)
@@ -61,8 +61,6 @@ private:
        InsetCode lyxCode() const override { return NOTE_CODE; }
        ///
        docstring layoutName() const override;
-       ///
-       bool inheritFont() const override { return params_.type == InsetNoteParams::Note; }
        /// Is the content of this inset part of the output document?
        bool producesOutput() const override
                { return params_.type == InsetNoteParams::Greyedout; }
index 9eb80dbbd5032c9866366b19cf6c72082f5d79e4..1a008a98882548fa1c36334dbcfd9010ef5cd942 100644 (file)
@@ -95,8 +95,6 @@ public:
        ///
        bool neverIndent() const override { return true; }
        ///
-       bool inheritFont() const override { return true; }
-       ///
        int plaintext(odocstringstream & ods, OutputParams const & op,
                      size_t max_length = INT_MAX) const override;
        ///
index 5602984b3339be79d73199034f71ebdb36436489..84b9ae42228fc6beaa3c355af626ee49978fab22 100644 (file)
@@ -62,6 +62,8 @@ public:
        ///
        InsetCode lyxCode() const override { return CELL_CODE; }
        ///
+       docstring layoutName() const override { return from_ascii("Tabular:Cell"); }
+       ///
        Inset * clone() const override { return new InsetTableCell(*this); }
        ///
        bool getStatus(Cursor & cur, FuncRequest const & cmd,
@@ -88,8 +90,6 @@ public:
                                  UpdateType utype, TocBackend & backend) const override;
        ///
        void metrics(MetricsInfo &, Dimension &) const override;
-       /// Needs to be same as InsetTabular
-       bool inheritFont() const override { return false; }
        /// Can the cell contain several paragraphs?
        bool allowMultiPar() const override { return !isMultiRow && (!isMultiColumn || isFixedWidth); }
        ///
@@ -1039,8 +1039,6 @@ public:
        ///
        bool canPaintChange(BufferView const &) const override { return true; }
        ///
-       bool inheritFont() const override { return false; }
-       ///
        bool allowMultiPar() const override;
        ///
        bool allowsCaptionVariation(std::string const &) const override;