Skip to content

Commit 800f03c

Browse files
authored
Support static VARC variation axes (#2142)
1 parent 5f411f6 commit 800f03c

5 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎font-test-data/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ pub mod morx {
135135
pub mod varc {
136136
pub static CJK_6868: &[u8] = include_bytes!("../test_data/ttf/varc-6868.ttf");
137137
pub static CONDITIONALS: &[u8] = include_bytes!("../test_data/ttf/varc-ac01-conditional.ttf");
138+
pub static STATIC_GVAR: &[u8] = include_bytes!("../test_data/ttf/varc-static-gvar.ttf");
138139
pub static DELTA_PRECISION: &[u8] = include_bytes!("../test_data/ttf/varc-delta-precision.ttf");
139140
}
140141

1012 Bytes
Binary file not shown.

‎skrifa/src/outline/cff/mod.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ impl<'a> Outlines<'a> {
105105
self.top_dict.charstrings.count() as usize
106106
}
107107

108+
pub(crate) fn variation_axis_count(&self) -> usize {
109+
self.top_dict
110+
.var_store
111+
.as_ref()
112+
.and_then(|store| store.variation_region_list().ok())
113+
.map(|regions| regions.axis_count() as usize)
114+
.unwrap_or_default()
115+
}
116+
108117
/// Returns the number of available subfonts.
109118
pub fn subfont_count(&self) -> u32 {
110119
// All CFF fonts have at least one logical subfont.

‎skrifa/src/outline/glyf/mod.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ impl<'a> Outlines<'a> {
143143
self.glyph_count as usize
144144
}
145145

146+
pub(crate) fn variation_axis_count(&self) -> usize {
147+
self.gvar
148+
.as_ref()
149+
.map(|gvar| gvar.axis_count() as usize)
150+
.unwrap_or_default()
151+
}
152+
146153
pub fn prefer_interpreter(&self) -> bool {
147154
self.prefer_interpreter
148155
}

‎skrifa/src/outline/varc/mod.rs‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ impl<'a> BaseOutlines<'a> {
110110
Self::Cff(..) => 0,
111111
}
112112
}
113+
114+
fn variation_axis_count(&self) -> usize {
115+
match self {
116+
Self::Glyf(glyf) => glyf.variation_axis_count(),
117+
Self::Cff(cff) => cff.variation_axis_count(),
118+
}
119+
}
113120
}
114121

115122
#[derive(Clone)]
@@ -152,7 +159,9 @@ impl<'a> Outlines<'a> {
152159
fn from_base(font: &FontRef<'a>, varc: Varc<'a>, base: BaseOutlines<'a>) -> Option<Self> {
153160
let glyph_metrics = GlyphHMetrics::new(font)?;
154161
let units_per_em = font.head().ok()?.units_per_em();
155-
let axis_count = font.axes().len();
162+
// A static VARC font may omit fvar and use the axes retained in gvar
163+
// or the CFF2 VariationStore for component-internal coordinates.
164+
let axis_count = font.axes().len().max(base.variation_axis_count());
156165
let coverage = varc.coverage().ok()?;
157166
let var_store = varc.multi_var_store().transpose().ok()?;
158167
let regions = var_store
@@ -996,6 +1005,33 @@ mod tests {
9961005
assert_eq!(out.as_slice(), &[coord(0.25)]);
9971006
}
9981007

1008+
#[test]
1009+
fn draws_with_gvar_axes_without_fvar() {
1010+
let font = FontRef::new(font_test_data::varc::STATIC_GVAR).unwrap();
1011+
assert!(font.fvar().is_err());
1012+
assert_eq!(font.gvar().unwrap().axis_count(), 1);
1013+
1014+
let outlines = Outlines::new(&font).unwrap();
1015+
assert_eq!(outlines.axis_count, 1);
1016+
let outline = outlines.outline(GlyphId::new(1)).unwrap().unwrap();
1017+
let mut buf = vec![0; outline.required_buffer_size()];
1018+
let mut pen = Vec::<PathElement>::new();
1019+
outlines
1020+
.draw(
1021+
&outline,
1022+
&mut buf,
1023+
Size::unscaled(),
1024+
&[],
1025+
PathStyle::default(),
1026+
&mut pen,
1027+
)
1028+
.unwrap();
1029+
assert_eq!(
1030+
path_head_signature(&pen, 4),
1031+
["M50.00,0.00", "L450.00,0.00", "L250.00,500.00", "Z"]
1032+
);
1033+
}
1034+
9991035
#[test]
10001036
fn scale_matrix_only_scales_translation() {
10011037
let matrix = Matrix::from_elements([1.0, 2.0, 3.0, 4.0, 5.0, -6.0]);

0 commit comments

Comments
 (0)