mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 12:41:30 +11:00
Address review feedback
* reorganize GlyphCache::get_or_insert() to use the HashMap entry API * change DrawGlyphs::hint() parameter name from `yes` to `hint` for clarity * change Layout::path_data() to return bytes instead of [f32; 2]. Path segments could be encoded as i16, making this incorrect
This commit is contained in:
parent
69dd838d09
commit
86b1a66af0
|
@ -48,21 +48,24 @@ impl GlyphCache {
|
||||||
style: &Style,
|
style: &Style,
|
||||||
scaler: &mut GlyphProvider,
|
scaler: &mut GlyphProvider,
|
||||||
) -> Option<CachedRange> {
|
) -> Option<CachedRange> {
|
||||||
|
let encoding_cache = &mut self.encoding;
|
||||||
|
let mut encode_glyph = || {
|
||||||
|
let start = encoding_cache.stream_offsets();
|
||||||
|
scaler.encode_glyph(key.glyph_id as u16, style, encoding_cache)?;
|
||||||
|
let end = encoding_cache.stream_offsets();
|
||||||
|
Some(CachedRange { start, end })
|
||||||
|
};
|
||||||
// For now, only cache non-zero filled glyphs so we don't need to keep style
|
// For now, only cache non-zero filled glyphs so we don't need to keep style
|
||||||
// as part of the key.
|
// as part of the key.
|
||||||
let is_nz_fill = matches!(style, Style::Fill(Fill::NonZero));
|
let range = if matches!(style, Style::Fill(Fill::NonZero)) {
|
||||||
if is_nz_fill {
|
use std::collections::hash_map::Entry;
|
||||||
if let Some(range) = self.glyphs.get(&key) {
|
match self.glyphs.entry(key) {
|
||||||
return Some(*range);
|
Entry::Occupied(entry) => *entry.get(),
|
||||||
|
Entry::Vacant(entry) => *entry.insert(encode_glyph()?),
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
let start = self.encoding.stream_offsets();
|
encode_glyph()?
|
||||||
scaler.encode_glyph(key.glyph_id as u16, style, &mut self.encoding)?;
|
};
|
||||||
let end = self.encoding.stream_offsets();
|
|
||||||
let range = CachedRange { start, end };
|
|
||||||
if is_nz_fill {
|
|
||||||
self.glyphs.insert(key, range);
|
|
||||||
}
|
|
||||||
Some(range)
|
Some(range)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl Layout {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the path data stream.
|
/// Returns the path data stream.
|
||||||
pub fn path_data<'a>(&self, data: &'a [u8]) -> &'a [[f32; 2]] {
|
pub fn path_data<'a>(&self, data: &'a [u8]) -> &'a [u8] {
|
||||||
let start = self.path_data_base as usize * 4;
|
let start = self.path_data_base as usize * 4;
|
||||||
let end = self.draw_tag_base as usize * 4;
|
let end = self.draw_tag_base as usize * 4;
|
||||||
bytemuck::cast_slice(&data[start..end])
|
bytemuck::cast_slice(&data[start..end])
|
||||||
|
|
|
@ -245,8 +245,8 @@ impl<'a> DrawGlyphs<'a> {
|
||||||
/// Sets whether to enable hinting.
|
/// Sets whether to enable hinting.
|
||||||
///
|
///
|
||||||
/// The default value is `false`.
|
/// The default value is `false`.
|
||||||
pub fn hint(mut self, yes: bool) -> Self {
|
pub fn hint(mut self, hint: bool) -> Self {
|
||||||
self.run.hint = yes;
|
self.run.hint = hint;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue