Replace hardcoded inheritFont() with InheritFont InsetLayout tag

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.
This commit is contained in:
Jean-Marc Lasgouttes 2023-07-22 23:27:09 +02:00
parent 747de78f9c
commit 81e35bc396
10 changed files with 45 additions and 23 deletions

View File

@ -4,7 +4,7 @@
# #
# Detailed format description is available in the customization manual # Detailed format description is available in the customization manual
Format 100 Format 101
Provides stdinsets 1 Provides stdinsets 1
@ -19,6 +19,7 @@ InsetLayout Marginal
LabelString Margin LabelString Margin
LatexType command LatexType command
LatexName marginpar LatexName marginpar
InheritFont false
Font Font
Size Small Size Small
EndFont EndFont
@ -52,6 +53,7 @@ InsetLayout Foot
LatexType Command LatexType Command
LatexName footnote LatexName footnote
Counter footnote Counter footnote
InheritFont false
Font Font
Size Small Size Small
EndFont EndFont
@ -138,6 +140,7 @@ InsetLayout Note:Comment
LatexName comment LatexName comment
Requires verbatim Requires verbatim
BgColor commentbg BgColor commentbg
InheritFont false
LabelFont LabelFont
Color comment Color comment
Size Small Size Small
@ -179,6 +182,7 @@ InsetLayout Note:Greyedout
LatexName lyxgreyedout LatexName lyxgreyedout
Requires color,lyxgreyedout Requires color,lyxgreyedout
BgColor greyedoutbg BgColor greyedoutbg
InheritFont false
Font Font
Size Normal Size Normal
Color greyedouttext Color greyedouttext
@ -351,6 +355,7 @@ InsetLayout Listings
LabelString Listings[[inset]] LabelString Listings[[inset]]
LatexType none LatexType none
Decoration minimalistic Decoration minimalistic
InheritFont false
Font Font
Color foreground Color foreground
Family typewriter Family typewriter
@ -462,6 +467,7 @@ InsetLayout IndexMacro:subentry
End End
InsetLayout Box InsetLayout Box
InheritFont false
LabelFont LabelFont
Color foreground Color foreground
Size Small Size Small
@ -572,6 +578,7 @@ End
InsetLayout Float InsetLayout Float
LaTeXType environment LaTeXType environment
InheritFont false
LabelFont LabelFont
Color collapsible Color collapsible
Size Small Size Small
@ -800,6 +807,7 @@ InsetLayout PrintNomencl
End End
InsetLayout Tabular InsetLayout Tabular
InheritFont false
HTMLStyle HTMLStyle
table { table {
border-collapse: collapse; border-collapse: collapse;

View File

@ -478,8 +478,9 @@ def convert(lines, end_format):
re_trimLabelStringAppendix = re.compile(b'^(\\s*LabelStringAppendix\\s+)"\\s*(.*?)\\s*"\\s*$') re_trimLabelStringAppendix = re.compile(b'^(\\s*LabelStringAppendix\\s+)"\\s*(.*?)\\s*"\\s*$')
re_trimEndLabelString = re.compile(b'^(\\s*EndLabelString\\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*$') 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 for sectioning styles (hardcoded in 1.3)
counters = {b"part" : b"\\Roman{part}", counters = {b"part" : b"\\Roman{part}",
b"chapter" : b"\\arabic{chapter}", b"chapter" : b"\\arabic{chapter}",
@ -586,7 +587,36 @@ def convert(lines, end_format):
i += 1 i += 1
continue 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. # nothing to do.
i += 1 i += 1
continue continue

View File

@ -59,7 +59,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script, // You should also run the development/tools/updatelayouts.py script,
// to update the format of all of our layout files. // 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 // Layout format for the current lyx file format. Controls which format is

View File

@ -127,8 +127,6 @@ public:
/// ///
bool neverIndent() const override { return true; } bool neverIndent() const override { return true; }
/// ///
bool inheritFont() const override { return false; }
///
void latex(otexstream &, OutputParams const &) const override; void latex(otexstream &, OutputParams const &) const override;
/// ///
int plaintext(odocstringstream & ods, OutputParams const & op, int plaintext(odocstringstream & ods, OutputParams const & op,

View File

@ -105,8 +105,6 @@ private:
/// ///
bool insetAllowed(InsetCode) const override; bool insetAllowed(InsetCode) const override;
/// ///
bool inheritFont() const override { return false; }
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
/// ///
bool hasSubCaptions(ParIterator const & it) const override; bool hasSubCaptions(ParIterator const & it) const override;

View File

@ -31,10 +31,6 @@ private:
void write(std::ostream & os) const override; void write(std::ostream & os) const override;
/// ///
bool insetAllowed(InsetCode) 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; }
}; };

View File

@ -43,8 +43,6 @@ public:
private: private:
/// ///
bool isLabeled() const override { return true; } 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; } InsetCode lyxCode() const override { return LISTINGS_CODE; }
/// lstinline is inlined, normal listing is displayed /// lstinline is inlined, normal listing is displayed

View File

@ -61,8 +61,6 @@ private:
InsetCode lyxCode() const override { return NOTE_CODE; } InsetCode lyxCode() const override { return NOTE_CODE; }
/// ///
docstring layoutName() const override; docstring layoutName() const override;
///
bool inheritFont() const override { return params_.type == InsetNoteParams::Note; }
/// Is the content of this inset part of the output document? /// Is the content of this inset part of the output document?
bool producesOutput() const override bool producesOutput() const override
{ return params_.type == InsetNoteParams::Greyedout; } { return params_.type == InsetNoteParams::Greyedout; }

View File

@ -95,8 +95,6 @@ public:
/// ///
bool neverIndent() const override { return true; } bool neverIndent() const override { return true; }
/// ///
bool inheritFont() const override { return true; }
///
int plaintext(odocstringstream & ods, OutputParams const & op, int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const override; size_t max_length = INT_MAX) const override;
/// ///

View File

@ -62,6 +62,8 @@ public:
/// ///
InsetCode lyxCode() const override { return CELL_CODE; } InsetCode lyxCode() const override { return CELL_CODE; }
/// ///
docstring layoutName() const override { return from_ascii("Tabular:Cell"); }
///
Inset * clone() const override { return new InsetTableCell(*this); } Inset * clone() const override { return new InsetTableCell(*this); }
/// ///
bool getStatus(Cursor & cur, FuncRequest const & cmd, bool getStatus(Cursor & cur, FuncRequest const & cmd,
@ -88,8 +90,6 @@ public:
UpdateType utype, TocBackend & backend) const override; UpdateType utype, TocBackend & backend) const override;
/// ///
void metrics(MetricsInfo &, Dimension &) 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? /// Can the cell contain several paragraphs?
bool allowMultiPar() const override { return !isMultiRow && (!isMultiColumn || isFixedWidth); } bool allowMultiPar() const override { return !isMultiRow && (!isMultiColumn || isFixedWidth); }
/// ///
@ -1039,8 +1039,6 @@ public:
/// ///
bool canPaintChange(BufferView const &) const override { return true; } bool canPaintChange(BufferView const &) const override { return true; }
/// ///
bool inheritFont() const override { return false; }
///
bool allowMultiPar() const override; bool allowMultiPar() const override;
/// ///
bool allowsCaptionVariation(std::string const &) const override; bool allowsCaptionVariation(std::string const &) const override;