2 * Copyright © 2018 Adobe Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Adobe Author(s): Michiharu Ariza
27 #ifndef HB_SUBSET_CFF_COMMON_HH
28 #define HB_SUBSET_CFF_COMMON_HH
32 #include "hb-subset-plan.hh"
33 #include "hb-cff-interp-cs-common.hh"
37 /* Used for writing a temporary charstring */
40 str_encoder_t (str_buff_t &buff_)
41 : buff (buff_), error (false) {}
43 void reset () { buff.resize (0); }
45 void encode_byte (unsigned char b)
47 if (unlikely (buff.push (b) == &Crap(unsigned char)))
51 void encode_int (int v)
53 if ((-1131 <= v) && (v <= 1131))
55 if ((-107 <= v) && (v <= 107))
56 encode_byte (v + 139);
60 encode_byte ((v >> 8) + OpCode_TwoBytePosInt0);
61 encode_byte (v & 0xFF);
66 encode_byte ((v >> 8) + OpCode_TwoByteNegInt0);
67 encode_byte (v & 0xFF);
72 if (unlikely (v < -32768))
74 else if (unlikely (v > 32767))
76 encode_byte (OpCode_shortint);
77 encode_byte ((v >> 8) & 0xFF);
78 encode_byte (v & 0xFF);
82 void encode_num (const number_t& n)
84 if (n.in_int_range ())
86 encode_int (n.to_int ());
90 int32_t v = n.to_fixed ();
91 encode_byte (OpCode_fixedcs);
92 encode_byte ((v >> 24) & 0xFF);
93 encode_byte ((v >> 16) & 0xFF);
94 encode_byte ((v >> 8) & 0xFF);
95 encode_byte (v & 0xFF);
99 void encode_op (op_code_t op)
101 if (Is_OpCode_ESC (op))
103 encode_byte (OpCode_escape);
104 encode_byte (Unmake_OpCode_ESC (op));
110 void copy_str (const byte_str_t &str)
112 unsigned int offset = buff.length;
113 buff.resize (offset + str.length);
114 if (unlikely (buff.length < offset + str.length))
119 memcpy (&buff[offset], &str[0], str.length);
122 bool is_error () const { return error; }
125 void set_error () { error = true; }
131 struct cff_sub_table_offsets_t {
132 cff_sub_table_offsets_t () : privateDictsOffset (0)
135 FDSelectInfo.init ();
137 charStringsInfo.init ();
138 globalSubrsInfo.init ();
139 localSubrsInfos.init ();
142 ~cff_sub_table_offsets_t () { localSubrsInfos.fini (); }
144 table_info_t topDictInfo;
145 table_info_t FDSelectInfo;
146 table_info_t FDArrayInfo;
147 table_info_t charStringsInfo;
148 unsigned int privateDictsOffset;
149 table_info_t globalSubrsInfo;
150 hb_vector_t<table_info_t> localSubrsInfos;
153 template <typename OPSTR=op_str_t>
154 struct cff_top_dict_op_serializer_t : op_serializer_t
156 bool serialize (hb_serialize_context_t *c,
158 const cff_sub_table_offsets_t &offsets) const
160 TRACE_SERIALIZE (this);
164 case OpCode_CharStrings:
165 return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.charStringsInfo.offset));
168 return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.FDArrayInfo.offset));
170 case OpCode_FDSelect:
171 return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.FDSelectInfo.offset));
174 return_trace (copy_opstr (c, opstr));
179 unsigned int calculate_serialized_size (const OPSTR &opstr) const
183 case OpCode_CharStrings:
185 case OpCode_FDSelect:
186 return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (opstr.op);
189 return opstr.str.length;
194 struct cff_font_dict_op_serializer_t : op_serializer_t
196 bool serialize (hb_serialize_context_t *c,
197 const op_str_t &opstr,
198 const table_info_t &privateDictInfo) const
200 TRACE_SERIALIZE (this);
202 if (opstr.op == OpCode_Private)
204 /* serialize the private dict size & offset as 2-byte & 4-byte integers */
205 if (unlikely (!UnsizedByteStr::serialize_int2 (c, privateDictInfo.size) ||
206 !UnsizedByteStr::serialize_int4 (c, privateDictInfo.offset)))
207 return_trace (false);
209 /* serialize the opcode */
210 HBUINT8 *p = c->allocate_size<HBUINT8> (1);
211 if (unlikely (p == nullptr)) return_trace (false);
212 p->set (OpCode_Private);
218 HBUINT8 *d = c->allocate_size<HBUINT8> (opstr.str.length);
219 if (unlikely (d == nullptr)) return_trace (false);
220 memcpy (d, &opstr.str[0], opstr.str.length);
225 unsigned int calculate_serialized_size (const op_str_t &opstr) const
227 if (opstr.op == OpCode_Private)
228 return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Private);
230 return opstr.str.length;
234 struct cff_private_dict_op_serializer_t : op_serializer_t
236 cff_private_dict_op_serializer_t (bool desubroutinize_, bool drop_hints_)
237 : desubroutinize (desubroutinize_), drop_hints (drop_hints_) {}
239 bool serialize (hb_serialize_context_t *c,
240 const op_str_t &opstr,
241 const unsigned int subrsOffset) const
243 TRACE_SERIALIZE (this);
245 if (drop_hints && dict_opset_t::is_hint_op (opstr.op))
247 if (opstr.op == OpCode_Subrs)
249 if (desubroutinize || (subrsOffset == 0))
252 return_trace (FontDict::serialize_offset2_op (c, opstr.op, subrsOffset));
255 return_trace (copy_opstr (c, opstr));
258 unsigned int calculate_serialized_size (const op_str_t &opstr,
259 bool has_localsubr=true) const
261 if (drop_hints && dict_opset_t::is_hint_op (opstr.op))
263 if (opstr.op == OpCode_Subrs)
265 if (desubroutinize || !has_localsubr)
268 return OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (opstr.op);
271 return opstr.str.length;
275 const bool desubroutinize;
276 const bool drop_hints;
279 struct flatten_param_t
285 template <typename ACC, typename ENV, typename OPSET, op_code_t endchar_op=OpCode_Invalid>
286 struct subr_flattener_t
288 subr_flattener_t (const ACC &acc_,
289 const hb_subset_plan_t *plan_)
290 : acc (acc_), plan (plan_) {}
292 bool flatten (str_buff_vec_t &flat_charstrings)
294 if (!flat_charstrings.resize (plan->num_output_glyphs ()))
296 for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
297 flat_charstrings[i].init ();
298 for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
300 hb_codepoint_t glyph;
301 if (!plan->old_gid_for_new_gid (i, &glyph))
303 /* add an endchar only charstring for a missing glyph if CFF1 */
304 if (endchar_op != OpCode_Invalid) flat_charstrings[i].push (endchar_op);
307 const byte_str_t str = (*acc.charStrings)[glyph];
308 unsigned int fd = acc.fdSelect->get_fd (glyph);
309 if (unlikely (fd >= acc.fdCount))
311 cs_interpreter_t<ENV, OPSET, flatten_param_t> interp;
312 interp.env.init (str, acc, fd);
313 flatten_param_t param = { flat_charstrings[i], plan->drop_hints };
314 if (unlikely (!interp.interpret (param)))
321 const hb_subset_plan_t *plan;
324 struct subr_closures_t
326 subr_closures_t () : valid (false), global_closure (nullptr)
327 { local_closures.init (); }
329 void init (unsigned int fd_count)
332 global_closure = hb_set_create ();
333 if (global_closure == hb_set_get_empty ())
335 if (!local_closures.resize (fd_count))
338 for (unsigned int i = 0; i < local_closures.length; i++)
340 local_closures[i] = hb_set_create ();
341 if (local_closures[i] == hb_set_get_empty ())
348 hb_set_destroy (global_closure);
349 for (unsigned int i = 0; i < local_closures.length; i++)
350 hb_set_destroy (local_closures[i]);
351 local_closures.fini ();
356 hb_set_clear (global_closure);
357 for (unsigned int i = 0; i < local_closures.length; i++)
358 hb_set_clear (local_closures[i]);
361 bool is_valid () const { return valid; }
363 hb_set_t *global_closure;
364 hb_vector_t<hb_set_t *> local_closures;
367 struct parsed_cs_op_t : op_str_t
369 void init (unsigned int subr_num_ = 0)
372 subr_num = subr_num_;
378 void fini () { op_str_t::fini (); }
380 bool for_drop () const { return drop_flag; }
381 void set_drop () { if (!for_keep ()) drop_flag = true; }
383 bool for_keep () const { return keep_flag; }
384 void set_keep () { keep_flag = true; }
386 bool for_skip () const { return skip_flag; }
387 void set_skip () { skip_flag = true; }
389 unsigned int subr_num;
397 struct parsed_cs_str_t : parsed_values_t<parsed_cs_op_t>
403 hint_dropped = false;
407 void add_op (op_code_t op, const byte_str_ref_t& str_ref)
410 SUPER::add_op (op, str_ref);
413 void add_call_op (op_code_t op, const byte_str_ref_t& str_ref, unsigned int subr_num)
417 unsigned int parsed_len = get_count ();
418 if (likely (parsed_len > 0))
419 values[parsed_len-1].set_skip ();
423 SUPER::add_op (op, str_ref, val);
427 void set_prefix (const number_t &num, op_code_t op = OpCode_Invalid)
434 bool at_end (unsigned int pos) const
436 return ((pos + 1 >= values.length) /* CFF2 */
437 || (values[pos + 1].op == OpCode_return));
440 bool is_parsed () const { return parsed; }
441 void set_parsed () { parsed = true; }
443 bool is_hint_dropped () const { return hint_dropped; }
444 void set_hint_dropped () { hint_dropped = true; }
446 bool is_vsindex_dropped () const { return vsindex_dropped; }
447 void set_vsindex_dropped () { vsindex_dropped = true; }
449 bool has_prefix () const { return has_prefix_; }
450 op_code_t prefix_op () const { return prefix_op_; }
451 const number_t &prefix_num () const { return prefix_num_; }
456 bool vsindex_dropped;
458 op_code_t prefix_op_;
459 number_t prefix_num_;
462 typedef parsed_values_t<parsed_cs_op_t> SUPER;
465 struct parsed_cs_str_vec_t : hb_vector_t<parsed_cs_str_t>
467 void init (unsigned int len_ = 0)
471 for (unsigned int i = 0; i < length; i++)
474 void fini () { SUPER::fini_deep (); }
477 typedef hb_vector_t<parsed_cs_str_t> SUPER;
480 struct subr_subset_param_t
482 void init (parsed_cs_str_t *parsed_charstring_,
483 parsed_cs_str_vec_t *parsed_global_subrs_, parsed_cs_str_vec_t *parsed_local_subrs_,
484 hb_set_t *global_closure_, hb_set_t *local_closure_,
487 parsed_charstring = parsed_charstring_;
488 current_parsed_str = parsed_charstring;
489 parsed_global_subrs = parsed_global_subrs_;
490 parsed_local_subrs = parsed_local_subrs_;
491 global_closure = global_closure_;
492 local_closure = local_closure_;
493 drop_hints = drop_hints_;
496 parsed_cs_str_t *get_parsed_str_for_context (call_context_t &context)
498 switch (context.type)
500 case CSType_CharString:
501 return parsed_charstring;
503 case CSType_LocalSubr:
504 if (likely (context.subr_num < parsed_local_subrs->length))
505 return &(*parsed_local_subrs)[context.subr_num];
508 case CSType_GlobalSubr:
509 if (likely (context.subr_num < parsed_global_subrs->length))
510 return &(*parsed_global_subrs)[context.subr_num];
516 template <typename ENV>
517 void set_current_str (ENV &env, bool calling)
519 parsed_cs_str_t *parsed_str = get_parsed_str_for_context (env.context);
520 if (likely (parsed_str != nullptr))
522 /* If the called subroutine is parsed partially but not completely yet,
523 * it must be because we are calling it recursively.
524 * Handle it as an error. */
525 if (unlikely (calling && !parsed_str->is_parsed () && (parsed_str->values.length > 0)))
528 current_parsed_str = parsed_str;
534 parsed_cs_str_t *current_parsed_str;
536 parsed_cs_str_t *parsed_charstring;
537 parsed_cs_str_vec_t *parsed_global_subrs;
538 parsed_cs_str_vec_t *parsed_local_subrs;
539 hb_set_t *global_closure;
540 hb_set_t *local_closure;
544 struct subr_remap_t : remap_t
546 void create (hb_set_t *closure)
548 /* create a remapping of subroutine numbers from old to new.
549 * no optimization based on usage counts. fonttools doesn't appear doing that either.
551 reset (closure->get_max () + 1);
552 for (hb_codepoint_t old_num = 0; old_num < length; old_num++)
554 if (hb_set_has (closure, old_num))
558 if (get_count () < 1240)
560 else if (get_count () < 33900)
566 hb_codepoint_t operator[] (unsigned int old_num) const
568 if (old_num >= length)
569 return CFF_UNDEF_CODE;
571 return remap_t::operator[] (old_num);
574 int biased_num (unsigned int old_num) const
576 hb_codepoint_t new_num = (*this)[old_num];
577 return (int)new_num - bias;
588 global_remap.init ();
589 local_remaps.init ();
592 ~subr_remap_ts () { fini (); }
594 void init (unsigned int fdCount)
596 local_remaps.resize (fdCount);
597 for (unsigned int i = 0; i < fdCount; i++)
598 local_remaps[i].init ();
601 void create (subr_closures_t& closures)
603 global_remap.create (closures.global_closure);
604 for (unsigned int i = 0; i < local_remaps.length; i++)
605 local_remaps[i].create (closures.local_closures[i]);
610 global_remap.fini ();
611 local_remaps.fini_deep ();
614 subr_remap_t global_remap;
615 hb_vector_t<subr_remap_t> local_remaps;
618 template <typename SUBSETTER, typename SUBRS, typename ACC, typename ENV, typename OPSET, op_code_t endchar_op=OpCode_Invalid>
619 struct subr_subsetter_t
621 subr_subsetter_t (ACC &acc_, const hb_subset_plan_t *plan_)
622 : acc (acc_), plan (plan_)
624 parsed_charstrings.init ();
625 parsed_global_subrs.init ();
626 parsed_local_subrs.init ();
633 parsed_charstrings.fini_deep ();
634 parsed_global_subrs.fini_deep ();
635 parsed_local_subrs.fini_deep ();
638 /* Subroutine subsetting with --no-desubroutinize runs in phases:
640 * 1. execute charstrings/subroutines to determine subroutine closures
641 * 2. parse out all operators and numbers
642 * 3. mark hint operators and operands for removal if --no-hinting
643 * 4. re-encode all charstrings and subroutines with new subroutine numbers
645 * Phases #1 and #2 are done at the same time in collect_subrs ().
646 * Phase #3 walks charstrings/subroutines forward then backward (hence parsing required),
647 * because we can't tell if a number belongs to a hint op until we see the first moveto.
649 * Assumption: a callsubr/callgsubr operator must immediately follow a (biased) subroutine number
650 * within the same charstring/subroutine, e.g., not split across a charstring and a subroutine.
654 closures.init (acc.fdCount);
655 remaps.init (acc.fdCount);
657 parsed_charstrings.init (plan->num_output_glyphs ());
658 parsed_global_subrs.init (acc.globalSubrs->count);
659 parsed_local_subrs.resize (acc.fdCount);
660 for (unsigned int i = 0; i < acc.fdCount; i++)
662 parsed_local_subrs[i].init (acc.privateDicts[i].localSubrs->count);
664 if (unlikely (!closures.valid))
668 for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
670 hb_codepoint_t glyph;
671 if (!plan->old_gid_for_new_gid (i, &glyph))
673 const byte_str_t str = (*acc.charStrings)[glyph];
674 unsigned int fd = acc.fdSelect->get_fd (glyph);
675 if (unlikely (fd >= acc.fdCount))
678 cs_interpreter_t<ENV, OPSET, subr_subset_param_t> interp;
679 interp.env.init (str, acc, fd);
681 subr_subset_param_t param;
682 param.init (&parsed_charstrings[i],
683 &parsed_global_subrs, &parsed_local_subrs[fd],
684 closures.global_closure, closures.local_closures[fd],
687 if (unlikely (!interp.interpret (param)))
690 /* finalize parsed string esp. copy CFF1 width or CFF2 vsindex to the parsed charstring for encoding */
691 SUBSETTER::finalize_parsed_str (interp.env, param, parsed_charstrings[i]);
694 if (plan->drop_hints)
696 /* mark hint ops and arguments for drop */
697 for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
699 hb_codepoint_t glyph;
700 if (!plan->old_gid_for_new_gid (i, &glyph))
702 unsigned int fd = acc.fdSelect->get_fd (glyph);
703 if (unlikely (fd >= acc.fdCount))
705 subr_subset_param_t param;
706 param.init (&parsed_charstrings[i],
707 &parsed_global_subrs, &parsed_local_subrs[fd],
708 closures.global_closure, closures.local_closures[fd],
711 drop_hints_param_t drop;
712 if (drop_hints_in_str (parsed_charstrings[i], param, drop))
714 parsed_charstrings[i].set_hint_dropped ();
715 if (drop.vsindex_dropped)
716 parsed_charstrings[i].set_vsindex_dropped ();
720 /* after dropping hints recreate closures of actually used subrs */
722 for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
724 hb_codepoint_t glyph;
725 if (!plan->old_gid_for_new_gid (i, &glyph))
727 unsigned int fd = acc.fdSelect->get_fd (glyph);
728 if (unlikely (fd >= acc.fdCount))
730 subr_subset_param_t param;
731 param.init (&parsed_charstrings[i],
732 &parsed_global_subrs, &parsed_local_subrs[fd],
733 closures.global_closure, closures.local_closures[fd],
735 collect_subr_refs_in_str (parsed_charstrings[i], param);
739 remaps.create (closures);
744 bool encode_charstrings (str_buff_vec_t &buffArray) const
746 if (unlikely (!buffArray.resize (plan->num_output_glyphs ())))
748 for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
750 hb_codepoint_t glyph;
751 if (!plan->old_gid_for_new_gid (i, &glyph))
753 /* add an endchar only charstring for a missing glyph if CFF1 */
754 if (endchar_op != OpCode_Invalid) buffArray[i].push (endchar_op);
757 unsigned int fd = acc.fdSelect->get_fd (glyph);
758 if (unlikely (fd >= acc.fdCount))
760 if (unlikely (!encode_str (parsed_charstrings[i], fd, buffArray[i])))
766 bool encode_subrs (const parsed_cs_str_vec_t &subrs, const subr_remap_t& remap, unsigned int fd, str_buff_vec_t &buffArray) const
768 unsigned int count = remap.get_count ();
770 if (unlikely (!buffArray.resize (count)))
772 for (unsigned int old_num = 0; old_num < subrs.length; old_num++)
774 hb_codepoint_t new_num = remap[old_num];
775 if (new_num != CFF_UNDEF_CODE)
777 if (unlikely (!encode_str (subrs[old_num], fd, buffArray[new_num])))
784 bool encode_globalsubrs (str_buff_vec_t &buffArray)
786 return encode_subrs (parsed_global_subrs, remaps.global_remap, 0, buffArray);
789 bool encode_localsubrs (unsigned int fd, str_buff_vec_t &buffArray) const
791 return encode_subrs (parsed_local_subrs[fd], remaps.local_remaps[fd], fd, buffArray);
795 struct drop_hints_param_t
797 drop_hints_param_t ()
798 : seen_moveto (false),
799 ends_in_hint (false),
801 vsindex_dropped (false) {}
806 bool vsindex_dropped;
809 bool drop_hints_in_subr (parsed_cs_str_t &str, unsigned int pos,
810 parsed_cs_str_vec_t &subrs, unsigned int subr_num,
811 const subr_subset_param_t ¶m, drop_hints_param_t &drop)
813 drop.ends_in_hint = false;
814 bool has_hint = drop_hints_in_str (subrs[subr_num], param, drop);
816 /* if this subr ends with a stem hint (i.e., not a number; potential argument for moveto),
817 * then this entire subroutine must be a hint. drop its call. */
818 if (drop.ends_in_hint)
820 str.values[pos].set_drop ();
821 /* if this subr call is at the end of the parent subr, propagate the flag
822 * otherwise reset the flag */
823 if (!str.at_end (pos))
824 drop.ends_in_hint = false;
826 else if (drop.all_dropped)
828 str.values[pos].set_drop ();
834 /* returns true if it sees a hint op before the first moveto */
835 bool drop_hints_in_str (parsed_cs_str_t &str, const subr_subset_param_t ¶m, drop_hints_param_t &drop)
837 bool seen_hint = false;
839 for (unsigned int pos = 0; pos < str.values.length; pos++)
841 bool has_hint = false;
842 switch (str.values[pos].op)
844 case OpCode_callsubr:
845 has_hint = drop_hints_in_subr (str, pos,
846 *param.parsed_local_subrs, str.values[pos].subr_num,
850 case OpCode_callgsubr:
851 has_hint = drop_hints_in_subr (str, pos,
852 *param.parsed_global_subrs, str.values[pos].subr_num,
859 drop.seen_moveto = true;
862 case OpCode_hintmask:
863 case OpCode_cntrmask:
864 if (drop.seen_moveto)
866 str.values[pos].set_drop ();
876 str.values[pos].set_drop ();
877 if (str.at_end (pos))
878 drop.ends_in_hint = true;
881 case OpCode_dotsection:
882 str.values[pos].set_drop ();
891 for (int i = pos - 1; i >= 0; i--)
893 parsed_cs_op_t &csop = str.values[(unsigned)i];
894 if (csop.for_drop ())
897 if (csop.op == OpCode_vsindexcs)
898 drop.vsindex_dropped = true;
900 seen_hint |= has_hint;
904 /* Raise all_dropped flag if all operators except return are dropped from a subr.
905 * It may happen even after seeing the first moveto if a subr contains
906 * only (usually one) hintmask operator, then calls to this subr can be dropped.
908 drop.all_dropped = true;
909 for (unsigned int pos = 0; pos < str.values.length; pos++)
911 parsed_cs_op_t &csop = str.values[pos];
912 if (csop.op == OpCode_return)
914 if (!csop.for_drop ())
916 drop.all_dropped = false;
924 void collect_subr_refs_in_subr (parsed_cs_str_t &str, unsigned int pos,
925 unsigned int subr_num, parsed_cs_str_vec_t &subrs,
927 const subr_subset_param_t ¶m)
929 hb_set_add (closure, subr_num);
930 collect_subr_refs_in_str (subrs[subr_num], param);
933 void collect_subr_refs_in_str (parsed_cs_str_t &str, const subr_subset_param_t ¶m)
935 for (unsigned int pos = 0; pos < str.values.length; pos++)
937 if (!str.values[pos].for_drop ())
939 switch (str.values[pos].op)
941 case OpCode_callsubr:
942 collect_subr_refs_in_subr (str, pos,
943 str.values[pos].subr_num, *param.parsed_local_subrs,
944 param.local_closure, param);
947 case OpCode_callgsubr:
948 collect_subr_refs_in_subr (str, pos,
949 str.values[pos].subr_num, *param.parsed_global_subrs,
950 param.global_closure, param);
959 bool encode_str (const parsed_cs_str_t &str, const unsigned int fd, str_buff_t &buff) const
962 str_encoder_t encoder (buff);
964 /* if a prefix (CFF1 width or CFF2 vsindex) has been removed along with hints,
965 * re-insert it at the beginning of charstreing */
966 if (str.has_prefix () && str.is_hint_dropped ())
968 encoder.encode_num (str.prefix_num ());
969 if (str.prefix_op () != OpCode_Invalid)
970 encoder.encode_op (str.prefix_op ());
972 for (unsigned int i = 0; i < str.get_count(); i++)
974 const parsed_cs_op_t &opstr = str.values[i];
975 if (!opstr.for_drop () && !opstr.for_skip ())
979 case OpCode_callsubr:
980 encoder.encode_int (remaps.local_remaps[fd].biased_num (opstr.subr_num));
981 encoder.encode_op (OpCode_callsubr);
984 case OpCode_callgsubr:
985 encoder.encode_int (remaps.global_remap.biased_num (opstr.subr_num));
986 encoder.encode_op (OpCode_callgsubr);
990 encoder.copy_str (opstr.str);
995 return !encoder.is_error ();
1000 const hb_subset_plan_t *plan;
1002 subr_closures_t closures;
1004 parsed_cs_str_vec_t parsed_charstrings;
1005 parsed_cs_str_vec_t parsed_global_subrs;
1006 hb_vector_t<parsed_cs_str_vec_t> parsed_local_subrs;
1008 subr_remap_ts remaps;
1011 typedef typename SUBRS::count_type subr_count_type;
1014 } /* namespace CFF */
1017 hb_plan_subset_cff_fdselect (const hb_subset_plan_t *plan,
1018 unsigned int fdCount,
1019 const CFF::FDSelect &src, /* IN */
1020 unsigned int &subset_fd_count /* OUT */,
1021 unsigned int &subset_fdselect_size /* OUT */,
1022 unsigned int &subset_fdselect_format /* OUT */,
1023 hb_vector_t<CFF::code_pair_t> &fdselect_ranges /* OUT */,
1024 CFF::remap_t &fdmap /* OUT */);
1027 hb_serialize_cff_fdselect (hb_serialize_context_t *c,
1028 unsigned int num_glyphs,
1029 const CFF::FDSelect &src,
1030 unsigned int fd_count,
1031 unsigned int fdselect_format,
1033 const hb_vector_t<CFF::code_pair_t> &fdselect_ranges);
1035 #endif /* HB_SUBSET_CFF_COMMON_HH */