Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[skrifa] cleanup glyf code structure #709

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions skrifa/src/scale/glyf/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use read_fonts::{
types::{F26Dot6, Fixed, Point},
};

use super::ScalerGlyph;
use super::Outline;

/// Buffers used during glyph scaling.
pub struct ScalerMemory<'a> {
pub struct OutlineMemory<'a> {
pub unscaled: &'a mut [Point<i32>],
pub scaled: &'a mut [Point<F26Dot6>],
pub original_scaled: &'a mut [Point<F26Dot6>],
Expand All @@ -21,21 +21,21 @@ pub struct ScalerMemory<'a> {
pub composite_deltas: &'a mut [Point<Fixed>],
}

impl<'a> ScalerMemory<'a> {
pub(super) fn new(glyph: &ScalerGlyph, buf: &'a mut [u8], with_hinting: bool) -> Option<Self> {
let (scaled, buf) = alloc_slice(buf, glyph.points)?;
let (unscaled, buf) = alloc_slice(buf, glyph.max_other_points)?;
impl<'a> OutlineMemory<'a> {
pub(super) fn new(outline: &Outline, buf: &'a mut [u8], with_hinting: bool) -> Option<Self> {
let (scaled, buf) = alloc_slice(buf, outline.points)?;
let (unscaled, buf) = alloc_slice(buf, outline.max_other_points)?;
// We only need original scaled points when hinting
let (original_scaled, buf) = if glyph.has_hinting && with_hinting {
alloc_slice(buf, glyph.max_other_points)?
let (original_scaled, buf) = if outline.has_hinting && with_hinting {
alloc_slice(buf, outline.max_other_points)?
} else {
(Default::default(), buf)
};
// Don't allocate any delta buffers if we don't have variations
let (deltas, iup_buffer, composite_deltas, buf) = if glyph.has_variations {
let (deltas, buf) = alloc_slice(buf, glyph.max_simple_points)?;
let (iup_buffer, buf) = alloc_slice(buf, glyph.max_simple_points)?;
let (composite_deltas, buf) = alloc_slice(buf, glyph.max_component_delta_stack)?;
let (deltas, iup_buffer, composite_deltas, buf) = if outline.has_variations {
let (deltas, buf) = alloc_slice(buf, outline.max_simple_points)?;
let (iup_buffer, buf) = alloc_slice(buf, outline.max_simple_points)?;
let (composite_deltas, buf) = alloc_slice(buf, outline.max_component_delta_stack)?;
(deltas, iup_buffer, composite_deltas, buf)
} else {
(
Expand All @@ -45,8 +45,8 @@ impl<'a> ScalerMemory<'a> {
buf,
)
};
let (contours, buf) = alloc_slice(buf, glyph.contours)?;
let (flags, _) = alloc_slice(buf, glyph.points)?;
let (contours, buf) = alloc_slice(buf, outline.contours)?;
let (flags, _) = alloc_slice(buf, outline.points)?;
Some(Self {
unscaled,
scaled,
Expand Down Expand Up @@ -145,7 +145,7 @@ mod tests {

#[test]
fn outline_memory() {
let outline_info = ScalerGlyph {
let outline_info = Outline {
glyph: None,
glyph_id: Default::default(),
points: 10,
Expand All @@ -159,7 +159,7 @@ mod tests {
};
let required_size = outline_info.required_buffer_size(false);
let mut buf = vec![0u8; required_size];
let memory = ScalerMemory::new(&outline_info, &mut buf, false).unwrap();
let memory = OutlineMemory::new(&outline_info, &mut buf, false).unwrap();
assert_eq!(memory.scaled.len(), outline_info.points);
assert_eq!(memory.unscaled.len(), outline_info.max_other_points);
// We don't allocate this buffer when hinting is disabled
Expand All @@ -176,7 +176,7 @@ mod tests {

#[test]
fn fail_outline_memory() {
let outline_info = ScalerGlyph {
let outline_info = Outline {
glyph: None,
glyph_id: Default::default(),
points: 10,
Expand All @@ -192,6 +192,6 @@ mod tests {
// requirements. So subtract 5 to force a failure.
let not_enough = outline_info.required_buffer_size(false) - 5;
let mut buf = vec![0u8; not_enough];
assert!(ScalerMemory::new(&outline_info, &mut buf, false).is_none());
assert!(OutlineMemory::new(&outline_info, &mut buf, false).is_none());
}
}
Loading