Garret Rieger | 6a45e5d | 2018-02-06 16:04:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2018 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 | * |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 24 | * Google Author(s): Garret Rieger, Roderick Sheeter |
Garret Rieger | 6a45e5d | 2018-02-06 16:04:09 -0800 | [diff] [blame] | 25 | */ |
| 26 | |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 27 | #include "hb-open-type-private.hh" |
Garret Rieger | 53aa0e9 | 2018-02-06 17:05:22 -0800 | [diff] [blame] | 28 | #include "hb-ot-glyf-table.hh" |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 29 | #include "hb-set.h" |
Garret Rieger | 6a45e5d | 2018-02-06 16:04:09 -0800 | [diff] [blame] | 30 | #include "hb-subset-glyf.hh" |
Garret Rieger | 2130392 | 2018-02-16 17:01:00 -0700 | [diff] [blame] | 31 | #include "hb-subset-plan.hh" |
Garret Rieger | 6a45e5d | 2018-02-06 16:04:09 -0800 | [diff] [blame] | 32 | |
Ebrahim Byagowi | 203b647 | 2018-02-11 01:00:03 +0330 | [diff] [blame] | 33 | static bool |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 34 | _calculate_glyf_and_loca_prime_size (const OT::glyf::accelerator_t &glyf, |
Behdad Esfahbod | 5c3112a | 2018-05-01 19:07:04 -0400 | [diff] [blame] | 35 | hb_vector_t<hb_codepoint_t> &glyph_ids, |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 36 | hb_bool_t drop_hints, |
| 37 | bool *use_short_loca /* OUT */, |
| 38 | unsigned int *glyf_size /* OUT */, |
| 39 | unsigned int *loca_size /* OUT */, |
Behdad Esfahbod | 5c3112a | 2018-05-01 19:07:04 -0400 | [diff] [blame] | 40 | hb_vector_t<unsigned int> *instruction_ranges /* OUT */) |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 41 | { |
| 42 | unsigned int total = 0; |
Behdad Esfahbod | fd0bde6 | 2018-02-13 16:35:30 -0800 | [diff] [blame] | 43 | for (unsigned int i = 0; i < glyph_ids.len; i++) |
| 44 | { |
Rod Sheeter | 59c658c | 2018-02-08 19:22:47 -0800 | [diff] [blame] | 45 | hb_codepoint_t next_glyph = glyph_ids[i]; |
Garret Rieger | 1396614 | 2018-03-20 16:55:42 -0700 | [diff] [blame] | 46 | if (!instruction_ranges->resize (instruction_ranges->len + 2)) |
| 47 | { |
Garret Rieger | 45def99 | 2018-03-20 17:28:47 -0700 | [diff] [blame] | 48 | DEBUG_MSG(SUBSET, nullptr, "Failed to resize instruction_ranges."); |
Garret Rieger | 1396614 | 2018-03-20 16:55:42 -0700 | [diff] [blame] | 49 | return false; |
| 50 | } |
| 51 | unsigned int *instruction_start = &(*instruction_ranges)[instruction_ranges->len - 2]; |
Rod Sheeter | 903771b | 2018-02-26 19:50:06 -0800 | [diff] [blame] | 52 | *instruction_start = 0; |
Garret Rieger | 1396614 | 2018-03-20 16:55:42 -0700 | [diff] [blame] | 53 | unsigned int *instruction_end = &(*instruction_ranges)[instruction_ranges->len - 1]; |
Rod Sheeter | 903771b | 2018-02-26 19:50:06 -0800 | [diff] [blame] | 54 | *instruction_end = 0; |
Rod Sheeter | 9bd6d25 | 2018-02-23 13:05:58 -0800 | [diff] [blame] | 55 | |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 56 | unsigned int start_offset, end_offset; |
Rod Sheeter | 1454d82 | 2018-02-23 17:49:23 -0800 | [diff] [blame] | 57 | if (unlikely (!(glyf.get_offsets(next_glyph, &start_offset, &end_offset) |
Rod Sheeter | 903771b | 2018-02-26 19:50:06 -0800 | [diff] [blame] | 58 | && glyf.remove_padding(start_offset, &end_offset)))) |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 59 | { |
| 60 | DEBUG_MSG(SUBSET, nullptr, "Invalid gid %d", next_glyph); |
| 61 | continue; |
| 62 | } |
Rod Sheeter | 9bd6d25 | 2018-02-23 13:05:58 -0800 | [diff] [blame] | 63 | if (end_offset - start_offset < OT::glyf::GlyphHeader::static_size) |
| 64 | continue; /* 0-length glyph */ |
| 65 | |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 66 | if (drop_hints) |
| 67 | { |
| 68 | if (unlikely (!glyf.get_instruction_offsets(start_offset, end_offset, |
Rod Sheeter | 903771b | 2018-02-26 19:50:06 -0800 | [diff] [blame] | 69 | instruction_start, instruction_end))) |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 70 | { |
| 71 | DEBUG_MSG(SUBSET, nullptr, "Unable to get instruction offsets for %d", next_glyph); |
| 72 | return false; |
| 73 | } |
| 74 | } |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 75 | |
Rod Sheeter | 903771b | 2018-02-26 19:50:06 -0800 | [diff] [blame] | 76 | total += end_offset - start_offset - (*instruction_end - *instruction_start); |
Rod Sheeter | 9bd6d25 | 2018-02-23 13:05:58 -0800 | [diff] [blame] | 77 | /* round2 so short loca will work */ |
| 78 | total += total % 2; |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 81 | *glyf_size = total; |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 82 | *use_short_loca = (total <= 131070); |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 83 | *loca_size = (glyph_ids.len + 1) |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 84 | * (*use_short_loca ? sizeof(OT::HBUINT16) : sizeof(OT::HBUINT32)); |
| 85 | |
| 86 | DEBUG_MSG(SUBSET, nullptr, "preparing to subset glyf: final size %d, loca size %d, using %s loca", |
| 87 | total, |
| 88 | *loca_size, |
| 89 | *use_short_loca ? "short" : "long"); |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 90 | return true; |
| 91 | } |
| 92 | |
Garret Rieger | 0ab73e5 | 2018-02-20 15:33:03 -0800 | [diff] [blame] | 93 | static bool |
| 94 | _write_loca_entry (unsigned int id, |
| 95 | unsigned int offset, |
| 96 | bool is_short, |
| 97 | void *loca_prime, |
| 98 | unsigned int loca_size) |
| 99 | { |
| 100 | unsigned int entry_size = is_short ? sizeof (OT::HBUINT16) : sizeof (OT::HBUINT32); |
| 101 | if ((id + 1) * entry_size <= loca_size) |
| 102 | { |
| 103 | if (is_short) { |
| 104 | ((OT::HBUINT16*) loca_prime) [id].set (offset / 2); |
| 105 | } else { |
| 106 | ((OT::HBUINT32*) loca_prime) [id].set (offset); |
| 107 | } |
| 108 | return true; |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 109 | } |
Garret Rieger | 0ab73e5 | 2018-02-20 15:33:03 -0800 | [diff] [blame] | 110 | |
| 111 | // Offset was not written because the write is out of bounds. |
| 112 | DEBUG_MSG (SUBSET, |
| 113 | nullptr, |
| 114 | "WARNING: Attempted to write an out of bounds loca entry at index %d. Loca size is %d.", |
| 115 | id, |
| 116 | loca_size); |
| 117 | return false; |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Garret Rieger | 2130392 | 2018-02-16 17:01:00 -0700 | [diff] [blame] | 120 | static void |
| 121 | _update_components (hb_subset_plan_t * plan, |
| 122 | char * glyph_start, |
| 123 | unsigned int length) |
Garret Rieger | 2130392 | 2018-02-16 17:01:00 -0700 | [diff] [blame] | 124 | { |
| 125 | OT::glyf::CompositeGlyphHeader::Iterator iterator; |
| 126 | if (OT::glyf::CompositeGlyphHeader::get_iterator (glyph_start, |
| 127 | length, |
| 128 | &iterator)) |
| 129 | { |
| 130 | do |
| 131 | { |
| 132 | hb_codepoint_t new_gid; |
Garret Rieger | 251cc97 | 2018-05-30 12:23:51 -0700 | [diff] [blame] | 133 | if (!plan->new_gid_for_old_gid (iterator.current->glyphIndex, |
| 134 | &new_gid)) |
Garret Rieger | 2130392 | 2018-02-16 17:01:00 -0700 | [diff] [blame] | 135 | continue; |
| 136 | |
| 137 | ((OT::glyf::CompositeGlyphHeader *) iterator.current)->glyphIndex.set (new_gid); |
| 138 | } while (iterator.move_to_next()); |
| 139 | } |
| 140 | } |
| 141 | |
Rod Sheeter | 20d5739 | 2018-02-28 11:15:08 -0800 | [diff] [blame] | 142 | static bool _remove_composite_instruction_flag(char *glyf_prime, unsigned int length) |
| 143 | { |
| 144 | /* remove WE_HAVE_INSTRUCTIONS from flags in dest */ |
| 145 | OT::glyf::CompositeGlyphHeader::Iterator composite_it; |
| 146 | if (unlikely (!OT::glyf::CompositeGlyphHeader::get_iterator (glyf_prime, length, &composite_it))) return false; |
| 147 | const OT::glyf::CompositeGlyphHeader *glyph; |
| 148 | do { |
| 149 | glyph = composite_it.current; |
| 150 | OT::HBUINT16 *flags = const_cast<OT::HBUINT16 *> (&glyph->flags); |
| 151 | flags->set ( (uint16_t) *flags & ~OT::glyf::CompositeGlyphHeader::WE_HAVE_INSTRUCTIONS); |
| 152 | } while (composite_it.move_to_next()); |
| 153 | return true; |
| 154 | } |
| 155 | |
Ebrahim Byagowi | 203b647 | 2018-02-11 01:00:03 +0330 | [diff] [blame] | 156 | static bool |
Garret Rieger | 2130392 | 2018-02-16 17:01:00 -0700 | [diff] [blame] | 157 | _write_glyf_and_loca_prime (hb_subset_plan_t *plan, |
| 158 | const OT::glyf::accelerator_t &glyf, |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 159 | const char *glyf_data, |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 160 | bool use_short_loca, |
Behdad Esfahbod | 5c3112a | 2018-05-01 19:07:04 -0400 | [diff] [blame] | 161 | hb_vector_t<unsigned int> &instruction_ranges, |
Garret Rieger | 0ab73e5 | 2018-02-20 15:33:03 -0800 | [diff] [blame] | 162 | unsigned int glyf_prime_size, |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 163 | char *glyf_prime_data /* OUT */, |
Garret Rieger | 0ab73e5 | 2018-02-20 15:33:03 -0800 | [diff] [blame] | 164 | unsigned int loca_prime_size, |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 165 | char *loca_prime_data /* OUT */) |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 166 | { |
Garret Rieger | 251cc97 | 2018-05-30 12:23:51 -0700 | [diff] [blame] | 167 | hb_vector_t<hb_codepoint_t> &glyph_ids = plan->glyphs; |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 168 | char *glyf_prime_data_next = glyf_prime_data; |
| 169 | |
Garret Rieger | 0ab73e5 | 2018-02-20 15:33:03 -0800 | [diff] [blame] | 170 | bool success = true; |
Behdad Esfahbod | fd0bde6 | 2018-02-13 16:35:30 -0800 | [diff] [blame] | 171 | for (unsigned int i = 0; i < glyph_ids.len; i++) |
| 172 | { |
| 173 | unsigned int start_offset, end_offset; |
Rod Sheeter | 1454d82 | 2018-02-23 17:49:23 -0800 | [diff] [blame] | 174 | if (unlikely (!(glyf.get_offsets (glyph_ids[i], &start_offset, &end_offset) |
Rod Sheeter | 903771b | 2018-02-26 19:50:06 -0800 | [diff] [blame] | 175 | && glyf.remove_padding(start_offset, &end_offset)))) |
Behdad Esfahbod | fd0bde6 | 2018-02-13 16:35:30 -0800 | [diff] [blame] | 176 | end_offset = start_offset = 0; |
Garret Rieger | 07851aa | 2018-03-26 20:56:56 -0600 | [diff] [blame] | 177 | |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 178 | unsigned int instruction_start = instruction_ranges[i * 2]; |
| 179 | unsigned int instruction_end = instruction_ranges[i * 2 + 1]; |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 180 | |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 181 | int length = end_offset - start_offset - (instruction_end - instruction_start); |
Garret Rieger | a998eee | 2018-02-20 16:48:52 -0800 | [diff] [blame] | 182 | |
| 183 | if (glyf_prime_data_next + length > glyf_prime_data + glyf_prime_size) |
| 184 | { |
| 185 | DEBUG_MSG (SUBSET, |
| 186 | nullptr, |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 187 | "WARNING: Attempted to write an out of bounds glyph entry for gid %d (length %d)", |
| 188 | i, length); |
Garret Rieger | a998eee | 2018-02-20 16:48:52 -0800 | [diff] [blame] | 189 | return false; |
| 190 | } |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 191 | |
| 192 | if (instruction_start == instruction_end) |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 193 | memcpy (glyf_prime_data_next, glyf_data + start_offset, length); |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 194 | else |
| 195 | { |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 196 | memcpy (glyf_prime_data_next, glyf_data + start_offset, instruction_start - start_offset); |
| 197 | memcpy (glyf_prime_data_next + instruction_start - start_offset, glyf_data + instruction_end, end_offset - instruction_end); |
Rod Sheeter | b3f1a04 | 2018-02-28 11:41:24 -0800 | [diff] [blame] | 198 | /* if the instructions end at the end this was a composite glyph, else simple */ |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 199 | if (instruction_end == end_offset) |
Rod Sheeter | 6836a82 | 2018-02-27 20:51:12 -0800 | [diff] [blame] | 200 | { |
Rod Sheeter | 20d5739 | 2018-02-28 11:15:08 -0800 | [diff] [blame] | 201 | if (unlikely (!_remove_composite_instruction_flag (glyf_prime_data_next, length))) return false; |
Rod Sheeter | 6836a82 | 2018-02-27 20:51:12 -0800 | [diff] [blame] | 202 | } |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 203 | else |
Rod Sheeter | 9bd6d25 | 2018-02-23 13:05:58 -0800 | [diff] [blame] | 204 | /* zero instruction length, which is just before instruction_start */ |
| 205 | memset (glyf_prime_data_next + instruction_start - start_offset - 2, 0, 2); |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 206 | } |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 207 | |
Garret Rieger | 0ab73e5 | 2018-02-20 15:33:03 -0800 | [diff] [blame] | 208 | success = success && _write_loca_entry (i, |
| 209 | glyf_prime_data_next - glyf_prime_data, |
| 210 | use_short_loca, |
| 211 | loca_prime_data, |
| 212 | loca_prime_size); |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 213 | _update_components (plan, glyf_prime_data_next, length); |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 214 | |
Garret Rieger | 07851aa | 2018-03-26 20:56:56 -0600 | [diff] [blame] | 215 | // TODO: don't align to two bytes if using long loca. |
| 216 | glyf_prime_data_next += length + (length % 2); // Align to 2 bytes for short loca. |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Garret Rieger | 0ab73e5 | 2018-02-20 15:33:03 -0800 | [diff] [blame] | 219 | success = success && _write_loca_entry (glyph_ids.len, |
| 220 | glyf_prime_data_next - glyf_prime_data, |
| 221 | use_short_loca, |
| 222 | loca_prime_data, |
| 223 | loca_prime_size); |
| 224 | return success; |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Ebrahim Byagowi | 203b647 | 2018-02-11 01:00:03 +0330 | [diff] [blame] | 227 | static bool |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 228 | _hb_subset_glyf_and_loca (const OT::glyf::accelerator_t &glyf, |
| 229 | const char *glyf_data, |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 230 | hb_subset_plan_t *plan, |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 231 | bool *use_short_loca, |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 232 | hb_blob_t **glyf_prime /* OUT */, |
| 233 | hb_blob_t **loca_prime /* OUT */) |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 234 | { |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 235 | // TODO(grieger): Sanity check allocation size for the new table. |
Garret Rieger | 251cc97 | 2018-05-30 12:23:51 -0700 | [diff] [blame] | 236 | hb_vector_t<hb_codepoint_t> &glyphs_to_retain = plan->glyphs; |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 237 | |
| 238 | unsigned int glyf_prime_size; |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 239 | unsigned int loca_prime_size; |
Behdad Esfahbod | 5c3112a | 2018-05-01 19:07:04 -0400 | [diff] [blame] | 240 | hb_vector_t<unsigned int> instruction_ranges; |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 241 | instruction_ranges.init(); |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 242 | |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 243 | if (unlikely (!_calculate_glyf_and_loca_prime_size (glyf, |
| 244 | glyphs_to_retain, |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 245 | plan->drop_hints, |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 246 | use_short_loca, |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 247 | &glyf_prime_size, |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 248 | &loca_prime_size, |
| 249 | &instruction_ranges))) { |
Behdad Esfahbod | a60ba79 | 2018-05-01 19:01:25 -0400 | [diff] [blame] | 250 | instruction_ranges.fini(); |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 251 | return false; |
| 252 | } |
| 253 | |
Rod Sheeter | 0ac8c0c | 2018-02-23 17:43:00 -0800 | [diff] [blame] | 254 | char *glyf_prime_data = (char *) calloc (1, glyf_prime_size); |
| 255 | char *loca_prime_data = (char *) calloc (1, loca_prime_size); |
Garret Rieger | 2130392 | 2018-02-16 17:01:00 -0700 | [diff] [blame] | 256 | if (unlikely (!_write_glyf_and_loca_prime (plan, glyf, glyf_data, |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 257 | *use_short_loca, |
Rod Sheeter | 4f07437 | 2018-02-21 22:23:05 -0800 | [diff] [blame] | 258 | instruction_ranges, |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 259 | glyf_prime_size, glyf_prime_data, |
| 260 | loca_prime_size, loca_prime_data))) { |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 261 | free (glyf_prime_data); |
Garret Rieger | 0ab73e5 | 2018-02-20 15:33:03 -0800 | [diff] [blame] | 262 | free (loca_prime_data); |
Behdad Esfahbod | a60ba79 | 2018-05-01 19:01:25 -0400 | [diff] [blame] | 263 | instruction_ranges.fini(); |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 264 | return false; |
| 265 | } |
Behdad Esfahbod | a60ba79 | 2018-05-01 19:01:25 -0400 | [diff] [blame] | 266 | instruction_ranges.fini(); |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 267 | |
| 268 | *glyf_prime = hb_blob_create (glyf_prime_data, |
| 269 | glyf_prime_size, |
| 270 | HB_MEMORY_MODE_READONLY, |
| 271 | glyf_prime_data, |
| 272 | free); |
Garret Rieger | 8e9fd6f | 2018-02-07 19:01:21 -0800 | [diff] [blame] | 273 | *loca_prime = hb_blob_create (loca_prime_data, |
| 274 | loca_prime_size, |
| 275 | HB_MEMORY_MODE_READONLY, |
| 276 | loca_prime_data, |
| 277 | free); |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 278 | return true; |
| 279 | } |
| 280 | |
Garret Rieger | 6a45e5d | 2018-02-06 16:04:09 -0800 | [diff] [blame] | 281 | /** |
| 282 | * hb_subset_glyf: |
| 283 | * Subsets the glyph table according to a provided plan. |
| 284 | * |
| 285 | * Return value: subsetted glyf table. |
| 286 | * |
| 287 | * Since: 1.7.5 |
| 288 | **/ |
| 289 | bool |
Garret Rieger | f9c665f | 2018-02-07 16:53:18 -0800 | [diff] [blame] | 290 | hb_subset_glyf_and_loca (hb_subset_plan_t *plan, |
Garret Rieger | 1582eab | 2018-02-09 12:52:08 -0800 | [diff] [blame] | 291 | bool *use_short_loca, /* OUT */ |
| 292 | hb_blob_t **glyf_prime, /* OUT */ |
Garret Rieger | f9c665f | 2018-02-07 16:53:18 -0800 | [diff] [blame] | 293 | hb_blob_t **loca_prime /* OUT */) |
Garret Rieger | 6a45e5d | 2018-02-06 16:04:09 -0800 | [diff] [blame] | 294 | { |
Behdad Esfahbod | ed7b2e5 | 2018-08-01 23:59:09 -0700 | [diff] [blame^] | 295 | hb_blob_t *glyf_blob = hb_sanitize_context_t ().reference_table<OT::glyf> (plan->source); |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 296 | const char *glyf_data = hb_blob_get_data(glyf_blob, nullptr); |
Garret Rieger | 53aa0e9 | 2018-02-06 17:05:22 -0800 | [diff] [blame] | 297 | |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 298 | OT::glyf::accelerator_t glyf; |
Rod Sheeter | fa87770 | 2018-02-14 14:16:25 -0800 | [diff] [blame] | 299 | glyf.init(plan->source); |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 300 | bool result = _hb_subset_glyf_and_loca (glyf, |
| 301 | glyf_data, |
Garret Rieger | 2130392 | 2018-02-16 17:01:00 -0700 | [diff] [blame] | 302 | plan, |
Garret Rieger | d18decd | 2018-02-09 18:41:21 -0800 | [diff] [blame] | 303 | use_short_loca, |
| 304 | glyf_prime, |
| 305 | loca_prime); |
Garret Rieger | 99967e2 | 2018-02-23 15:45:45 -0800 | [diff] [blame] | 306 | |
| 307 | hb_blob_destroy (glyf_blob); |
Garret Rieger | 0a5d144 | 2018-02-07 13:09:54 -0800 | [diff] [blame] | 308 | glyf.fini(); |
Garret Rieger | 4e1abe2 | 2018-02-07 13:28:11 -0800 | [diff] [blame] | 309 | |
| 310 | return result; |
Garret Rieger | 6a45e5d | 2018-02-06 16:04:09 -0800 | [diff] [blame] | 311 | } |