2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2012 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
29 #include "hb-private.hh"
31 #include "hb-face-private.hh"
32 #include "hb-open-file-private.hh"
33 #include "hb-ot-head-table.hh"
34 #include "hb-ot-maxp-table.hh"
41 const hb_face_t _hb_face_nil = {
42 HB_OBJECT_HEADER_STATIC,
46 NULL, /* reference_table_func */
54 hb_face_t::NOTHING, /* dirty */
57 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
58 #include "hb-shaper-list.hh"
59 #undef HB_SHAPER_IMPLEMENT
62 NULL, /* shape_plans */
67 * hb_face_create_for_tables:
68 * @reference_table_func: (closure user_data) (destroy destroy) (scope notified):
74 * Return value: (transfer full)
79 hb_face_create_for_tables (hb_reference_table_func_t reference_table_func,
81 hb_destroy_func_t destroy)
85 if (!reference_table_func || !(face = hb_object_create<hb_face_t> ())) {
88 return hb_face_get_empty ();
91 face->reference_table_func = reference_table_func;
92 face->user_data = user_data;
93 face->destroy = destroy;
96 face->num_glyphs = (unsigned int) -1;
102 typedef struct hb_face_for_data_closure_t {
105 } hb_face_for_data_closure_t;
107 static hb_face_for_data_closure_t *
108 _hb_face_for_data_closure_create (hb_blob_t *blob, unsigned int index)
110 hb_face_for_data_closure_t *closure;
112 closure = (hb_face_for_data_closure_t *) calloc (1, sizeof (hb_face_for_data_closure_t));
113 if (unlikely (!closure))
116 closure->blob = blob;
117 closure->index = index;
123 _hb_face_for_data_closure_destroy (hb_face_for_data_closure_t *closure)
125 hb_blob_destroy (closure->blob);
130 _hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data)
132 hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) user_data;
134 if (tag == HB_TAG_NONE)
135 return hb_blob_reference (data->blob);
137 const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob);
138 const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index);
140 const OT::OpenTypeTable &table = ot_face.get_table_by_tag (tag);
142 hb_blob_t *blob = hb_blob_create_sub_blob (data->blob, table.offset, table.length);
148 * hb_face_create: (Xconstructor)
154 * Return value: (transfer full):
159 hb_face_create (hb_blob_t *blob,
164 if (unlikely (!blob))
165 blob = hb_blob_get_empty ();
167 hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (OT::Sanitizer<OT::OpenTypeFontFile>::sanitize (hb_blob_reference (blob)), index);
169 if (unlikely (!closure))
170 return hb_face_get_empty ();
172 face = hb_face_create_for_tables (_hb_face_for_data_reference_table,
174 (hb_destroy_func_t) _hb_face_for_data_closure_destroy);
186 * Return value: (transfer full)
191 hb_face_get_empty (void)
193 return const_cast<hb_face_t *> (&_hb_face_nil);
198 * hb_face_reference: (skip)
208 hb_face_reference (hb_face_t *face)
210 return hb_object_reference (face);
214 * hb_face_destroy: (skip)
222 hb_face_destroy (hb_face_t *face)
224 if (!hb_object_destroy (face)) return;
226 for (hb_face_t::plan_node_t *node = face->shape_plans; node; )
228 hb_face_t::plan_node_t *next = node->next;
229 hb_shape_plan_destroy (node->shape_plan);
234 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, face);
235 #include "hb-shaper-list.hh"
236 #undef HB_SHAPER_IMPLEMENT
239 face->destroy (face->user_data);
245 * hb_face_set_user_data: (skip)
259 hb_face_set_user_data (hb_face_t *face,
260 hb_user_data_key_t *key,
262 hb_destroy_func_t destroy,
265 return hb_object_set_user_data (face, key, data, destroy, replace);
269 * hb_face_get_user_data: (skip)
275 * Return value: (transfer none):
280 hb_face_get_user_data (hb_face_t *face,
281 hb_user_data_key_t *key)
283 return hb_object_get_user_data (face, key);
287 * hb_face_make_immutable:
295 hb_face_make_immutable (hb_face_t *face)
297 if (unlikely (hb_object_is_inert (face)))
300 face->immutable = true;
304 * hb_face_is_immutable:
314 hb_face_is_immutable (hb_face_t *face)
316 return face->immutable;
321 * hb_face_reference_table:
327 * Return value: (transfer full):
332 hb_face_reference_table (hb_face_t *face,
335 return face->reference_table (tag);
339 * hb_face_reference_blob:
344 * Return value: (transfer full):
349 hb_face_reference_blob (hb_face_t *face)
351 return face->reference_table (HB_TAG_NONE);
364 hb_face_set_index (hb_face_t *face,
370 if (face->index == index)
373 face->dirty |= face->INDEX;
389 hb_face_get_index (hb_face_t *face)
404 hb_face_set_upem (hb_face_t *face,
410 if (face->upem == upem)
413 face->dirty |= face->UPEM;
429 hb_face_get_upem (hb_face_t *face)
431 return face->get_upem ();
435 hb_face_t::load_upem (void) const
437 hb_blob_t *head_blob = OT::Sanitizer<OT::head>::sanitize (reference_table (HB_OT_TAG_head));
438 const OT::head *head_table = OT::Sanitizer<OT::head>::lock_instance (head_blob);
439 upem = head_table->get_upem ();
440 hb_blob_destroy (head_blob);
444 * hb_face_set_glyph_count:
453 hb_face_set_glyph_count (hb_face_t *face,
454 unsigned int glyph_count)
459 if (face->num_glyphs == glyph_count)
462 face->dirty |= face->NUM_GLYPHS;
464 face->num_glyphs = glyph_count;
468 * hb_face_get_glyph_count:
478 hb_face_get_glyph_count (hb_face_t *face)
480 return face->get_num_glyphs ();
484 hb_face_t::load_num_glyphs (void) const
486 hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>::sanitize (reference_table (HB_OT_TAG_maxp));
487 const OT::maxp *maxp_table = OT::Sanitizer<OT::maxp>::lock_instance (maxp_blob);
488 num_glyphs = maxp_table->get_num_glyphs ();
489 hb_blob_destroy (maxp_blob);