StyleRegistry

Struct StyleRegistry 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

Source

pub fn from_template(template: &Template) -> BlueprintResult<Self>

Creates a StyleRegistry from a Template.

This is the final resolution step:

  1. Iterate over template styles (in order)
  2. Resolve each PartialStyle → CharShape + ParaShape
  3. Deduplicate fonts
  4. Allocate sequential indices
§Errors
§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, "한컴바탕");
Source

pub fn get_style(&self, name: &str) -> Option<&StyleEntry>

Looks up a style by name.

Returns None if the style name does not exist.

Source

pub fn char_shape(&self, idx: CharShapeIndex) -> Option<&CharShape>

Retrieves a character shape by index.

Returns None if the index is out of bounds.

Source

pub fn para_shape(&self, idx: ParaShapeIndex) -> Option<&ParaShape>

Retrieves a paragraph shape by index.

Returns None if the index is out of bounds.

Source

pub fn font(&self, idx: FontIndex) -> Option<&FontId>

Retrieves a font by index.

Returns None if the index is out of bounds.

Source

pub fn font_count(&self) -> usize

Returns the number of unique fonts.

Source

pub fn char_shape_count(&self) -> usize

Returns the number of character shapes.

Source

pub fn para_shape_count(&self) -> usize

Returns the number of paragraph shapes.

Source

pub fn style_count(&self) -> usize

Returns the number of named styles.

Trait Implementations§

Source§

impl Clone for StyleRegistry

Source§

fn clone(&self) -> StyleRegistry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StyleRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for StyleRegistry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for StyleRegistry

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for StyleRegistry

Source§

fn eq(&self, other: &StyleRegistry) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for StyleRegistry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for StyleRegistry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,