add option to check and warn or bail out on flowtext

This commit is contained in:
Tobias Oberstein 2016-04-02 16:49:10 +02:00
parent 70e6fb776e
commit b14e801cb7
4 changed files with 162 additions and 0 deletions

View file

@ -17,3 +17,9 @@ test_version:
test_help:
PYTHONPATH=. python -m scour.scour --help
test_error_on_flowtext:
# this is fine ..
PYTHONPATH=. scour --error-on-flowtext unittests/flowtext-less.svg /dev/null
# .. and this should bail out!
PYTHONPATH=. scour --error-on-flowtext unittests/flowtext.svg /dev/null

View file

@ -2880,6 +2880,14 @@ def scourString(in_string, options=None):
global numBytesSavedInTransforms
doc = xml.dom.minidom.parseString(in_string)
# determine number of flowRoot elements in input document
# flowRoot elements don't render at all on current browsers (04/2016)
cnt_flowText_el = len(doc.getElementsByTagName('flowRoot'))
if cnt_flowText_el:
print("SVG input document uses {} flow text elements, which won't render on browsers!".format(cnt_flowText_el))
if options.error_on_flowtext:
sys.exit(1)
# remove <metadata> if the user wants to
if options.remove_metadata:
removeMetadataElements(doc)
@ -3225,6 +3233,10 @@ _option_group_ids.add_option("--protect-ids-prefix",
help="don't remove IDs starting with the given prefix")
_options_parser.add_option_group(_option_group_ids)
_option_group_compatibility = optparse.OptionGroup(_options_parser, "SVG compatibility checks")
_option_group_compatibility.add_option("--error-on-flowtext",
action="store_true", dest="error_on_flowtext", default=False,
help="In case the input SVG uses flow text, bail out with error. Otherwise only warn. (default: False)")
def maybe_gziped_file(filename, mode="r"):

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="flowtext-less.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="350"
inkscape:cy="520"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1559"
inkscape:window-height="876"
inkscape:window-x="41"
inkscape:window-y="24"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1">
<text
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
x="142.85715"
y="638.07648"
id="text2997"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan2999"
x="142.85715"
y="638.07648">abcd</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

78
unittests/flowtext.svg Normal file
View file

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="Neues Dokument 1">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="350"
inkscape:cy="520"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="936"
inkscape:window-height="631"
inkscape:window-x="41"
inkscape:window-y="24"
inkscape:window-maximized="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1">
<flowRoot
xml:space="preserve"
id="flowRoot2985"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"><flowRegion
id="flowRegion2987"><rect
id="rect2989"
width="480"
height="262.85715"
x="45.714287"
y="218.07646" /></flowRegion><flowPara
id="flowPara2991">sfdadasd</flowPara><flowPara
id="flowPara2993">asdasd</flowPara><flowPara
id="flowPara2995">adsa</flowPara></flowRoot> <text
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
x="142.85715"
y="638.07648"
id="text2997"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan2999"
x="142.85715"
y="638.07648">abcd</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB