diff --git a/src/attrs.rs b/src/attrs.rs index b10c4d8..550f947 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -101,6 +101,7 @@ pub struct Attrs<'a> { pub stretch: Stretch, pub style: Style, pub weight: Weight, + pub metadata: usize, } impl<'a> Attrs<'a> { @@ -115,6 +116,7 @@ impl<'a> Attrs<'a> { stretch: Stretch::Normal, style: Style::Normal, weight: Weight::NORMAL, + metadata: 0, } } @@ -154,6 +156,12 @@ impl<'a> Attrs<'a> { self } + /// Set metadata + pub fn metadata(mut self, metadata: usize) -> Self { + self.metadata = metadata; + self + } + /// Check if font matches pub fn matches(&self, face: &fontdb::FaceInfo) -> bool { //TODO: smarter way of including emoji @@ -185,6 +193,7 @@ pub struct AttrsOwned { pub stretch: Stretch, pub style: Style, pub weight: Weight, + pub metadata: usize, } impl AttrsOwned { @@ -196,6 +205,7 @@ impl AttrsOwned { stretch: attrs.stretch, style: attrs.style, weight: attrs.weight, + metadata: attrs.metadata, } } @@ -207,6 +217,7 @@ impl AttrsOwned { stretch: self.stretch, style: self.style, weight: self.weight, + metadata: self.metadata, } } } diff --git a/src/layout.rs b/src/layout.rs index 2bc1b1b..d3e75ba 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -26,6 +26,8 @@ pub struct LayoutGlyph { pub y_int: i32, /// Optional color override pub color_opt: Option, + /// Metadata from `Attrs` + pub metadata: usize, } /// A line of laid out glyphs diff --git a/src/shape.rs b/src/shape.rs index cbe05a7..cf19111 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -52,6 +52,7 @@ fn shape_fallback( missing.push(start_glyph); } + let attrs = attrs_list.get_span(start_glyph); glyphs.push(ShapeGlyph { start: start_glyph, end: end_run, // Set later @@ -61,7 +62,9 @@ fn shape_fallback( y_offset, font_id: font.info.id, glyph_id: info.glyph_id.try_into().expect("failed to cast glyph ID"), - color_opt: None, + //TODO: color should not be related to shaping + color_opt: attrs.color_opt, + metadata: attrs.metadata, }); } @@ -90,13 +93,6 @@ fn shape_fallback( } } - // Set color - //TODO: these attributes should not be related to shaping - for glyph in &mut glyphs { - let attrs = attrs_list.get_span(glyph.start); - glyph.color_opt = attrs.color_opt; - } - (glyphs, missing) } @@ -244,6 +240,7 @@ pub struct ShapeGlyph { pub font_id: fontdb::ID, pub glyph_id: u16, pub color_opt: Option, + pub metadata: usize, } impl ShapeGlyph { @@ -268,6 +265,7 @@ impl ShapeGlyph { x_int, y_int, color_opt: self.color_opt, + metadata: self.metadata, } } }