How to use the scour.svg_regex.svg_parser.parse function in scour

To help you get started, we’ve selected a few scour examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scour-project / scour / test_scour.py View on Github external
def runTest(self):
        doc = scourXmlFile('unittests/path-line-optimize.svg')
        path = svg_parser.parse(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d'))
        self.assertEqual(path[2][0], 'v',
                         'Did not change line to vertical line segment in path')
        self.assertEqual(float(path[2][1][0]), 100.0,
                         'Did not calculate vertical line segment in path correctly')
github scour-project / scour / test_scour.py View on Github external
def runTest(self):
        doc = scourXmlFile('unittests/path-with-caps.svg', parse_args(['--disable-style-to-xml']))
        for id in ['none', 'attr_butt', 'style_butt']:
            path = svg_parser.parse(doc.getElementById(id).getAttribute('d'))
            self.assertEqual(len(path), 1,
                             'Did not remove empty segments when path had butt linecaps')
github scour-project / scour / test_scour.py View on Github external
def runTest(self):
        doc = scourXmlFile('unittests/path-with-caps.svg', parse_args(['--disable-style-to-xml']))
        for id in ['attr_round', 'attr_square', 'style_round', 'style_square']:
            path = svg_parser.parse(doc.getElementById(id).getAttribute('d'))
            self.assertEqual(len(path), 2,
                             'Did remove empty segments when path had round or square linecaps')
github scour-project / scour / scour / scour.py View on Github external
def cleanPath(element, options) :
   """
      Cleans the path string (d attribute) of the element
   """
   global numBytesSavedInPathData
   global numPathSegmentsReduced
   global numCurvesStraightened

   # this gets the parser object from svg_regex.py
   oldPathStr = element.getAttribute('d')
   path = svg_parser.parse(oldPathStr)

   # This determines whether the stroke has round linecaps.  If it does,
   # we do not want to collapse empty segments, as they are actually rendered.
   withRoundLineCaps = element.getAttribute('stroke-linecap') == 'round'

   # The first command must be a moveto, and whether it's relative (m)
   # or absolute (M), the first set of coordinates *is* absolute. So
   # the first iteration of the loop below will get x,y and startx,starty.

   # convert absolute coordinates into relative ones.
   # Reuse the data structure 'path', since we're not adding or removing subcommands.
   # Also reuse the coordinate lists since we're not adding or removing any.
   for pathIndex in range(0, len(path)):
      cmd, data = path[pathIndex] # Changes to cmd don't get through to the data structure
      i = 0
      # adjust abs to rel