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] FontRef instead of TableProvider #1079

Merged
merged 6 commits into from
Aug 15, 2024
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
12 changes: 12 additions & 0 deletions read-fonts/src/tables/postscript/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::codegen_prelude::*;
/// Common type for uniform access to CFF and CFF2 index formats.
#[derive(Clone)]
pub enum Index<'a> {
Empty,
Format1(Index1<'a>),
Format2(Index2<'a>),
}
Expand All @@ -28,6 +29,7 @@ impl<'a> Index<'a> {
/// Returns the number of objects in the index.
pub fn count(&self) -> u32 {
match self {
Self::Empty => 0,
Self::Format1(ix) => ix.count() as u32,
Self::Format2(ix) => ix.count(),
}
Expand All @@ -51,6 +53,7 @@ impl<'a> Index<'a> {
/// Returns the total size in bytes of the index table.
pub fn size_in_bytes(&self) -> Result<usize, ReadError> {
match self {
Self::Empty => Ok(0),
Self::Format1(ix) => ix.size_in_bytes(),
Self::Format2(ix) => ix.size_in_bytes(),
}
Expand All @@ -59,6 +62,7 @@ impl<'a> Index<'a> {
/// Returns the offset at the given index.
pub fn get_offset(&self, index: usize) -> Result<usize, Error> {
match self {
Self::Empty => Err(ReadError::OutOfBounds.into()),
Self::Format1(ix) => ix.get_offset(index),
Self::Format2(ix) => ix.get_offset(index),
}
Expand All @@ -67,6 +71,7 @@ impl<'a> Index<'a> {
/// Returns the data for the object at the given index.
pub fn get(&self, index: usize) -> Result<&'a [u8], Error> {
match self {
Self::Empty => Err(ReadError::OutOfBounds.into()),
Self::Format1(ix) => ix.get(index),
Self::Format2(ix) => ix.get(index),
}
Expand All @@ -85,6 +90,12 @@ impl<'a> From<Index2<'a>> for Index<'a> {
}
}

impl Default for Index<'_> {
fn default() -> Self {
Self::Empty
}
}

impl<'a> Index1<'a> {
/// Returns the total size in bytes of the index table.
pub fn size_in_bytes(&self) -> Result<usize, ReadError> {
Expand Down Expand Up @@ -272,6 +283,7 @@ mod tests {
let buf = make_index(fmt, off_size, count);
let index = Index::new(buf.font_data().as_bytes(), fmt == 2).unwrap();
let built_off_size = match &index {
Index::Empty => 0,
Index::Format1(v1) => v1.off_size(),
Index::Format2(v2) => v2.off_size(),
};
Expand Down
8 changes: 5 additions & 3 deletions skrifa/src/outline/cff/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,9 @@ mod tests {
use read_fonts::{tables::postscript::charstring::CommandSink, types::F2Dot14, FontRef};

use super::{
BlueZone, Blues, Fixed, Hint, HintMap, HintMask, HintParams, HintState, HintingSink,
StemHint, GHOST_BOTTOM, GHOST_TOP, HINT_MASK_SIZE, LOCKED, PAIR_BOTTOM, PAIR_TOP,
super::OutlinesCommon, BlueZone, Blues, Fixed, Hint, HintMap, HintMask, HintParams,
HintState, HintingSink, StemHint, GHOST_BOTTOM, GHOST_TOP, HINT_MASK_SIZE, LOCKED,
PAIR_BOTTOM, PAIR_TOP,
};

fn make_hint_state() -> HintState {
Expand Down Expand Up @@ -1302,7 +1303,8 @@ mod tests {
#[test]
fn hint_mapping() {
let font = FontRef::new(font_test_data::CANTARELL_VF_TRIMMED).unwrap();
let cff_font = super::super::Outlines::new(&font).unwrap();
let base = OutlinesCommon::new(&font).unwrap();
let cff_font = super::super::Outlines::new(&base).unwrap();
let state = cff_font
.subfont(0, Some(8.0), &[F2Dot14::from_f32(-1.0); 2])
.unwrap()
Expand Down
Loading