pub struct Fragment {
pub root: NodeId,
pub nodes: Vec<LayoutNode>,
pub source_map: SourceMap,
pub metadata: FragmentMetadata,
pub surface: Surface,
}Expand description
One typeset fragment: a tree of layout nodes rooted at root, stored densely by id.
Fields§
§root: NodeIdThe root node, placed at (0, 0) with its reference point on the surface baseline.
nodes: Vec<LayoutNode>Every node of the tree, nodes[i].id == NodeId(i).
source_map: SourceMapSource files and enclosing construct spans.
metadata: FragmentMetadataHow the fragment was produced.
surface: SurfaceExtent of the root box, surface.baseline == root.height.
Implementations§
Source§impl Fragment
impl Fragment
Sourcepub fn new(
root: NodeId,
nodes: Vec<LayoutNode>,
source_map: SourceMap,
metadata: FragmentMetadata,
) -> Result<Self, FragmentError>
pub fn new( root: NodeId, nodes: Vec<LayoutNode>, source_map: SourceMap, metadata: FragmentMetadata, ) -> Result<Self, FragmentError>
Builds a fragment, deriving the surface from the root and checking every invariant.
Sourcepub fn validate(&self) -> Result<(), FragmentError>
pub fn validate(&self) -> Result<(), FragmentError>
Checks dense ids, a single tree under the root, the root placement, the surface and source ids.
Sourcepub fn node(&self, id: NodeId) -> Option<&LayoutNode>
pub fn node(&self, id: NodeId) -> Option<&LayoutNode>
Returns the node with the given id in constant time.
Sourcepub fn root_node(&self) -> Option<&LayoutNode>
pub fn root_node(&self) -> Option<&LayoutNode>
Returns the root node, None for an empty fragment.
Sourcepub fn children(&self, id: NodeId) -> &[NodeId]
pub fn children(&self, id: NodeId) -> &[NodeId]
Returns the children of a node, empty for leaves and unknown ids.
Sourcepub fn source_entries_for_node(
&self,
node: NodeId,
) -> impl Iterator<Item = &SourceMapEntry>
pub fn source_entries_for_node( &self, node: NodeId, ) -> impl Iterator<Item = &SourceMapEntry>
Iterates the enclosing construct entries of a node, innermost first.
Sourcepub fn source_origins_for_node(
&self,
node: NodeId,
) -> impl Iterator<Item = SourceOrigin<'_>>
pub fn source_origins_for_node( &self, node: NodeId, ) -> impl Iterator<Item = SourceOrigin<'_>>
Iterates the node’s primary origin followed by its enclosing construct origins.
Sourcepub fn primary_source_for_node(&self, node: NodeId) -> Option<SourceRange>
pub fn primary_source_for_node(&self, node: NodeId) -> Option<SourceRange>
Returns the primary source range of a node.
Sourcepub fn glyph_source_range(
&self,
node: NodeId,
glyph_index: usize,
) -> Option<SourceRange>
pub fn glyph_source_range( &self, node: NodeId, glyph_index: usize, ) -> Option<SourceRange>
Resolves a glyph’s cluster span to a range in the node’s primary source file.
Sourcepub fn glyph_source_origin(
&self,
node: NodeId,
glyph_index: usize,
) -> Option<SourceOrigin<'_>>
pub fn glyph_source_origin( &self, node: NodeId, glyph_index: usize, ) -> Option<SourceOrigin<'_>>
Resolves a glyph’s cluster span to a full source origin.