Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fc-pregmod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pregmodfan
fc-pregmod
Commits
78f11ffc
Commit
78f11ffc
authored
6 years ago
by
deepmurk
Browse files
Options
Downloads
Patches
Plain Diff
Sync2
Sync
parent
92a93e7e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!2047
RA rework
,
!1914
Belly Stuff + Fixes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
artTools/normalize_svg.py
+0
-76
0 additions, 76 deletions
artTools/normalize_svg.py
with
0 additions
and
76 deletions
artTools/normalize_svg.py
deleted
100644 → 0
+
0
−
76
View file @
92a93e7e
#!/usr/bin/env python3
'''
Application for
"
fixing
"
SVGs edited with Inkscape
These problems are addressed:
* Inkscape notoriously copies class styles into the object definitions.
https://bugs.launchpad.net/inkscape/+bug/167937
* Inkscape uses labels on layers. Layers are basically named groups.
Inkscape does not sync the group id with the layer label.
Usage Example:
python3 inkscape_svg_fixup.py vector_source.svg
Note:
The output of lxml differs greatly from standard SVG indentation.
Please open and save the file in Inkscape before committing.
'''
import
lxml.etree
as
etree
import
sys
def
fix
(
tree
):
# know namespaces
ns
=
{
'
svg
'
:
'
http://www.w3.org/2000/svg
'
,
'
inkscape
'
:
'
http://www.inkscape.org/namespaces/inkscape
'
}
# find document global style definition
# mangle it and interpret as python dictionary
style_element
=
tree
.
find
(
'
./svg:style
'
,
namespaces
=
ns
)
style_definitions
=
style_element
.
text
pythonic_style_definitions
=
'
{
'
+
style_definitions
.
\
replace
(
'
\t
.
'
,
'"'
).
replace
(
'
{
'
,
'"
:
"'
).
replace
(
'
}
'
,
'"
,
'
).
\
replace
(
'
/*
'
,
'
#
'
)
+
'
}
'
styles
=
eval
(
pythonic_style_definitions
)
# go through all SVG elements
for
elem
in
tree
.
iter
():
if
(
elem
.
tag
==
etree
.
QName
(
ns
[
'
svg
'
],
'
g
'
)):
# compare inkscape label with group element ID
l
=
elem
.
get
(
etree
.
QName
(
ns
[
'
inkscape
'
],
'
label
'
))
if
l
:
i
=
elem
.
get
(
'
id
'
)
if
(
i
!=
l
):
print
(
"
Overwriting ID %s with Label %s...
"
%
(
i
,
l
))
elem
.
set
(
'
id
'
,
l
)
# remove all offending style attributes
s
=
elem
.
get
(
'
style
'
)
c
=
elem
.
get
(
'
class
'
)
if
(
c
and
s
):
s
=
s
.
lower
()
c
=
c
.
split
(
'
'
)[
0
]
# regard main style only
cs
=
''
if
c
in
styles
:
cs
=
styles
[
c
].
strip
(
'
;
'
).
lower
()
if
(
c
not
in
styles
):
print
(
"
Object id %s references unknown style class %s.
"
%
(
i
,
c
))
else
:
if
(
cs
!=
s
.
strip
(
'
;
'
)):
print
(
"
Style %s removed from object id %s differed from class %s style %s.
"
%
(
s
,
i
,
c
,
cs
))
del
elem
.
attrib
[
"
style
"
]
if
__name__
==
"
__main__
"
:
input_file
=
sys
.
argv
[
1
]
tree
=
etree
.
parse
(
input_file
)
fix
(
tree
)
# store SVG into file (input file is overwritten)
svg
=
etree
.
tostring
(
tree
,
pretty_print
=
True
)
with
open
(
input_file
,
'
wb
'
)
as
f
:
f
.
write
(
'
<?xml version=
"
1.0
"
encoding=
"
UTF-8
"
standalone=
"
no
"
?>
\n
'
.
encode
(
"
utf-8
"
))
f
.
write
(
svg
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment