inkex.properties module#
Property management and parsing, CSS cascading, default value storage
New in version 1.2.
- inkex.properties.all_properties#
A list of all properties, their parser class, and additional information such as whether they are inheritable or can be given as presentation attributes
- inkex.properties._strip_whitespace_nodes(value: List[tinycss2.ast.Node]) List[tinycss2.ast.Node] [source]#
- class inkex.properties._StyleConverter[source]#
Bases:
object
Converter between str and computed value of a style, with context element
- convert(value: TokenList, element: Optional[BaseElement] = None) object [source]#
Get parsed property value with resolved urls, color, etc.
- Parameters
element (BaseElement) – the SVG element to which this style is applied to currently used for resolving gradients / masks, could be used for computing percentage attributes or calc() attributes [optional]
- Returns
parsed property value
- Return type
object
- raise_invalid_value(value: TokenList, element: Optional[BaseElement] = None) None [source]#
Checks if the value str is valid in the context of element.
- Parameters
value (str) – attribute value
element (Optional[BaseElement], optional) – Context element. Defaults to None.
- Raises
various exceptions if the property has a bad value –
- convert_back(value: object, element: Optional[BaseElement] = None) TokenList [source]#
Converts value back to string in the context of element.
- Parameters
value (object) – parsed value of attribute
element (_type_, optional) – Context element. Defaults to None.
- Returns
_description_
- Return type
str
- class inkex.properties._AlphaValueConverter[source]#
Bases:
inkex.properties._StyleConverter
Stores an alpha value (such as opacity), which may be specified as as percentage or absolute value.
Reference: https://www.w3.org/TR/css-color/#typedef-alpha-value
- convert(value: TokenList, element: Optional[BaseElement] = None) object [source]#
Get parsed property value with resolved urls, color, etc.
- Parameters
element (BaseElement) – the SVG element to which this style is applied to currently used for resolving gradients / masks, could be used for computing percentage attributes or calc() attributes [optional]
- Returns
parsed property value
- Return type
object
- convert_back(value: object, element: Optional[BaseElement] = None) TokenList [source]#
Converts value back to string in the context of element.
- Parameters
value (object) – parsed value of attribute
element (_type_, optional) – Context element. Defaults to None.
- Returns
_description_
- Return type
str
- class inkex.properties._ColorValueConverter[source]#
Bases:
inkex.properties._StyleConverter
Converts a color value
Reference: https://drafts.csswg.org/css-color-3/#valuea-def-color
- convert(value: TokenList, element: Optional[BaseElement] = None) object [source]#
Get parsed property value with resolved urls, color, etc.
- Parameters
element (BaseElement) – the SVG element to which this style is applied to currently used for resolving gradients / masks, could be used for computing percentage attributes or calc() attributes [optional]
- Returns
parsed property value
- Return type
object
- class inkex.properties._URLNoneValueConverter[source]#
Bases:
inkex.properties._StyleConverter
Converts a value that is either none or an url, such as markers or masks.
Reference: https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties
- convert(value: TokenList, element: Optional[BaseElement] = None) object [source]#
Get parsed property value with resolved urls, color, etc.
- Parameters
element (BaseElement) – the SVG element to which this style is applied to currently used for resolving gradients / masks, could be used for computing percentage attributes or calc() attributes [optional]
- Returns
parsed property value
- Return type
object
- convert_back(value: object, element: Optional[BaseElement] = None) TokenList [source]#
Converts value back to string in the context of element.
- Parameters
value (object) – parsed value of attribute
element (_type_, optional) – Context element. Defaults to None.
- Returns
_description_
- Return type
str
- static _insert_if_necessary(element: BaseElement, value: BaseElement) BaseElement [source]#
Ensures that the return (value or a deep copy of it) is inside the same document as element.
if element is unrooted, don’t do anything (just return value) If element is attached to the same document as value, return value. If value is not attached to a document, attach it to the defs of element’s document and return value. If value is already attached to another document, create a copy and return the copy.
New in version 1.4.
- class inkex.properties._PaintValueConverter[source]#
Bases:
inkex.properties._ColorValueConverter
,inkex.properties._URLNoneValueConverter
Stores a paint value (such as fill and stroke), which may be specified as color, or url.
Reference: https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint
- convert(value: TokenList, element: Optional[BaseElement] = None) object [source]#
Get parsed property value with resolved urls, color, etc.
- Parameters
element (BaseElement) – the SVG element to which this style is applied to currently used for resolving gradients / masks, could be used for computing percentage attributes or calc() attributes [optional]
- Returns
parsed property value
- Return type
object
- convert_back(value: object, element: Optional[BaseElement] = None) TokenList [source]#
Converts value back to string in the context of element.
- Parameters
value (object) – parsed value of attribute
element (_type_, optional) – Context element. Defaults to None.
- Returns
_description_
- Return type
str
- class inkex.properties._EnumValueConverter(options)[source]#
Bases:
inkex.properties._StyleConverter
Stores a value that can only have a finite set of options
- raise_invalid_value(value: TokenList, element: BaseElement | None = None) None [source]#
Checks if the value str is valid in the context of element.
- Parameters
value (str) – attribute value
element (Optional[BaseElement], optional) – Context element. Defaults to None.
- Raises
various exceptions if the property has a bad value –
- class inkex.properties._ShorthandValueConverter(keys)[source]#
Bases:
inkex.properties._StyleConverter
Stores a value that sets other values (e.g. the font shorthand)
- class inkex.properties._FontValueShorthandConverter[source]#
Bases:
inkex.properties._ShorthandValueConverter
Logic for the shorthand font property
- class inkex.properties._TextDecorationValueConverter[source]#
Bases:
inkex.properties._ShorthandValueConverter
Logic for the shorthand font property
New in version 1.3.
- class inkex.properties._MarkerShorthandValueConverter[source]#
Bases:
inkex.properties._ShorthandValueConverter
,inkex.properties._URLNoneValueConverter
Logic for the marker shorthand property
- get_shorthand_changes(value)[source]#
calculates the value of affected attributes for this shorthand
- Returns
a dictionary containing the new values of the affected attributes
- Return type
Dict[str, str]
- convert_back(value: object, element: Optional[BaseElement] = None) TokenList [source]#
Convert value back to a tokenlist
- class inkex.properties._FontSizeValueConverter[source]#
Bases:
inkex.properties._StyleConverter
Logic for the font-size property
- convert(value: TokenList, element: Optional[BaseElement] = None) object [source]#
Get parsed property value with resolved urls, color, etc.
- Parameters
element (BaseElement) – the SVG element to which this style is applied to currently used for resolving gradients / masks, could be used for computing percentage attributes or calc() attributes [optional]
- Returns
parsed property value
- Return type
object
- class inkex.properties._StrokeDasharrayValueConverter[source]#
Bases:
inkex.properties._StyleConverter
Logic for the stroke-dasharray property
- convert(value: TokenList, element: Optional[BaseElement] = None) object [source]#
Get parsed property value with resolved urls, color, etc.
- Parameters
element (BaseElement) – the SVG element to which this style is applied to currently used for resolving gradients / masks, could be used for computing percentage attributes or calc() attributes [optional]
- Returns
parsed property value
- Return type
object
- convert_back(value: object, element: Optional[BaseElement] = None) TokenList [source]#
Converts value back to string in the context of element.
- Parameters
value (object) – parsed value of attribute
element (_type_, optional) – Context element. Defaults to None.
- Returns
_description_
- Return type
str
- class inkex.properties._FilterListConverter[source]#
Bases:
inkex.properties._URLNoneValueConverter
Stores a list of Filters
New in version 1.4.
- convert(value: TokenList, element: Optional[BaseElement] = None) object [source]#
Get parsed property value with resolved urls, color, etc.
- Parameters
element (BaseElement) – the SVG element to which this style is applied to currently used for resolving gradients / masks, could be used for computing percentage attributes or calc() attributes [optional]
- Returns
parsed property value
- Return type
object
- convert_back(value: object, element: Optional[BaseElement] = None) TokenList [source]#
Converts value back to string in the context of element.
- Parameters
value (object) – parsed value of attribute
element (_type_, optional) – Context element. Defaults to None.
- Returns
_description_
- Return type
str
- class inkex.properties.PropertyDescription(name: str, converter: inkex.properties._StyleConverter, default_value: str, presentation: bool = False, inherited: bool = False)[source]#
Bases:
object
Describes a CSS / presentation attribute
- presentation: bool#
- inherited: bool#
- default_value: List[tinycss2.ast.Node]#
- name: str#
- converter: inkex.properties._StyleConverter#