]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/layout2layout.py
* layouttranslations.review - review of all langs.
[lyx.git] / lib / scripts / layout2layout.py
index 113f99bf04fe1127b52e028e532a00d589e1f6d0..32f095663e2d1efb09dac79a7448dbaae58359d7 100644 (file)
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 # file layout2layout.py
@@ -144,6 +143,28 @@ import os, re, string, sys
 # Incremented to format 42, 22 December 2012 by spitz
 # New Style tag "ItemCommand"
 
+# Incremented to format 43, 30 December 2012 by spitz
+# Extended InsetCaption format
+
+# Incremented to format 44, 9 February 2013 by rgh
+# Remove COUNTER label style; rename as STATIC
+# Rename TOP_ENVIRONMENT to ABOVE and CENTERED_TOP_ENVIRONMENT to CENTERED
+
+# Incremented to format 45, 12 February 2013 by rgh
+# New Tag "NoInsetLayout"
+
+# Incremented to format 46, 15 May 2013 by gb
+# New Tag "ForceLocal"
+
+# Incremented to format 47, 23 May 2013 by rgh
+# Add PackageOptions tag
+
+# Incremented to format 48, 31 May 2013 by rgh
+# Add InitialValue tag for counters
+
+# Incremented to format 49, 10 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").
 
@@ -151,7 +172,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.sh script to update all
 # layout files to the new format.
 
-currentFormat = 42
+currentFormat = 49
 
 
 def usage(prog_name):
@@ -237,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)
@@ -256,6 +278,12 @@ def convert(lines):
     # Arguments
     re_OptArgs = re.compile(r'^(\s*)OptionalArgs(\s+)(\d+)\D*$', re.IGNORECASE)
     re_ReqArgs = re.compile(r'^(\s*)RequiredArgs(\s+)(\d+)\D*$', re.IGNORECASE)
+    
+    # various changes associated with changing how chapters are handled
+    re_LabelTypeIsCounter = re.compile(r'^(\s*)LabelType(\s*)Counter\s*$', re.IGNORECASE)
+    re_TopEnvironment = re.compile(r'^(\s*)LabelType(\s+)Top_Environment\s*$', re.IGNORECASE)
+    re_CenteredEnvironment = re.compile(r'^(\s*)LabelType(\s+)Centered_Top_Environment\s*$', re.IGNORECASE)
+    re_ChapterStyle = re.compile(r'^\s*Style\s+Chapter\s*$', re.IGNORECASE)
 
 
     # counters for sectioning styles (hardcoded in 1.3)
@@ -276,7 +304,7 @@ def convert(lines):
                         "subparagraph"  : "\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}.\\arabic{paragraph}.\\arabic{subparagraph}"}
 
     # Value of TocLevel for sectioning styles
-    toclevels = {"part"          : 0,
+    toclevels = {"part"          : -1,
                  "chapter"       : 0,
                  "section"       : 1,
                  "subsection"    : 2,
@@ -305,6 +333,12 @@ def convert(lines):
     flexstyles = []
     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
@@ -338,7 +372,7 @@ def convert(lines):
                     # nothing to do
                     return format
                 else:
-                    error('Cannot convert file format %s' % format)
+                    error('Cannot convert file format %s to %s' % (format, currentFormat))
             else:
                 lines.insert(i, "Format 2")
                 only_comment = 0
@@ -361,6 +395,81 @@ 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
+            continue
+
+        if format == 43:
+          match = re_LabelTypeIsCounter.match(lines[i])
+          if match:
+            if inchapter:
+             lines[i] = match.group(1) + "LabelType" + match.group(2) + "Above"              
+            else:
+              lines[i] = match.group(1) + "LabelType" + match.group(2) + "Static"
+
+          match = re_TopEnvironment.match(lines[i])
+          if match:
+            lines[i] = match.group(1) + "LabelType" + match.group(2) + "Above"
+
+          match = re_CenteredEnvironment.match(lines[i])
+          if match:
+            lines[i] = match.group(1) + "LabelType" + match.group(2) + "Centered"
+
+          if inchapter:
+            match = re_Style.match(lines[i])
+            if match:
+              inchapter = False
+          else:
+            match = re_ChapterStyle.match(lines[i])
+            if match:
+              inchapter = True
+
+          i += 1
+          continue
+
+        if format == 42:
+          if lines[i] == "InsetLayout Caption":
+            lines[i] = "InsetLayout Caption:Standard"
+          i += 1
+          continue
+        
         if format == 41:
             # nothing to do.
             i += 1