From ebeccf3e63bff96b7a7766dea566704a9cbeae44 Mon Sep 17 00:00:00 2001 From: Michiharu Ariza Date: Tue, 18 Sep 2018 17:24:30 -0700 Subject: [PATCH] fixed char widths & standard Encoding in subset CFF also merged flush_n_args to flush_args into one takes start index of the arguments on stack instead of count --- src/hb-cff-interp-cs-common.hh | 20 +++++--------------- src/hb-cff1-interp-cs.hh | 11 +++++++---- src/hb-cff2-interp-cs.hh | 2 +- src/hb-subset-cff1.cc | 22 ++++++++++++++++------ src/hb-subset-cff2.cc | 12 ++++++------ 5 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/hb-cff-interp-cs-common.hh b/src/hb-cff-interp-cs-common.hh index 965603f96..ec3eae40f 100644 --- a/src/hb-cff-interp-cs-common.hh +++ b/src/hb-cff-interp-cs-common.hh @@ -220,7 +220,7 @@ struct CSOpSet : OpSet return env.returnFromSubr (); case OpCode_endchar: env.set_endchar (true); - OPSET::flush_op (op, env, param); + OPSET::flush_args_and_op (op, env, param); break; case OpCode_fixedcs: @@ -352,25 +352,15 @@ struct CSOpSet : OpSet OPSET::flush_args_and_op (op, env, param); } - static inline void flush_args_and_op (OpCode op, ENV &env, PARAM& param) + static inline void flush_args_and_op (OpCode op, ENV &env, PARAM& param, unsigned int start_arg = 0) { - OPSET::flush_n_args_and_op (op, env.argStack.get_count (), env, param); - } - - static inline void flush_n_args_and_op (OpCode op, unsigned int n, ENV &env, PARAM& param) - { - OPSET::flush_n_args (n, env, param); + OPSET::flush_args (env, param, start_arg); OPSET::flush_op (op, env, param); } - static inline void flush_args (ENV &env, PARAM& param) + static inline void flush_args (ENV &env, PARAM& param, unsigned int start_arg = 0) { - OPSET::flush_n_args (env.argStack.get_count (), env, param); - } - - static inline void flush_n_args (unsigned int n, ENV &env, PARAM& param) - { - env.pop_n_args (n); + env.pop_n_args (env.argStack.get_count () - start_arg); } static inline void flush_op (OpCode op, ENV &env, PARAM& param) diff --git a/src/hb-cff1-interp-cs.hh b/src/hb-cff1-interp-cs.hh index 29c4ad356..f618ef844 100644 --- a/src/hb-cff1-interp-cs.hh +++ b/src/hb-cff1-interp-cs.hh @@ -48,17 +48,20 @@ struct CFF1CSInterpEnv : CSInterpEnv bool check_transient_array_index (unsigned int i) const { return i < kTransientArraySize; } - inline void check_width (void) + inline unsigned int check_width (void) { + unsigned int arg_start = 0; if (!processed_width) { if ((SUPER::argStack.get_count () & 1) != 0) { width = SUPER::argStack[0]; has_width = true; + arg_start = 1; } processed_width = true; } + return arg_start; } bool processed_width; @@ -198,10 +201,10 @@ struct CFF1CSOpSet : CSOpSet return true; } - static inline void flush_args (CFF1CSInterpEnv &env, PARAM& param) + static inline void flush_args (CFF1CSInterpEnv &env, PARAM& param, unsigned int start_arg = 0) { - env.check_width (); - SUPER::flush_args (env, param); + start_arg = env.check_width (); + SUPER::flush_args (env, param, start_arg); } private: diff --git a/src/hb-cff2-interp-cs.hh b/src/hb-cff2-interp-cs.hh index 2f40de6d4..5a564bcf7 100644 --- a/src/hb-cff2-interp-cs.hh +++ b/src/hb-cff2-interp-cs.hh @@ -168,7 +168,7 @@ struct CFF2CSOpSet : CSOpSet static inline void process_vsindex (CFF2CSInterpEnv &env, PARAM& param) { env.process_vsindex (); - OPSET::flush_n_args_and_op (OpCode_vsindexcs, 1, env, param); + OPSET::flush_args_and_op (OpCode_vsindexcs, env, param, env.argStack.get_count ()-1); } private: diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 0218da7c2..3e9b34169 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -270,8 +270,12 @@ struct CFF1FontDict_OpSerializer : CFFFontDict_OpSerializer struct CFF1CSOpSet_Flatten : CFF1CSOpSet { - static inline void flush_args_and_op (OpCode op, CFF1CSInterpEnv &env, FlattenParam& param) + static inline void flush_args_and_op (OpCode op, CFF1CSInterpEnv &env, FlattenParam& param, unsigned int start_arg = 0) { + start_arg = env.check_width (); + if ((start_arg > 0) && likely (param.flatStr.len == 0)) + flush_width (env, param); + switch (op) { case OpCode_hstem: @@ -292,16 +296,16 @@ struct CFF1CSOpSet_Flatten : CFF1CSOpSet /* NO BREAK */ default: - SUPER::flush_args_and_op (op, env, param); + SUPER::flush_args_and_op (op, env, param, start_arg); break; } } - static inline void flush_n_args (unsigned int n, CFF1CSInterpEnv &env, FlattenParam& param) + static inline void flush_args (CFF1CSInterpEnv &env, FlattenParam& param, unsigned int start_arg = 0) { - for (unsigned int i = env.argStack.get_count () - n; i < env.argStack.get_count (); i++) + for (unsigned int i = start_arg; i < env.argStack.get_count (); i++) param.flatStr.encode_num (env.argStack[i]); - SUPER::flush_n_args (n, env, param); + SUPER::flush_args (env, param, start_arg); } static inline void flush_op (OpCode op, CFF1CSInterpEnv &env, FlattenParam& param) @@ -309,6 +313,12 @@ struct CFF1CSOpSet_Flatten : CFF1CSOpSet param.flatStr.encode_op (op); } + static inline void flush_width (CFF1CSInterpEnv &env, FlattenParam& param) + { + assert (env.has_width); + param.flatStr.encode_num (env.width); + } + static inline void flush_hintmask (OpCode op, CFF1CSInterpEnv &env, FlattenParam& param) { SUPER::flush_hintmask (op, env, param); @@ -527,7 +537,7 @@ struct cff_subset_plan { } subset_charset = gid_renum || !acc.is_predef_charset (); - subset_encoding = !acc.is_CID() && (gid_renum || !acc.is_predef_encoding ()); + subset_encoding = !acc.is_CID() && !acc.is_predef_encoding (); /* CFF header */ final_size += OT::cff1::static_size; diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 6ee1caa28..705574c92 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -77,7 +77,7 @@ struct CFF2TopDict_OpSerializer : CFFTopDict_OpSerializer<> struct CFF2CSOpSet_Flatten : CFF2CSOpSet { - static inline void flush_args_and_op (OpCode op, CFF2CSInterpEnv &env, FlattenParam& param) + static inline void flush_args_and_op (OpCode op, CFF2CSInterpEnv &env, FlattenParam& param, unsigned int start_arg = 0) { switch (op) { @@ -104,19 +104,19 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet /* NO BREAK */ default: - SUPER::flush_args_and_op (op, env, param); + SUPER::flush_args_and_op (op, env, param, start_arg); break; } } - static inline void flush_n_args (unsigned int n, CFF2CSInterpEnv &env, FlattenParam& param) + static inline void flush_args (CFF2CSInterpEnv &env, FlattenParam& param, unsigned int start_arg = 0) { - for (unsigned int i = env.argStack.get_count () - n; i < env.argStack.get_count ();) + for (unsigned int i = start_arg; i < env.argStack.get_count ();) { const BlendArg &arg = env.argStack[i]; if (arg.blended ()) { - assert ((arg.numValues > 0) && (n >= arg.numValues)); + assert ((arg.numValues > 0) && (env.argStack.get_count () - start_arg >= arg.numValues)); flatten_blends (arg, i, env, param); i += arg.numValues; } @@ -126,7 +126,7 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet i++; } } - SUPER::flush_n_args (n, env, param); + SUPER::flush_args (env, param, start_arg); } static inline void flatten_blends (const BlendArg &arg, unsigned int i, CFF2CSInterpEnv &env, FlattenParam& param)