From 7e7ac31540dd0e2d5ad08931527de802585645c1 Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Wed, 29 Jul 2009 13:42:04 -0500 Subject: [PATCH] Fixes for polygon coord processing. Add --strip-xml-prolog option --- fulltests/grapes.svg | 171 ++++++++++++++++++++++++++++++++++ fulltests/manchester.svg | 194 +++++++++++++++++++++++++++++++++++++++ package.sh | 2 +- release-notes.html | 1 + scour.py | 21 +++-- scra.py | 4 + statistics.html | 41 ++++++++- testscour.py | 2 + 8 files changed, 427 insertions(+), 9 deletions(-) create mode 100644 fulltests/grapes.svg create mode 100644 fulltests/manchester.svg diff --git a/fulltests/grapes.svg b/fulltests/grapes.svg new file mode 100644 index 0000000..6f32572 --- /dev/null +++ b/fulltests/grapes.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fulltests/manchester.svg b/fulltests/manchester.svg new file mode 100644 index 0000000..49b712c --- /dev/null +++ b/fulltests/manchester.svg @@ -0,0 +1,194 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/package.sh b/package.sh index 2e83ca1..3eae3b6 100755 --- a/package.sh +++ b/package.sh @@ -1,5 +1,5 @@ #!/bin/bash -SCOURVER="0.15" +SCOURVER="0.16" cd .. tar cvf scour/tarballs/scour-$SCOURVER.tar scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html gzip scour/tarballs/scour-$SCOURVER.tar diff --git a/release-notes.html b/release-notes.html index b44eb46..9074e8a 100644 --- a/release-notes.html +++ b/release-notes.html @@ -19,6 +19,7 @@
  • Remove trailing zeros after decimal places for all path coordinates
  • Use scientific notation in path coordinates if that representation is shorter
  • Scour polygon coordinates just like path coordinates
  • +
  • Add XML prolog to scour output to ensure valid XML, added --strip-xml-prolog option
  • diff --git a/scour.py b/scour.py index 1681751..26dc7b5 100755 --- a/scour.py +++ b/scour.py @@ -961,8 +961,8 @@ def cleanPath(element) : nums = [] for t in dataset: # convert to a Decimal - nums.append(Decimal(str(t[0]))) - nums.append(Decimal(str(t[1]))) + nums.append(Decimal(str(t[0])) * Decimal(1)) + nums.append(Decimal(str(t[1])) * Decimal(1)) # only create this segment if it is not empty if nums: @@ -1405,6 +1405,10 @@ def scourCoordinates(data): if data != None: c = 0 for coord in data: + # reduce to the proper number of digits + coord = Decimal(coord) * Decimal(1) + + # integerize if we can if int(coord) == coord: coord = Decimal(str(int(coord))) # Decimal.trim() is available in Python 2.6+ to trim trailing zeros @@ -1419,9 +1423,6 @@ def scourCoordinates(data): s = s[:-1] coord = Decimal(s) - # reduce to the proper number of digits - coord = coord * Decimal(1) - # Decimal.normalize() will uses scientific notation - if that # string is smaller, then use it normd = coord.normalize() @@ -1641,7 +1642,12 @@ def scourString(in_string, options=None): lines.append(line) # return the string stripped of empty lines - return "".join(lines) + if options.strip_xml_prolog == False: + xmlprolog = '\n' + else: + xmlprolog = "" + + return xmlprolog + "".join(lines) # used mostly by unit tests # input is a filename @@ -1690,6 +1696,9 @@ _options_parser.add_option("--disable-embed-rasters", _options_parser.add_option("--keep-editor-data", action="store_true", dest="keep_editor_data", default=False, help="won't remove Inkscape, Sodipodi or Adobe Illustrator elements and attributes") +_options_parser.add_option("--strip-xml-prolog", + action="store_true", dest="strip_xml_prolog", default=False, + help="won't output the prolog") # GZ: this is confusing, most people will be thinking in terms of # decimal places, which is not what decimal precision is doing diff --git a/scra.py b/scra.py index f09a778..6775fc1 100644 --- a/scra.py +++ b/scra.py @@ -56,6 +56,7 @@ def form(req): Collapse nested groups when possible
    Strip all unused id attributes
    Simplify colors to #RGB format
    + Strip the <?xml ?> prolog