Struct rsvg::document::DocumentBuilder
source · pub struct DocumentBuilder {
session: Session,
load_options: Arc<LoadOptions>,
tree: Option<Node<NodeData>>,
ids: HashMap<String, Node<NodeData>>,
stylesheets: Vec<Stylesheet>,
}
Expand description
Used to build a tree of SVG nodes while an XML document is being read.
This struct holds the document-related state while loading an SVG document from XML: the loading options, the partially-built tree of nodes, the CSS stylesheets that appear while loading the document.
The XML loader asks a DocumentBuilder
to
append_element
,
append_characters
, etc. When all the XML has
been consumed, the caller can use build
to get a
fully-loaded Document
.
Fields§
§session: Session
Metadata for the document’s lifetime.
load_options: Arc<LoadOptions>
Loading options; mainly the URL resolver.
tree: Option<Node<NodeData>>
Root node of the tree.
ids: HashMap<String, Node<NodeData>>
Mapping from id
attributes to nodes.
stylesheets: Vec<Stylesheet>
Stylesheets defined in the document.
Implementations§
source§impl DocumentBuilder
impl DocumentBuilder
pub fn new(session: Session, load_options: Arc<LoadOptions>) -> DocumentBuilder
sourcepub fn append_stylesheet(&mut self, stylesheet: Stylesheet)
pub fn append_stylesheet(&mut self, stylesheet: Stylesheet)
Adds a stylesheet in order to the document.
Stylesheets will later be matched in the order in which they were added.
sourcepub fn append_element(
&mut self,
name: &QualName,
attrs: Attributes,
parent: Option<Node<NodeData>>
) -> Node<NodeData>
pub fn append_element( &mut self, name: &QualName, attrs: Attributes, parent: Option<Node<NodeData>> ) -> Node<NodeData>
Creates an element of the specified name
as a child of parent
.
This is the main function to create new SVG elements while parsing XML.
name
is the XML element’s name, for example rect
.
attrs
has the XML element’s attributes, e.g. cx/cy/r for <circle cx="0" cy="0" r="5">
.
If parent
is None
it means that we are creating the root node in the tree of
elements. The code will later validate that this is indeed an <svg>
element.
sourcepub fn append_characters(&mut self, text: &str, parent: &mut Node<NodeData>)
pub fn append_characters(&mut self, text: &str, parent: &mut Node<NodeData>)
Creates a node for an XML text element as a child of parent
.
sourcepub fn build(self) -> Result<Document, LoadingError>
pub fn build(self) -> Result<Document, LoadingError>
Does the final validation on the Document
being read, and returns it.
Auto Trait Implementations§
impl !RefUnwindSafe for DocumentBuilder
impl !Send for DocumentBuilder
impl !Sync for DocumentBuilder
impl Unpin for DocumentBuilder
impl !UnwindSafe for DocumentBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.