diff --git a/Makefile b/Makefile index bc870ee..e0365bb 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/scour/scour.py b/scour/scour.py index 3ff0adc..0104a72 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -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 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"): diff --git a/unittests/flowtext-less.svg b/unittests/flowtext-less.svg new file mode 100644 index 0000000..eea559c --- /dev/null +++ b/unittests/flowtext-less.svg @@ -0,0 +1,66 @@ + + + + + + + + + + image/svg+xml + + + + + + + abcd + + diff --git a/unittests/flowtext.svg b/unittests/flowtext.svg new file mode 100644 index 0000000..9409b4f --- /dev/null +++ b/unittests/flowtext.svg @@ -0,0 +1,78 @@ + + + + + + + + + + image/svg+xml + + + + + + + sfdadasdasdasdadsa abcd + +