Add custom metadata to Attrs, copied to ShapeGlyph and LayoutGlyph

This commit is contained in:
Jeremy Soller 2022-12-14 09:19:03 -07:00
parent cdf36db03d
commit 8bf0032974
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
3 changed files with 19 additions and 8 deletions

View file

@ -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,
}
}
}

View file

@ -26,6 +26,8 @@ pub struct LayoutGlyph {
pub y_int: i32,
/// Optional color override
pub color_opt: Option<Color>,
/// Metadata from `Attrs`
pub metadata: usize,
}
/// A line of laid out glyphs

View file

@ -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<Color>,
pub metadata: usize,
}
impl ShapeGlyph {
@ -268,6 +265,7 @@ impl ShapeGlyph {
x_int,
y_int,
color_opt: self.color_opt,
metadata: self.metadata,
}
}
}