mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +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,
|
||||
scaler: &mut GlyphProvider,
|
||||
) -> 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
|
||||
// as part of the key.
|
||||
let is_nz_fill = matches!(style, Style::Fill(Fill::NonZero));
|
||||
if is_nz_fill {
|
||||
if let Some(range) = self.glyphs.get(&key) {
|
||||
return Some(*range);
|
||||
let range = if matches!(style, Style::Fill(Fill::NonZero)) {
|
||||
use std::collections::hash_map::Entry;
|
||||
match self.glyphs.entry(key) {
|
||||
Entry::Occupied(entry) => *entry.get(),
|
||||
Entry::Vacant(entry) => *entry.insert(encode_glyph()?),
|
||||
}
|
||||
}
|
||||
let start = self.encoding.stream_offsets();
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
encode_glyph()?
|
||||
};
|
||||
Some(range)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Layout {
|
|||
}
|
||||
|
||||
/// 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 end = self.draw_tag_base as usize * 4;
|
||||
bytemuck::cast_slice(&data[start..end])
|
||||
|
|
|
@ -245,8 +245,8 @@ impl<'a> DrawGlyphs<'a> {
|
|||
/// Sets whether to enable hinting.
|
||||
///
|
||||
/// The default value is `false`.
|
||||
pub fn hint(mut self, yes: bool) -> Self {
|
||||
self.run.hint = yes;
|
||||
pub fn hint(mut self, hint: bool) -> Self {
|
||||
self.run.hint = hint;
|
||||
self
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue