2 * Copyright (C) 2009 Red Hat, Inc.
4 * This is part of HarfBuzz, an OpenType Layout engine 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 * Red Hat Author(s): Behdad Esfahbod
27 #include "hb-private.h"
29 #include "hb-font-private.h"
30 #include "hb-ot-layout-private.h"
32 #include "hb-open-file-private.hh"
39 static hb_font_callbacks_t _hb_font_callbacks_nil = {
40 HB_REFERENCE_COUNT_INVALID /* ref_count */
42 hb_font_get_glyph_func_t glyph_func;
43 hb_font_get_contour_point_func_t contour_point_func;
44 hb_font_get_glyph_metrics_func_t glyph_metrics_func;
45 hb_font_get_kerning_func_t kerning_func;
50 hb_font_callbacks_create (void)
52 hb_font_callbacks_t *fcallbacks;
54 if (!HB_OBJECT_DO_CREATE (hb_font_callbacks_t, fcallbacks))
55 return &_hb_font_callbacks_nil;
61 hb_font_callbacks_reference (hb_font_callbacks_t *fcallbacks)
63 HB_OBJECT_DO_REFERENCE (fcallbacks);
67 hb_font_callbacks_get_reference_count (hb_font_callbacks_t *fcallbacks)
69 HB_OBJECT_DO_GET_REFERENCE_COUNT (fcallbacks);
73 hb_font_callbacks_destroy (hb_font_callbacks_t *fcallbacks)
75 HB_OBJECT_DO_DESTROY (fcallbacks);
81 hb_font_callbacks_copy (hb_font_callbacks_t *other_fcallbacks)
83 hb_font_callbacks_t *fcallbacks;
85 if (!HB_OBJECT_DO_CREATE (hb_font_callbacks_t, fcallbacks))
86 return &_hb_font_callbacks_nil;
88 *fcallbacks = *other_fcallbacks;
90 /* re-init refcount */
91 HB_OBJECT_DO_INIT (fcallbacks);
99 * hb_unicode_callbacks_t
102 static hb_unicode_callbacks_t _hb_unicode_callbacks_nil = {
103 HB_REFERENCE_COUNT_INVALID /* ref_count */
105 hb_unicode_get_general_category_func_t general_category_func);
106 hb_unicode_get_combining_class_func_t combining_class_func);
107 hb_unicode_get_mirroring_char_func_t mirroring_char_func);
108 hb_unicode_get_script_func_t script_func);
109 hb_unicode_get_eastasian_width_func_t eastasian_width_func);
113 hb_unicode_callbacks_t *
114 hb_unicode_callbacks_create (void)
116 hb_unicode_callbacks_t *ucallbacks;
118 if (!HB_OBJECT_DO_CREATE (hb_unicode_callbacks_t, ucallbacks))
119 return &_hb_unicode_callbacks_nil;
124 hb_unicode_callbacks_t *
125 hb_unicode_callbacks_reference (hb_unicode_callbacks_t *ucallbacks)
127 HB_OBJECT_DO_REFERENCE (ucallbacks);
131 hb_unicode_callbacks_get_reference_count (hb_unicode_callbacks_t *ucallbacks)
133 HB_OBJECT_DO_GET_REFERENCE_COUNT (ucallbacks);
137 hb_unicode_callbacks_destroy (hb_unicode_callbacks_t *ucallbacks)
139 HB_OBJECT_DO_DESTROY (ucallbacks);
144 hb_unicode_callbacks_t *
145 hb_unicode_callbacks_copy (hb_unicode_callbacks_t *other_ucallbacks)
147 hb_unicode_callbacks_t *ucallbacks;
149 if (!HB_OBJECT_DO_CREATE (hb_unicode_callbacks_t, ucallbacks))
150 return &_hb_unicode_callbacks_nil;
152 *ucallbacks = *other_ucallbacks;
153 HB_OBJECT_DO_INIT (ucallbacks);
165 _hb_face_get_table_from_blob (hb_tag_t tag, void *user_data)
167 hb_face_t *face = (hb_face_t *) user_data;
169 const OpenTypeFontFile &ot_file = Sanitizer<OpenTypeFontFile>::lock_instance (face->blob);
170 const OpenTypeFontFace &ot_face = ot_file.get_face (face->index);
172 const OpenTypeTable &table = ot_face.get_table_by_tag (tag);
174 hb_blob_t *blob = hb_blob_create_sub_blob (face->blob, table.offset, table.length);
176 hb_blob_unlock (face->blob);
181 static hb_face_t _hb_face_nil = {
182 HB_REFERENCE_COUNT_INVALID, /* ref_count */
187 NULL, /* get_table */
189 NULL, /* user_data */
191 NULL, /* fcallbacks */
192 NULL /* ucallbacks */
196 hb_face_create_for_tables (hb_get_table_func_t get_table,
197 hb_destroy_func_t destroy,
202 if (!HB_OBJECT_DO_CREATE (hb_face_t, face)) {
205 return &_hb_face_nil;
208 face->get_table = get_table;
209 face->destroy = destroy;
210 face->user_data = user_data;
212 _hb_ot_layout_init (face);
218 hb_face_create_for_data (hb_blob_t *blob,
223 if (!HB_OBJECT_DO_CREATE (hb_face_t, face))
224 return &_hb_face_nil;
226 face->blob = Sanitizer<OpenTypeFontFile>::sanitize (hb_blob_reference (blob));
228 face->get_table = _hb_face_get_table_from_blob;
229 face->user_data = face;
231 _hb_ot_layout_init (face);
237 hb_face_reference (hb_face_t *face)
239 HB_OBJECT_DO_REFERENCE (face);
243 hb_face_get_reference_count (hb_face_t *face)
245 HB_OBJECT_DO_GET_REFERENCE_COUNT (face);
249 hb_face_destroy (hb_face_t *face)
251 HB_OBJECT_DO_DESTROY (face);
253 _hb_ot_layout_fini (face);
255 hb_blob_destroy (face->blob);
258 face->destroy (face->user_data);
260 hb_font_callbacks_destroy (face->fcallbacks);
261 hb_unicode_callbacks_destroy (face->ucallbacks);
267 hb_face_set_font_callbacks (hb_face_t *face,
268 hb_font_callbacks_t *fcallbacks)
270 if (HB_OBJECT_IS_INERT (face))
273 hb_font_callbacks_reference (fcallbacks);
274 hb_font_callbacks_destroy (face->fcallbacks);
275 face->fcallbacks = fcallbacks;
279 hb_face_set_unicode_callbacks (hb_face_t *face,
280 hb_unicode_callbacks_t *ucallbacks)
282 if (HB_OBJECT_IS_INERT (face))
285 hb_unicode_callbacks_reference (ucallbacks);
286 hb_unicode_callbacks_destroy (face->ucallbacks);
287 face->ucallbacks = ucallbacks;
291 hb_face_get_table (hb_face_t *face,
294 if (HB_UNLIKELY (!face || !face->get_table))
295 return hb_blob_create_empty ();
297 return face->get_table (tag, face->user_data);
305 static hb_font_t _hb_font_nil = {
306 HB_REFERENCE_COUNT_INVALID, /* ref_count */
318 hb_font_create (hb_face_t *face)
322 if (!HB_OBJECT_DO_CREATE (hb_font_t, font))
323 return &_hb_font_nil;
325 font->face = hb_face_reference (face);
331 hb_font_reference (hb_font_t *font)
333 HB_OBJECT_DO_REFERENCE (font);
337 hb_font_get_reference_count (hb_font_t *font)
339 HB_OBJECT_DO_GET_REFERENCE_COUNT (font);
343 hb_font_destroy (hb_font_t *font)
345 HB_OBJECT_DO_DESTROY (font);
347 hb_face_destroy (font->face);
353 hb_font_get_face (hb_font_t *font)
355 if (HB_OBJECT_IS_INERT (font))
356 return &_hb_face_nil;
362 hb_font_set_scale (hb_font_t *font,
363 hb_16dot16_t x_scale,
364 hb_16dot16_t y_scale)
366 if (HB_OBJECT_IS_INERT (font))
369 font->x_scale = x_scale;
370 font->y_scale = y_scale;
374 hb_font_set_ppem (hb_font_t *font,
378 if (HB_OBJECT_IS_INERT (font))
381 font->x_ppem = x_ppem;
382 font->y_ppem = y_ppem;