#[non_exhaustive]pub struct StyleRegistry {
pub fonts: Vec<FontId>,
pub char_shapes: Vec<CharShape>,
pub para_shapes: Vec<ParaShape>,
pub style_entries: IndexMap<String, StyleEntry>,
}Expand description
A registry of resolved styles with index-based access.
After inheritance resolution, the Template is converted into a StyleRegistry where every style is assigned numeric indices for efficient lookup during document rendering.
§Font Deduplication
Multiple styles can reference the same font. The registry deduplicates fonts automatically:
// Two styles with the same font → single FontIndex
styles:
body: { font: "Batang", size: 10pt }
heading: { font: "Batang", size: 16pt }
// Registry: fonts = ["Batang"] (index 0)
// char_shapes[0].font_id = FontIndex(0)
// char_shapes[1].font_id = FontIndex(0)§Index Allocation
Indices are allocated sequentially in the order styles appear in the template (preserving YAML field order via IndexMap):
- CharShape 0, CharShape 1, CharShape 2…
- ParaShape 0, ParaShape 1, ParaShape 2…
- Font 0, Font 1… (deduplicated)
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.fonts: Vec<FontId>All unique fonts referenced by character shapes.
char_shapes: Vec<CharShape>All resolved character shapes.
para_shapes: Vec<ParaShape>All resolved paragraph shapes.
style_entries: IndexMap<String, StyleEntry>Mapping from style name to its indices (insertion-order preserved).
Implementations§
Source§impl StyleRegistry
impl StyleRegistry
Sourcepub fn from_template(template: &Template) -> BlueprintResult<Self>
pub fn from_template(template: &Template) -> BlueprintResult<Self>
Creates a StyleRegistry from a Template.
This is the final resolution step:
- Iterate over template styles (in order)
- Resolve each PartialStyle → CharShape + ParaShape
- Deduplicate fonts
- Allocate sequential indices
§Errors
BlueprintError::EmptyStyleMapif the template has no stylesBlueprintError::StyleResolutionif any style is missing required fields
§Examples
use hwpforge_blueprint::{Template, StyleRegistry};
let template = Template::from_yaml(yaml)?;
let registry = StyleRegistry::from_template(&template)?;
// Access by name
let body_entry = registry.get_style("body").unwrap();
let char_shape = registry.char_shape(body_entry.char_shape_id).unwrap();
assert_eq!(char_shape.font, "한컴바탕");Sourcepub fn get_style(&self, name: &str) -> Option<&StyleEntry>
pub fn get_style(&self, name: &str) -> Option<&StyleEntry>
Looks up a style by name.
Returns None if the style name does not exist.
Sourcepub fn char_shape(&self, idx: CharShapeIndex) -> Option<&CharShape>
pub fn char_shape(&self, idx: CharShapeIndex) -> Option<&CharShape>
Retrieves a character shape by index.
Returns None if the index is out of bounds.
Sourcepub fn para_shape(&self, idx: ParaShapeIndex) -> Option<&ParaShape>
pub fn para_shape(&self, idx: ParaShapeIndex) -> Option<&ParaShape>
Retrieves a paragraph shape by index.
Returns None if the index is out of bounds.
Sourcepub fn font(&self, idx: FontIndex) -> Option<&FontId>
pub fn font(&self, idx: FontIndex) -> Option<&FontId>
Retrieves a font by index.
Returns None if the index is out of bounds.
Sourcepub fn font_count(&self) -> usize
pub fn font_count(&self) -> usize
Returns the number of unique fonts.
Sourcepub fn char_shape_count(&self) -> usize
pub fn char_shape_count(&self) -> usize
Returns the number of character shapes.
Sourcepub fn para_shape_count(&self) -> usize
pub fn para_shape_count(&self) -> usize
Returns the number of paragraph shapes.
Sourcepub fn style_count(&self) -> usize
pub fn style_count(&self) -> usize
Returns the number of named styles.
Trait Implementations§
Source§impl Clone for StyleRegistry
impl Clone for StyleRegistry
Source§fn clone(&self) -> StyleRegistry
fn clone(&self) -> StyleRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StyleRegistry
impl Debug for StyleRegistry
Source§impl<'de> Deserialize<'de> for StyleRegistry
impl<'de> Deserialize<'de> for StyleRegistry
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for StyleRegistry
impl JsonSchema for StyleRegistry
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more