2 * Copyright © 2022 Google, 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 * Google Author(s): Garret Rieger
27 #ifndef HB_SUBSET_ACCELERATOR_HH
28 #define HB_SUBSET_ACCELERATOR_HH
34 #include "hb-multimap.hh"
37 extern HB_INTERNAL hb_user_data_key_t _hb_subset_accelerator_user_data_key;
40 struct cff_subset_accelerator_t;
44 struct SubtableUnicodesCache;
45 struct cff1_subset_accelerator_t;
46 struct cff2_subset_accelerator_t;
49 struct hb_subset_accelerator_t
51 static hb_user_data_key_t* user_data_key()
53 return &_hb_subset_accelerator_user_data_key;
56 static hb_subset_accelerator_t* create(hb_face_t *source,
57 const hb_map_t& unicode_to_gid_,
58 const hb_set_t& unicodes_,
60 hb_subset_accelerator_t* accel =
61 (hb_subset_accelerator_t*) hb_calloc (1, sizeof(hb_subset_accelerator_t));
63 if (unlikely (!accel)) return accel;
65 new (accel) hb_subset_accelerator_t (source,
73 static void destroy (void* p)
77 hb_subset_accelerator_t *accel = (hb_subset_accelerator_t *) p;
79 accel->~hb_subset_accelerator_t ();
84 hb_subset_accelerator_t (hb_face_t *source,
85 const hb_map_t& unicode_to_gid_,
86 const hb_set_t& unicodes_,
88 unicode_to_gid(unicode_to_gid_),
91 destroy_cmap_cache(nullptr),
93 source(hb_face_reference (source))
95 gid_to_unicodes.alloc (unicode_to_gid.get_population ());
96 for (const auto &_ : unicode_to_gid)
98 auto unicode = _.first;
100 gid_to_unicodes.add (gid, unicode);
104 HB_INTERNAL ~hb_subset_accelerator_t ();
108 mutable hb_mutex_t sanitized_table_cache_lock;
109 mutable hb_hashmap_t<hb_tag_t, hb::unique_ptr<hb_blob_t>> sanitized_table_cache;
111 hb_map_t unicode_to_gid;
112 hb_multimap_t gid_to_unicodes;
116 const OT::SubtableUnicodesCache* cmap_cache;
117 hb_destroy_func_t destroy_cmap_cache;
122 // TODO(garretrieger): cumulative glyf checksum map
124 bool in_error () const
126 return unicode_to_gid.in_error () ||
127 gid_to_unicodes.in_error () ||
128 unicodes.in_error () ||
129 sanitized_table_cache.in_error ();
133 #ifndef HB_NO_SUBSET_CFF
134 // These have to be immediately after source:
135 mutable hb_face_lazy_loader_t<OT::cff1_subset_accelerator_t, 1> cff1_accel;
136 mutable hb_face_lazy_loader_t<OT::cff2_subset_accelerator_t, 2> cff2_accel;
141 #endif /* HB_SUBSET_ACCELERATOR_HH */