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 ();