/src/harfbuzz/src/hb-subset-accelerator.hh
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2022 Google, Inc. |
3 | | * |
4 | | * This is part of HarfBuzz, a text shaping library. |
5 | | * |
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. |
11 | | * |
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 |
16 | | * DAMAGE. |
17 | | * |
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. |
23 | | * |
24 | | * Google Author(s): Garret Rieger |
25 | | */ |
26 | | |
27 | | #ifndef HB_SUBSET_ACCELERATOR_HH |
28 | | #define HB_SUBSET_ACCELERATOR_HH |
29 | | |
30 | | |
31 | | #include "hb.hh" |
32 | | |
33 | | #include "hb-map.hh" |
34 | | #include "hb-multimap.hh" |
35 | | #include "hb-set.hh" |
36 | | |
37 | | extern HB_INTERNAL hb_user_data_key_t _hb_subset_accelerator_user_data_key; |
38 | | |
39 | | namespace CFF { |
40 | | struct cff_subset_accelerator_t; |
41 | | } |
42 | | |
43 | | namespace OT { |
44 | | struct SubtableUnicodesCache; |
45 | | }; |
46 | | |
47 | | struct hb_subset_accelerator_t |
48 | | { |
49 | | static hb_user_data_key_t* user_data_key() |
50 | 0 | { |
51 | 0 | return &_hb_subset_accelerator_user_data_key; |
52 | 0 | } |
53 | | |
54 | | static hb_subset_accelerator_t* create(const hb_map_t& unicode_to_gid_, |
55 | | const hb_multimap_t gid_to_unicodes_, |
56 | | const hb_set_t& unicodes_, |
57 | 0 | bool has_seac_) { |
58 | 0 | hb_subset_accelerator_t* accel = |
59 | 0 | (hb_subset_accelerator_t*) hb_calloc (1, sizeof(hb_subset_accelerator_t)); |
60 | 0 |
|
61 | 0 | if (unlikely (!accel)) return accel; |
62 | 0 |
|
63 | 0 | new (accel) hb_subset_accelerator_t (unicode_to_gid_, |
64 | 0 | gid_to_unicodes_, |
65 | 0 | unicodes_, |
66 | 0 | has_seac_); |
67 | 0 |
|
68 | 0 | return accel; |
69 | 0 | } |
70 | | |
71 | | static void destroy (void* p) |
72 | 0 | { |
73 | 0 | if (!p) return; |
74 | 0 |
|
75 | 0 | hb_subset_accelerator_t *accel = (hb_subset_accelerator_t *) p; |
76 | 0 |
|
77 | 0 | accel->~hb_subset_accelerator_t (); |
78 | 0 |
|
79 | 0 | hb_free (accel); |
80 | 0 | } |
81 | | |
82 | | hb_subset_accelerator_t (const hb_map_t& unicode_to_gid_, |
83 | | const hb_multimap_t& gid_to_unicodes_, |
84 | | const hb_set_t& unicodes_, |
85 | | bool has_seac_) : |
86 | | unicode_to_gid(unicode_to_gid_), |
87 | | gid_to_unicodes (gid_to_unicodes_), |
88 | | unicodes(unicodes_), |
89 | | cmap_cache(nullptr), |
90 | | destroy_cmap_cache(nullptr), |
91 | | has_seac(has_seac_), |
92 | | cff_accelerator(nullptr), |
93 | 0 | destroy_cff_accelerator(nullptr) {} |
94 | | |
95 | | ~hb_subset_accelerator_t () |
96 | 0 | { |
97 | 0 | if (cff_accelerator && destroy_cff_accelerator) |
98 | 0 | destroy_cff_accelerator ((void*) cff_accelerator); |
99 | 0 |
|
100 | 0 | if (cmap_cache && destroy_cmap_cache) |
101 | 0 | destroy_cmap_cache ((void*) cmap_cache); |
102 | 0 | } |
103 | | |
104 | | // Generic |
105 | | |
106 | | mutable hb_mutex_t sanitized_table_cache_lock; |
107 | | mutable hb_hashmap_t<hb_tag_t, hb::unique_ptr<hb_blob_t>> sanitized_table_cache; |
108 | | |
109 | | const hb_map_t unicode_to_gid; |
110 | | const hb_multimap_t gid_to_unicodes; |
111 | | const hb_set_t unicodes; |
112 | | |
113 | | // cmap |
114 | | const OT::SubtableUnicodesCache* cmap_cache; |
115 | | hb_destroy_func_t destroy_cmap_cache; |
116 | | |
117 | | // CFF |
118 | | bool has_seac; |
119 | | const CFF::cff_subset_accelerator_t* cff_accelerator; |
120 | | hb_destroy_func_t destroy_cff_accelerator; |
121 | | |
122 | | // TODO(garretrieger): cumulative glyf checksum map |
123 | | |
124 | | bool in_error () const |
125 | 0 | { |
126 | 0 | return unicode_to_gid.in_error () || |
127 | 0 | gid_to_unicodes.in_error () || |
128 | 0 | unicodes.in_error () || |
129 | 0 | sanitized_table_cache.in_error (); |
130 | 0 | } |
131 | | }; |
132 | | |
133 | | |
134 | | #endif /* HB_SUBSET_ACCELERATOR_HH */ |