From 6e472748d71adb6a80867adad2bdb7ebcd75e99f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 4 Mar 2025 19:23:24 -0700 Subject: [PATCH] [fontations] Set Location only if non-zero --- src/fontations/lib.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index d87e6849a..812be0151 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -359,11 +359,21 @@ pub extern "C" fn hb_fontations_font_set_funcs(font: *mut hb_font_t) { let mut num_coords: u32 = 0; let coords = unsafe { hb_font_get_var_coords_normalized(font, &mut num_coords) }; let coords = unsafe { std::slice::from_raw_parts(coords, num_coords as usize) }; - let mut location = Location::new(num_coords as usize); - let coords_mut = location.coords_mut(); - for i in 0..num_coords as usize { - coords_mut[i] = NormalizedCoord::from_bits(coords[i] as i16); - } + let all_zeros = coords.iter().all(|&x| x == 0); + // if all zeros, use Location::default() + // otherwise, use the provided coords. + // This currently doesn't seem to have a perf effect on fontations, but it's a good idea to + // check if the coords are all zeros before creating a Location. + let location = if all_zeros { + Location::default() + } else { + let mut location = Location::new(num_coords as usize); + let coords_mut = location.coords_mut(); + for i in 0..num_coords as usize { + coords_mut[i] = NormalizedCoord::from_bits(coords[i] as i16); + } + location + }; let outline_glyphs = font_ref.outline_glyphs();