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] hinting mode changes/remove feature gate #710

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 0 additions & 5 deletions skrifa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ repository = "https://github.com/googlefonts/fontations"
readme = "README.md"
categories = ["text-processing", "parsing", "graphics"]

[features]
default = ["scale"]
scale = []
hinting = []

[dependencies]
read-fonts = { version = "0.13.1", path = "../read-fonts" }

Expand Down
1 change: 0 additions & 1 deletion skrifa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub mod charmap;
pub mod font;
pub mod instance;
pub mod metrics;
#[cfg(feature = "scale")]
pub mod scale;
pub mod setting;
pub mod string;
Expand Down
40 changes: 20 additions & 20 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::{Hinting, 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], hinting: Hinting) -> 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 && hinting != Hinting::None {
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 @@ -157,9 +157,9 @@ mod tests {
has_variations: true,
has_overlaps: false,
};
let required_size = outline_info.required_buffer_size(false);
let required_size = outline_info.required_buffer_size(Hinting::None);
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, Hinting::None).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 @@ -190,8 +190,8 @@ mod tests {
};
// Required size adds 4 bytes slop to account for internal alignment
// requirements. So subtract 5 to force a failure.
let not_enough = outline_info.required_buffer_size(false) - 5;
let not_enough = outline_info.required_buffer_size(Hinting::None) - 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, Hinting::None).is_none());
}
}
Loading