~inkscape.dev/inkscape/readme-update

« back to all changes in this revision

Viewing changes to share/extensions/scour.py

  • Committer: jeff_schiller
  • Date: 2009-11-10 04:05:55 UTC
  • Revision ID: jeff_schiller@users.sourceforge.net-20091110040555-v34tj6janm34udj0
Update scour from 0.21 to 0.22, see http://codedread.com/scour/release-notes.html

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#    at rounded corners)
35
35
 
36
36
# Next Up:
37
 
# + remove unused attributes in parent elements
38
 
# + prevent elements from being stripped if they are referenced in a <style> element
39
 
# + only move common attributes and remove unused attributes after removing duplicate gradients
40
 
# + only move common attributes to parent if the parent contains non-whitespace text nodes
41
 
# + do not pretty-print elements if whitespace is important (xml:space="preserve")
42
37
# - TODO: fix the removal of comment elements (between <?xml?> and <svg>)
43
 
#   (for instance, filter, marker, pattern) - need a crude CSS parser
44
38
# - add an option to remove ids if they match the Inkscape-style of IDs
45
39
# - investigate point-reducing algorithms
46
40
# - parse transform attribute
70
64
        Decimal = FixedPoint    
71
65
 
72
66
APP = 'scour'
73
 
VER = '0.21'
 
67
VER = '0.22'
74
68
COPYRIGHT = 'Copyright Jeff Schiller, 2009'
75
69
 
76
70
NS = {  'SVG':          'http://www.w3.org/2000/svg', 
426
420
        # if this node is a style element, parse its text into CSS
427
421
        if node.nodeName == 'style' and node.namespaceURI == NS['SVG']:
428
422
                # node.firstChild will be either a CDATA or a Text node
429
 
                cssRules = parseCssString(node.firstChild.nodeValue)
430
 
                for rule in cssRules:
431
 
                        for propname in rule['properties']:
432
 
                                propval = rule['properties'][propname]
433
 
                                findReferencingProperty(node, propname, propval, ids)
434
 
                
 
423
                if node.firstChild != None:
 
424
                        cssRules = parseCssString(node.firstChild.nodeValue)
 
425
                        for rule in cssRules:
 
426
                                for propname in rule['properties']:
 
427
                                        propval = rule['properties'][propname]
 
428
                                        findReferencingProperty(node, propname, propval, ids)
435
429
                return ids
436
430
        
437
431
        # else if xlink:href is set, then grab the id
2104
2098
                        elif child.nodeType == 3:
2105
2099
                                # trim it only in the case of not being a child of an element
2106
2100
                                # where whitespace might be important
2107
 
                                if element.nodeName in ["text", "tspan", "textPath", "tref", "title", "desc", "textArea", 
2108
 
                                                                                "flowRoot", "flowDiv", "flowSpan", "flowPara", "flowRegion"]:
 
2101
                                if preserveWhitespace:
2109
2102
                                        outString += makeWellFormed(child.nodeValue)
2110
2103
                                else:
2111
2104
                                        outString += makeWellFormed(child.nodeValue.strip())
2375
2368
                _options_parser.error("Can't have negative significant digits, see --help")
2376
2369
        if not options.indent_type in ["tab", "space", "none"]:
2377
2370
                _options_parser.error("Invalid value for --indent, see --help")
 
2371
        if options.infilename and options.outfilename and options.infilename == options.outfilename:
 
2372
                _options_parser.error("Input filename is the same as output filename")
2378
2373
 
2379
2374
        if options.infilename:
2380
2375
                infile = maybe_gziped_file(options.infilename)