From 5c000809a651fe8ea161f05ef6ff9719e1f08258 Mon Sep 17 00:00:00 2001
From: prndev <prndev@users.noreply.github.com>
Date: Tue, 1 May 2018 12:19:01 +0200
Subject: [PATCH] artTools/normalize_svg.py now sorts style definitions
 alphabetically.

It looks like inkscape does not sort the definitions, re-arranging them occasionally, making non-edits hard to distinguish from actual edits.
---
 artTools/normalize_svg.py | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/artTools/normalize_svg.py b/artTools/normalize_svg.py
index 9ca07756906..1cbdb169cb9 100644
--- a/artTools/normalize_svg.py
+++ b/artTools/normalize_svg.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 
 '''
-Application for "fixing" SVGs edited with Inkscape
+Application for "normalizing" SVGs
 
 These problems are addressed:
 
@@ -44,8 +44,23 @@ def fix(tree):
         if (i != l):
           print("Overwriting ID %s with Label %s..."%(i, l))
           elem.set('id', l)
-    
-    # remove all offending style attributes
+
+    # clean styles (for easier manual merging)
+    style_string = elem.get('style')
+    if style_string:
+      split_styles = style_string.strip('; ').split(';')
+      styles_pairs = [s.strip('; ').split(':') for s in split_styles]
+      filtered_pairs = [ (k,v) for k,v in styles_pairs if not (
+        k.startswith('font-') or
+        k.startswith('text-') or
+        k.endswith('-spacing') or
+        k in ["line-height", " direction", " writing", " baseline-shift", " white-space", " writing-mode"]
+      )]
+      split_styles = [':'.join(p) for p in filtered_pairs]
+      style_string = ';'.join(sorted(split_styles))
+      elem.attrib["style"] = style_string
+
+    # remove all style attributes offending class styles
     s = elem.get('style')
     c = elem.get('class')
     if (c and s):
-- 
GitLab