From 117264edde4b291dedb9fddbe6037231e4b994e1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Oct 2026 01:23:34 -0600 Subject: [PATCH] [subset] Preserve fractional CFF displacements during specialization (#6347) Check the real value when identifying zero operands. Converting to an integer truncates nonzero displacements smaller than one, allowing h/v specialization to remove them and change glyph geometry. Add move and line regressions covering positive and negative fractions on either axis, alongside genuine zero operands. The regression fails before the fix. The full Meson suite passes: 277 passed, one skipped. Assisted-by: Codex --- src/hb-cff-specializer.hh | 4 ++-- src/test-cff.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/hb-cff-specializer.hh b/src/hb-cff-specializer.hh index 34d4065a6..d1d18a797 100644 --- a/src/hb-cff-specializer.hh +++ b/src/hb-cff-specializer.hh @@ -18,11 +18,11 @@ namespace CFF { /* CharString command representation - forward declared in hb-subset-cff-common.hh */ -/* Check if a value is effectively zero */ +/* Specialization must preserve nonzero fractional displacements. */ static inline bool is_zero (const number_t &n) { - return n.to_int () == 0; + return n.to_real () == 0.; } /* Generalize CharString commands to canonical form diff --git a/src/test-cff.cc b/src/test-cff.cc index cbfb5275e..136e43b6a 100644 --- a/src/test-cff.cc +++ b/src/test-cff.cc @@ -70,6 +70,36 @@ test_specialized_line_geometry () } } +static void +test_specialized_fractional_geometry () +{ + const double deltas[][2] = { + {0.5, 12}, {-0.5, 12}, {12, 0.5}, {12, -0.5}, + {0.25, -0.75}, {0, 12}, {12, 0}, + }; + for (CFF::op_code_t op : {OpCode_rmoveto, OpCode_rlineto}) + for (const auto &delta : deltas) + { + hb_vector_t commands; + CFF::cs_command_t cmd (op); + CFF::number_t dx, dy; + dx.set_real (delta[0]); + dy.set_real (delta[1]); + cmd.args.push (dx); + cmd.args.push (dy); + commands.push (std::move (cmd)); + CFF::specialize_commands (commands); + CFF::str_buff_t encoded; + hb_always_assert (CFF::encode_commands (commands, encoded)); + CFF::generalize_commands (commands); + hb_always_assert (commands.length == 1); + hb_always_assert (commands[0].op == op); + hb_always_assert (commands[0].args.length == 2); + hb_always_assert (commands[0].args[0].to_real () == delta[0]); + hb_always_assert (commands[0].args[1].to_real () == delta[1]); + } +} + template static void test_fd_select_sentinel () @@ -100,6 +130,7 @@ int main (int argc, char **argv) { test_specialized_line_geometry (); + test_specialized_fractional_geometry (); test_fd_select_sentinel (); test_fd_select_sentinel ();