This is one of three bugs scheduled for 2.1.0: If you apply font changes, 
e.g. small size to a paragraph including a chunk inset, the result will not 
be compilable anymore (only after saving and reloading the document).

Jean-Marc did the detective work and found out the reason: resetFontEdit() 
returns the wrong value for chunk insets. The attached patch fixes that by 
setting the correct value in the layout file, and making the defaults of 
resetFontEdit() and inheritFont() compatible. See 
http://www.lyx.org/trac/ticket/8874 if you want to understand all details.

I tested this patch extensively, and it works fine now (it is the third 
version), but since it involves a layout file format change I'd rather ask: 
Is it OK to go in? Of course I would convert all other layout files at the 
same time.


Georg
diff --git a/lib/layouts/litinsets.inc b/lib/layouts/litinsets.inc
index 8bcee50..05440cb 100644
--- a/lib/layouts/litinsets.inc
+++ b/lib/layouts/litinsets.inc
@@ -6,7 +6,7 @@
 # Note that this file is included in sweave.module,
 # knitr.module and noweb.module.
 
-Format 48
+Format 49
 
 Counter chunk
     PrettyFormat "Chunk ##"
@@ -43,4 +43,5 @@ InsetLayout "Flex:Chunk"
             LeftDelim     <<
             RightDelim    >>=<br/>
     EndArgument
+    ResetsFont false
 End
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index 36e4130..8644017 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -162,6 +162,9 @@ import os, re, string, sys
 # Incremented to format 48, 31 May 2013 by rgh
 # Add InitialValue tag for counters
 
+# Incremented to format 49, 04 Feb 2014 by gb
+# Change default of "ResetsFont" tag to false
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -169,7 +172,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.sh script to update all
 # layout files to the new format.
 
-currentFormat = 48
+currentFormat = 49
 
 
 def usage(prog_name):
@@ -255,6 +258,7 @@ def convert(lines):
     re_Builtin = re.compile(r'^(\s*)LaTeXBuiltin\s+(\w*)', re.IGNORECASE)
     re_True = re.compile(r'^\s*(?:true|1)\s*$', re.IGNORECASE)
     re_InsetLayout = re.compile(r'^\s*InsetLayout\s+(?:Custom|CharStyle|Element):(\S+)\s*$', re.IGNORECASE)
+    re_ResetsFont = re.compile(r'^(\s*)ResetsFont(\s+)(\S+)$', re.IGNORECASE)
     # with quotes
     re_QInsetLayout = re.compile(r'^\s*InsetLayout\s+"(?:Custom|CharStyle|Element):([^"]+)"\s*$', re.IGNORECASE)
     re_InsetLayout_CopyStyle = re.compile(r'^\s*CopyStyle\s+(?:Custom|CharStyle|Element):(\S+)\s*$', re.IGNORECASE)
@@ -330,6 +334,11 @@ def convert(lines):
     opts = 0
     reqs = 0
     inchapter = False
+    isflexlayout = False         # only used for 48 -> 49
+    # Whether a style is inherited (works only for CopyStyle currently,
+    # not for true inherited styles, see bug 8920
+    inherited = False        # only used for 48 -> 49
+    resetsfont_found = False # only used for 48 -> 49
 
     while i < len(lines):
         # Skip comments and empty lines
@@ -386,6 +395,42 @@ def convert(lines):
                 i += 1
             continue
 
+        if format == 48:
+            # The default of ResetsFont in LyX changed from true to false,
+            # because it is now used for all InsetLayouts, not only flex ones.
+            # Therefore we need to set it to true for all flex insets which do
+            # do not already have a ResetsFont.
+            match = re_InsetLayout2.match(lines[i])
+            if match:
+                resetsfont_found = False
+                inherited = False
+                name = string.lower(match.group(1))
+                if name == "flex" or name[:5] == "flex:":
+                    isflexlayout = True
+                else:
+                    isflexlayout = False
+            match = re_ResetsFont.match(lines[i])
+            if match:
+                resetsfont_found = True
+            match = re_End.match(lines[i])
+            if match:
+                if isflexlayout and not resetsfont_found and not inherited:
+                    lines.insert(i, "\tResetsFont true")
+                    i += 1
+            match = re_Style.match(lines[i])
+            if match:
+                isflexlayout = False
+                inherited = False
+            match = re_Counter.match(lines[i])
+            if match:
+                isflexlayout = False
+                inherited = False
+            match = re_CopyStyle.match(lines[i])
+            if match:
+                inherited = True
+            i += 1
+            continue
+
         if format >= 44 and format <= 47:
             # nothing to do.
             i += 1
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index b77f31b..9d4509c 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -61,7 +61,7 @@ namespace lyx {
 // development/tools/updatelayouts.sh script, to update the format of
 // all of our layout files.
 //
-int const LAYOUT_FORMAT = 48; //rgh: initial values for counter
+int const LAYOUT_FORMAT = 49; //gb: change default of RestsFont
 
 namespace {
 
diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp
index 8b741b7..44707c1 100644
--- a/src/insets/Inset.cpp
+++ b/src/insets/Inset.cpp
@@ -642,6 +642,14 @@ Buffer const * Inset::updateFrontend() const
 }
 
 
+bool Inset::resetFontEdit() const
+{
+	if (getLayout().resetsFont())
+		return true;
+	return !inheritFont();
+}
+
+
 docstring Inset::completionPrefix(Cursor const &) const 
 {
 	return docstring();
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 8165b4c..bd48774 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -540,11 +540,12 @@ public:
 	 * 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(),
+	 * The default implementation returns true if the resetFont layout
+	 * tag is set and otherwise 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 resetFontEdit() const { return !inheritFont(); }
+	virtual bool resetFontEdit() const;
 
 	/// set the change for the entire inset
 	virtual void setChange(Change const &) {}
diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp
index 9a0db9a..70de9fd 100644
--- a/src/insets/InsetFlex.cpp
+++ b/src/insets/InsetFlex.cpp
@@ -57,14 +57,6 @@ 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();
diff --git a/src/insets/InsetFlex.h b/src/insets/InsetFlex.h
index 04fbb5f..8277002 100644
--- a/src/insets/InsetFlex.h
+++ b/src/insets/InsetFlex.h
@@ -30,8 +30,6 @@ public:
 	InsetLayout const & getLayout() const;
 	///
 	InsetCode lyxCode() const { return FLEX_CODE; }
-	///
-	bool resetFontEdit() const;
 	/// Default looks
 	InsetLayout::InsetDecoration decoration() const;
 	///
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index aa35f50..6f1a02f 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -41,7 +41,7 @@ InsetLayout::InsetLayout() :
 	passthru_(false), parbreakisnewline_(false), freespacing_(false), 
 	keepempty_(false), forceltr_(false), 
 	needprotect_(false), intoc_(false), spellcheck_(true), 
-	resetsfont_(true), display_(true), forcelocalfontswitch_(false)
+	resetsfont_(false), display_(true), forcelocalfontswitch_(false)
 { 
 	labelfont_.setColor(Color_error);
 }

Reply via email to