Skip to content

Commit

Permalink
Expose unsupported sample parts
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Jul 18, 2024
1 parent 059a24d commit 0283c5e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "font"
version = "0.37.0"
version = "0.38.0"
edition = "2021"
license = "Apache-2.0/MIT"
authors = ["Ivan Ukhov <ivan.ukhov@gmail.com>"]
Expand Down
10 changes: 5 additions & 5 deletions src/formats/opentype/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Directory {
/// Features to lookups.
pub features: Vec<(Feature, Vec<usize>)>,
/// Lookups.
pub lookups: Vec<Vec<Option<BTreeSet<Sample>>>>,
pub lookups: Vec<Vec<Option<BTreeSet<Option<Sample>>>>>,
}

pub(crate) fn read<T: crate::Read>(cache: &mut Cache<T>) -> Result<Directory> {
Expand Down Expand Up @@ -97,8 +97,8 @@ fn process_table<T>(
HashMap<(Feature, Vec<usize>), usize>,
),
lookups: &mut (
Vec<Vec<Option<BTreeSet<Sample>>>>,
HashMap<Vec<Option<BTreeSet<Sample>>>, usize>,
Vec<Vec<Option<BTreeSet<Option<Sample>>>>>,
HashMap<Vec<Option<BTreeSet<Option<Sample>>>>, usize>,
),
) -> Option<()>
where
Expand All @@ -125,8 +125,8 @@ fn process_graphs<T>(
directory: &layout::Directory<T>,
mapping: &Mapping,
lookups: &mut (
Vec<Vec<Option<BTreeSet<Sample>>>>,
HashMap<Vec<Option<BTreeSet<Sample>>>, usize>,
Vec<Vec<Option<BTreeSet<Option<Sample>>>>>,
HashMap<Vec<Option<BTreeSet<Option<Sample>>>>, usize>,
),
) -> Vec<usize>
where
Expand Down
41 changes: 20 additions & 21 deletions src/formats/opentype/features/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ pub trait Transform<'l> {
}

impl<'l> Transform<'l> for &[Option<Rules>] {
type Target = Vec<Option<BTreeSet<Sample>>>;
type Target = Vec<Option<BTreeSet<Option<Sample>>>>;
type Parameter = &'l [Vec<Option<Rules>>];

fn transform(self, mapping: &Mapping, rules: Self::Parameter) -> Self::Target {
self.iter()
.map(|value| {
value
.as_ref()
.and_then(|value| value.transform(mapping, rules))
})
.map(|value| value.as_ref().map(|value| value.transform(mapping, rules)))
.collect()
}
}

impl<'l> Transform<'l> for &Rules {
type Target = Option<BTreeSet<Sample>>;
type Target = BTreeSet<Option<Sample>>;
type Parameter = &'l [Vec<Option<Rules>>];

fn transform(self, mapping: &Mapping, rules: Self::Parameter) -> Self::Target {
Expand Down Expand Up @@ -141,34 +137,37 @@ where
values
}

fn postcompress<T>(values: T) -> Option<BTreeSet<Sample>>
fn postcompress<T>(values: T) -> BTreeSet<Option<Sample>>
where
T: Iterator<Item = Option<Sample>>,
{
let values = values.collect::<Option<BTreeSet<_>>>()?;
let values = values.collect::<BTreeSet<_>>();
let mut iterator = values.into_iter();
let mut values = BTreeSet::new();
let mut range: Option<(char, char)> = None;
loop {
match (range, iterator.next()) {
(None, Some(Sample::Alternate(value))) => {
values.insert(Sample::Alternate(value));
(None, Some(None)) => {
values.insert(None);
}
(None, Some(Sample::Composite(value))) => {
(None, Some(Some(Sample::Alternate(value)))) => {
values.insert(Sample::Alternate(value).into());
}
(None, Some(Some(Sample::Composite(value)))) => {
if value.len() == 1 && value[0].len() == 1 {
if let Some(Component::Scalar(next)) = value[0].first() {
range = Some((*next, *next));
continue;
}
}
values.insert(Sample::Composite(value));
values.insert(Sample::Composite(value).into());
}
(Some((start, end)), Some(Sample::Alternate(value))) => {
(Some((start, end)), Some(Some(Sample::Alternate(value)))) => {
sample(&mut values, (start, end));
values.insert(Sample::Alternate(value));
values.insert(Sample::Alternate(value).into());
range = None;
}
(Some((start, end)), Some(Sample::Composite(value))) => {
(Some((start, end)), Some(Some(Sample::Composite(value)))) => {
if value.len() == 1 && value[0].len() == 1 {
if let Some(Component::Scalar(next)) = value[0].first() {
if end as usize + 1 == *next as usize {
Expand All @@ -181,7 +180,7 @@ where
}
}
sample(&mut values, (start, end));
values.insert(Sample::Composite(value));
values.insert(Sample::Composite(value).into());
range = None;
}
(Some((start, end)), None) => {
Expand All @@ -193,7 +192,7 @@ where
}
}
}
Some(values)
values
}

#[inline]
Expand All @@ -206,10 +205,10 @@ fn component(values: &mut BTreeSet<Component>, (start, end): (char, char)) {
}

#[inline]
fn sample(values: &mut BTreeSet<Sample>, (start, end): (char, char)) {
fn sample(values: &mut BTreeSet<Option<Sample>>, (start, end): (char, char)) {
if start == end {
values.insert(Sample::Simple(Component::Scalar(start)));
values.insert(Sample::Simple(Component::Scalar(start)).into());
} else {
values.insert(Sample::Simple(Component::Range((start, end))));
values.insert(Sample::Simple(Component::Range((start, end))).into());
}
}
Loading

0 comments on commit 0283c5e

Please sign in to comment.