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 */
25
26 #include "hb.hh"
27
28 #include "hb-subset-serialize.h"
29 #include "hb-repacker.hh"
30
31 /**
32 * hb_subset_serialize_or_fail:
33 * @table_tag: tag of the table being packed, needed to allow table specific optimizations.
34 * @hb_objects: raw array of struct hb_subset_serialize_object_t, which provides
35 * object graph info
36 * @num_hb_objs: number of hb_subset_serialize_object_t in the hb_objects array.
37 *
38 * Given the input object graph info, repack a table to eliminate offset overflows and
39 * serialize it into a continuous array of bytes. A nullptr is returned if the serializing attempt fails.
40 * Table specific optimizations (eg. extension promotion in GSUB/GPOS) may be performed.
41 * Passing HB_TAG_NONE will disable table specific optimizations.
42 *
43 * Since: 10.2.0
44 **/
45 HB_EXTERN hb_blob_t *
hb_subset_serialize_or_fail(hb_tag_t table_tag,hb_subset_serialize_object_t * hb_objects,unsigned num_hb_objs)46 hb_subset_serialize_or_fail (hb_tag_t table_tag,
47 hb_subset_serialize_object_t *hb_objects,
48 unsigned num_hb_objs)
49 {
50 hb_vector_t<const hb_subset_serialize_object_t *> packed;
51 packed.alloc (num_hb_objs + 1);
52 packed.push (nullptr);
53 for (unsigned i = 0 ; i < num_hb_objs ; i++)
54 packed.push (&(hb_objects[i]));
55
56 return hb_resolve_overflows (packed, table_tag, 20, true);
57 }
58