Package bar :: Module svgpathparse
[hide private]
[frames] | no frames]

Module svgpathparse

Extracted from: simplepath.py functions for digesting paths into a simple list structure

Copyright (C) 2005 Aaron Spike, aaron@ekips.org

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

http://www.ekips.org/comp/inkscape/parsepath.php ekips path parsing code

Import Graph
Import Graph

Functions [hide private]
 
lexPath(d)
returns and iterator that breaks path data identifies command and parameter tokens
 
parsePath(d)
Parse SVG path and return an array of segments.
 
UnparsePath(PathParsePath)
Creates string from svgpathparse.parsePath function output.
 
chunks(l, n)
Returns: list l splited into chunks of length l
 
extractBoundingBox(pathString)
Returns: tuple of four integers: (x1,y1,x2,y2)
 
mergeBoundingBox(bbox1, bbox2)
 
_mergeBoundingBox(bboxes)
 
parseStyle(s)
Create a dictionary from the value of an inline style attribute
 
formatStyle(a)
Format an inline style attribute from a dictionary
 
modifyContour(pathElement, modifications)
Function modifies path element by modyfying colour and stroke.
Variables [hide private]
  pathdefs = {'A': ['A', 7, [<type 'float'>, <type 'float'>, <ty...
  __package__ = 'bar'
Function Details [hide private]

parsePath(d)

 

Parse SVG path and return an array of segments. Removes all shorthand notation. Converts coordinates to absolute.

UnparsePath(PathParsePath)

 

Creates string from svgpathparse.parsePath function output. This step is performed in order to generate d attribute value compatibile with existing syntax.

Parameters:
  • PathParsePath (list) - List of path segments parsed by svgpathparse.parsePath which needs to be converted to string.
Returns:
d attrubute value of given path element.

chunks(l, n)

 
Parameters:
  • l (list (or other iterable)) - list that will be splited into chunks
  • n (int) - length of single chunk
Returns:
list l splited into chunks of length l

Splits given list into chunks. Length of the list has to be multiple of chunk or exception will be raised.

extractBoundingBox(pathString)

 
Parameters:
  • pathString (string) - path definition according to SVG 1.1 specification
Returns:
tuple of four integers: (x1,y1,x2,y2)

Where x1,y2 are coordinates of top-left corner of bounding box and x2,y2 are coordinates of bottom-right corner of bounding box.

Please note that bounding box is only approximation of actual bounding box and may be slightly larger as it is based on extreme coordinated of control points creating given path. However, the difference is neglectable.

Examples:

>>> print extractBoundingBox("M100,100 L200,200 C300,300 300,100 100,100 Z")
(100, 100, 300, 300)

mergeBoundingBox(bbox1, bbox2)

 
Parameters:
  • bbox1 (tuple of four integers: (x1,y1,x2,y2)) - definition of first bounding box
  • bbox2 (tuple of four integers: (x1,y1,x2,y2)) - definition of second bounding box

Note: mergeBoundingBox(bbx1, bbx2) = mergeBoundingBox(bbx2, bbx1)

parseStyle(s)

 

Create a dictionary from the value of an inline style attribute

Copyright (C) 2005 Aaron Spike, aaron@ekips.org

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

formatStyle(a)

 

Format an inline style attribute from a dictionary

Copyright (C) 2005 Aaron Spike, aaron@ekips.org

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

modifyContour(pathElement, modifications)

 

Function modifies path element by modyfying colour and stroke. modifications['newStrokeWidth'] determines new stroke width while modifications['newStrokeColour'] determined new stroke colour. Width has to be provided as float whie colour usign colour string '#xxxxxx'.

Parameters:
  • pathElement (DOM XML element) - Path element that will be modified
  • modifications (dictionary) - Dictionary holding new stroke width and new stroke colour.

Variables Details [hide private]

pathdefs

Value:
{'A': ['A',
       7,
       [<type 'float'>,
        <type 'float'>,
        <type 'float'>,
        <type 'int'>,
        <type 'int'>,
        <type 'float'>,
...