Skip to content
Snippets Groups Projects
Commit 5c000809 authored by prndev's avatar prndev
Browse files

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.
parent 50dfd22a
No related branches found
No related tags found
2 merge requests!2047RA rework,!1959artTools/normalize_svg.py now sorts style definitions alphabetically.
#!/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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment