Documents and Elements¶
A novasvg.Document is loaded from a file or from a string, can be queried
with CSS selectors, styled with a stylesheet and rendered. Its tree is made of
novasvg.Element and novasvg.TextNode objects, both of which derive
from novasvg.Node.
import novasvg
doc = novasvg.Document.load_from_file("artwork.svg")
for rect in doc.query_selector_all("rect"):
print(rect)
Reference¶
- class Document¶
- apply_stylesheet(self, content: str) None¶
Apply a CSS stylesheet to the document.
- bounding_box(self) novasvg.Box¶
Get the bounding box of the document content.
- document_element(self) novasvg.Element¶
Get the root element of the document.
- element_from_point(self, x: float, y: float) novasvg.Element¶
Get the topmost element at a specific point.
- force_layout(self) None¶
Force an immediate layout update.
- get_element_by_id(self, id: str) novasvg.Element¶
Get an element by its ID.
- query_selector_all(self, content: str) list[novasvg.Element]¶
Select elements matching a CSS selector.
- render(self, bitmap: novasvg.Bitmap, matrix: novasvg.Matrix = <novasvg.Matrix object at 0x7f9bd1970b40>) None¶
Render the document onto a bitmap.
- render_to_bitmap(self, width: int = -1, height: int = -1, backgroundColor: novasvg.Color = <novasvg.Color object at 0x7f9bd1ad1790>) novasvg.Bitmap¶
- render_to_bitmap(self, width: int = -1, height: int = -1, backgroundColor: int = 0) novasvg.Bitmap
Overloaded function.
render_to_bitmap(self, width: int = -1, height: int = -1, backgroundColor: novasvg.Color = <novasvg.Color object at 0x7f9bd1ad1790>) -> novasvg.Bitmap
Render the document to a new Bitmap.
render_to_bitmap(self, width: int = -1, height: int = -1, backgroundColor: int = 0) -> novasvg.Bitmap
Render the document using a packed 0xRRGGBBAA background color.
- update_layout(self) None¶
Update the layout of the document if needed.
- property height¶
Get the intrinsic height of the document.
- load_from_data = <nanobind.nb_func object>¶
- load_from_file = <nanobind.nb_func object>¶
- property width¶
Get the intrinsic width of the document.
- class Element(*args, **kwargs)¶
- children(self) list[novasvg.Node]¶
Get child nodes.
- get_attribute(self, name: str) str¶
Get an attribute value.
- get_bounding_box(self) novasvg.Box¶
Get the bounding box without transformations.
- get_global_bounding_box(self) novasvg.Box¶
Get the global bounding box.
- get_global_matrix(self) novasvg.Matrix¶
Get the global transformation matrix.
- get_local_bounding_box(self) novasvg.Box¶
Get the local bounding box.
- get_local_matrix(self) novasvg.Matrix¶
Get the local transformation matrix.
- has_attribute(self, name: str) bool¶
Check if an attribute exists.
- render(self, bitmap: novasvg.Bitmap, matrix: novasvg.Matrix = <novasvg.Matrix object at 0x7f9bd1970780>) None¶
Render the element onto a bitmap.
- render_to_bitmap(self, width: int = -1, height: int = -1, backgroundColor: novasvg.Color = <novasvg.Color object at 0x7f9bd1ad14f0>) novasvg.Bitmap¶
- render_to_bitmap(self, width: int = -1, height: int = -1, backgroundColor: int = 0) novasvg.Bitmap
Overloaded function.
render_to_bitmap(self, width: int = -1, height: int = -1, backgroundColor: novasvg.Color = <novasvg.Color object at 0x7f9bd1ad14f0>) -> novasvg.Bitmap
Render the element to a new Bitmap.
render_to_bitmap(self, width: int = -1, height: int = -1, backgroundColor: int = 0) -> novasvg.Bitmap
Render the element using a packed 0xRRGGBBAA background color.
- set_attribute(self, name: str, value: str) None¶
Set an attribute value.
- class Node¶
- is_element(self) bool¶
Check if the node is an element node.
- is_null(self) bool¶
Check if the node is null.
- is_text_node(self) bool¶
Check if the node is a text node.
- parent_element(self) novasvg.Element¶
Get the parent element.
- to_element(self) novasvg.Element¶
Convert the node to an Element.
- to_text_node(self) novasvg.TextNode¶
Convert the node to a TextNode.