Add custom metadata to Attrs, copied to ShapeGlyph and LayoutGlyph
This commit is contained in:
parent
cdf36db03d
commit
8bf0032974
3 changed files with 19 additions and 8 deletions
11
src/attrs.rs
11
src/attrs.rs
|
|
@ -101,6 +101,7 @@ pub struct Attrs<'a> {
|
||||||
pub stretch: Stretch,
|
pub stretch: Stretch,
|
||||||
pub style: Style,
|
pub style: Style,
|
||||||
pub weight: Weight,
|
pub weight: Weight,
|
||||||
|
pub metadata: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Attrs<'a> {
|
impl<'a> Attrs<'a> {
|
||||||
|
|
@ -115,6 +116,7 @@ impl<'a> Attrs<'a> {
|
||||||
stretch: Stretch::Normal,
|
stretch: Stretch::Normal,
|
||||||
style: Style::Normal,
|
style: Style::Normal,
|
||||||
weight: Weight::NORMAL,
|
weight: Weight::NORMAL,
|
||||||
|
metadata: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,6 +156,12 @@ impl<'a> Attrs<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set metadata
|
||||||
|
pub fn metadata(mut self, metadata: usize) -> Self {
|
||||||
|
self.metadata = metadata;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if font matches
|
/// Check if font matches
|
||||||
pub fn matches(&self, face: &fontdb::FaceInfo) -> bool {
|
pub fn matches(&self, face: &fontdb::FaceInfo) -> bool {
|
||||||
//TODO: smarter way of including emoji
|
//TODO: smarter way of including emoji
|
||||||
|
|
@ -185,6 +193,7 @@ pub struct AttrsOwned {
|
||||||
pub stretch: Stretch,
|
pub stretch: Stretch,
|
||||||
pub style: Style,
|
pub style: Style,
|
||||||
pub weight: Weight,
|
pub weight: Weight,
|
||||||
|
pub metadata: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AttrsOwned {
|
impl AttrsOwned {
|
||||||
|
|
@ -196,6 +205,7 @@ impl AttrsOwned {
|
||||||
stretch: attrs.stretch,
|
stretch: attrs.stretch,
|
||||||
style: attrs.style,
|
style: attrs.style,
|
||||||
weight: attrs.weight,
|
weight: attrs.weight,
|
||||||
|
metadata: attrs.metadata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,6 +217,7 @@ impl AttrsOwned {
|
||||||
stretch: self.stretch,
|
stretch: self.stretch,
|
||||||
style: self.style,
|
style: self.style,
|
||||||
weight: self.weight,
|
weight: self.weight,
|
||||||
|
metadata: self.metadata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ pub struct LayoutGlyph {
|
||||||
pub y_int: i32,
|
pub y_int: i32,
|
||||||
/// Optional color override
|
/// Optional color override
|
||||||
pub color_opt: Option<Color>,
|
pub color_opt: Option<Color>,
|
||||||
|
/// Metadata from `Attrs`
|
||||||
|
pub metadata: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A line of laid out glyphs
|
/// A line of laid out glyphs
|
||||||
|
|
|
||||||
14
src/shape.rs
14
src/shape.rs
|
|
@ -52,6 +52,7 @@ fn shape_fallback(
|
||||||
missing.push(start_glyph);
|
missing.push(start_glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let attrs = attrs_list.get_span(start_glyph);
|
||||||
glyphs.push(ShapeGlyph {
|
glyphs.push(ShapeGlyph {
|
||||||
start: start_glyph,
|
start: start_glyph,
|
||||||
end: end_run, // Set later
|
end: end_run, // Set later
|
||||||
|
|
@ -61,7 +62,9 @@ fn shape_fallback(
|
||||||
y_offset,
|
y_offset,
|
||||||
font_id: font.info.id,
|
font_id: font.info.id,
|
||||||
glyph_id: info.glyph_id.try_into().expect("failed to cast glyph 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)
|
(glyphs, missing)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,6 +240,7 @@ pub struct ShapeGlyph {
|
||||||
pub font_id: fontdb::ID,
|
pub font_id: fontdb::ID,
|
||||||
pub glyph_id: u16,
|
pub glyph_id: u16,
|
||||||
pub color_opt: Option<Color>,
|
pub color_opt: Option<Color>,
|
||||||
|
pub metadata: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeGlyph {
|
impl ShapeGlyph {
|
||||||
|
|
@ -268,6 +265,7 @@ impl ShapeGlyph {
|
||||||
x_int,
|
x_int,
|
||||||
y_int,
|
y_int,
|
||||||
color_opt: self.color_opt,
|
color_opt: self.color_opt,
|
||||||
|
metadata: self.metadata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue