This is a simple python package for generating svg documents.
It's evolved though use in four projects over the last ten years; most recently I used it in breadboarder which now depends on it as an external package.
I have separated it out as I now have other current projects which use it.
`svg is organized into several modules, each responsible for a specific part of the SVG creation process.
-
svg.py: This module defines several classes that represent different SVG elements, such asRectangle,Line,Text,Circle,Image, andDimple. Each of these classes inherits from eitherSimpleItemorCompositeItem, which in turn inherit fromDrawable.Drawableis an abstract base class that requires its subclasses to implement anelementmethod. This method is responsible for creating an XML element that represents the SVG element. TheCompositeItemclass is used for SVG elements that can contain other elements, likeGroupedDrawable. -
path.py: This module defines thePathclass and severalPathSegmentsubclasses. APathis an SVG element that consists of one or more segments, which can be lines, arcs, etc. EachPathSegmentsubclass implements aspecificationmethod that returns a string representing the SVG path command for that segment. -
point.py: This module defines thePointclass, which represents a point in a 2D space. It provides methods for performing basic vector operations like addition, subtraction, and scaling. -
transform.py: This module defines several classes that represent SVG transformations, likeTranslationandRotation. These classes inherit from theTransformabstract base class, which requires its subclasses to implementtext,as_matrix, andtransformmethods. Thetextmethod returns a string representing the SVG transform command, and thetransformmethod applies the transformation to aPoint.
The code also includes a write function in svg.py that writes a string to a file. This could be used to write the SVG XML to a file.
Overall, this code provides a way to create complex SVG graphics using Python code. The user can create instances of the various SVG element classes, set their properties, and then call their element methods to generate the SVG XML.