style¶
Mess around with SVG styling
-
svgis.style.
add_style
(svgfile, style, replace=False)¶ Add to or replace the CSS style in an SVG file.
Parameters: - svgfile (str) – Path to an SVG file or an SVG string.
- newstyle (str) – CSS string, or path to CSS file.
- replace (bool) – If true, replace the existing CSS with newstyle (default: False)
-
svgis.style.
construct_classes
(classes, properties)¶ Build a class string for an element using the properties. Class names take the form CLASS_PROPERTY. If a given class isn’t found in properties, the class name is added (e.g. CLASS).
Parameters: - classes (Sequence) – Column names to include in the class list
- properties (dict) – A single feature’s properties.
Returns: (list) class names
-
svgis.style.
inline
(svg, style=None)¶ Inline the CSS rules in an SVG. This is a very rough operation, and full css precedence rules won’t be respected. Ignores sibling operators (
~
,+
), pseudo-selectors (e.g.:first-child
), and attribute selectors (e.g..foo[name=bar]
). Works best with rules like:.class
tag
tag.class
#layer .class
#layer tag
Parameters: - svg (string) – An SVG document.
- css (string) – CSS to use, instead of the CSS in the <defs> element of the SVG.
-
svgis.style.
pick
(style)¶ Fetch a CSS string.
Parameters: style (str) – Either a CSS string or the path of a css file.
-
svgis.style.
sanitize
(string)¶ Make input safe of use in an svg ID or class field. Replaces blocks of whitespace with an underscore (
_
), deleted periods, number signs and double-quotes (.#"
). If the first character isn’t an ascii letter, dash (-
) or underscore (_
), an underscore is added to the beginning.Parameters: string (mixed) – Input to sanitize Returns: str
Utilities for manipulating the DOM and applying styles to same
-
svgis.dom.
apply_rule
(doc, rule)¶ Apply a tinycss Rule to an ElementTree.Element (only tested on documents created by SVGIS).
Parameters: - doc (ElementTree.Element) – The svg document to scan.
- rule (tinycss rule) – Rule to apply.
-
svgis.dom.
cdata
(content=None)¶ Wrap text in CDATA section.
-
svgis.dom.
ns
(tag)¶ Apply the SVG namespace to a tag, e.g.
g
to{http://www.w3.org/2000/svg}g
.