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-open-file-private.hh"
33 #include "hb-ot-layout-private.h"
39 hb_font_funcs_t _hb_font_funcs_nil = {
40 HB_REFERENCE_COUNT_INVALID, /* ref_count */
44 NULL, /* glyph_func */
45 NULL, /* contour_point_func */
46 NULL, /* glyph_metrics_func */
47 NULL /* kerning_func */
51 hb_font_funcs_create (void)
53 hb_font_funcs_t *ffuncs;
55 if (!HB_OBJECT_DO_CREATE (hb_font_funcs_t, ffuncs))
56 return &_hb_font_funcs_nil;
62 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
64 HB_OBJECT_DO_REFERENCE (ffuncs);
68 hb_font_funcs_get_reference_count (hb_font_funcs_t *ffuncs)
70 HB_OBJECT_DO_GET_REFERENCE_COUNT (ffuncs);
74 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
76 HB_OBJECT_DO_DESTROY (ffuncs);
82 hb_font_funcs_copy (hb_font_funcs_t *other_ffuncs)
84 hb_font_funcs_t *ffuncs;
86 if (!HB_OBJECT_DO_CREATE (hb_font_funcs_t, ffuncs))
87 return &_hb_font_funcs_nil;
89 *ffuncs = *other_ffuncs;
91 /* re-init refcount */
92 HB_OBJECT_DO_INIT (ffuncs);
93 ffuncs->immutable = FALSE;
99 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
101 if (HB_OBJECT_IS_INERT (ffuncs))
104 ffuncs->immutable = TRUE;
114 _hb_face_get_table_from_blob (hb_tag_t tag, void *user_data)
116 hb_face_t *face = (hb_face_t *) user_data;
118 const OpenTypeFontFile &ot_file = Sanitizer<OpenTypeFontFile>::lock_instance (face->blob);
119 const OpenTypeFontFace &ot_face = ot_file.get_face (face->index);
121 const OpenTypeTable &table = ot_face.get_table_by_tag (tag);
123 hb_blob_t *blob = hb_blob_create_sub_blob (face->blob, table.offset, table.length);
125 hb_blob_unlock (face->blob);
130 static hb_face_t _hb_face_nil = {
131 HB_REFERENCE_COUNT_INVALID, /* ref_count */
136 NULL, /* get_table */
138 NULL, /* user_data */
144 hb_face_create_for_tables (hb_get_table_func_t get_table,
145 hb_destroy_func_t destroy,
150 if (!HB_OBJECT_DO_CREATE (hb_face_t, face)) {
153 return &_hb_face_nil;
156 face->get_table = get_table;
157 face->destroy = destroy;
158 face->user_data = user_data;
160 _hb_ot_layout_init (face);
166 hb_face_create_for_data (hb_blob_t *blob,
171 if (!HB_OBJECT_DO_CREATE (hb_face_t, face))
172 return &_hb_face_nil;
174 face->blob = Sanitizer<OpenTypeFontFile>::sanitize (hb_blob_reference (blob));
176 face->get_table = _hb_face_get_table_from_blob;
177 face->user_data = face;
179 _hb_ot_layout_init (face);
185 hb_face_reference (hb_face_t *face)
187 HB_OBJECT_DO_REFERENCE (face);
191 hb_face_get_reference_count (hb_face_t *face)
193 HB_OBJECT_DO_GET_REFERENCE_COUNT (face);
197 hb_face_destroy (hb_face_t *face)
199 HB_OBJECT_DO_DESTROY (face);
201 _hb_ot_layout_fini (face);
203 hb_blob_destroy (face->blob);
206 face->destroy (face->user_data);
212 hb_face_get_table (hb_face_t *face,
215 if (HB_UNLIKELY (!face || !face->get_table))
216 return hb_blob_create_empty ();
218 return face->get_table (tag, face->user_data);
226 static hb_font_t _hb_font_nil = {
227 HB_REFERENCE_COUNT_INVALID, /* ref_count */
241 hb_font_create (void)
245 if (!HB_OBJECT_DO_CREATE (hb_font_t, font))
246 return &_hb_font_nil;
252 hb_font_reference (hb_font_t *font)
254 HB_OBJECT_DO_REFERENCE (font);
258 hb_font_get_reference_count (hb_font_t *font)
260 HB_OBJECT_DO_GET_REFERENCE_COUNT (font);
264 hb_font_destroy (hb_font_t *font)
266 HB_OBJECT_DO_DESTROY (font);
268 hb_font_funcs_destroy (font->klass);
270 font->destroy (font->user_data);
276 hb_font_set_funcs (hb_font_t *font,
277 hb_font_funcs_t *klass,
278 hb_destroy_func_t destroy,
281 if (HB_OBJECT_IS_INERT (font))
285 font->destroy (font->user_data);
287 hb_font_funcs_reference (klass);
288 hb_font_funcs_destroy (font->klass);
290 font->destroy = destroy;
291 font->user_data = user_data;
295 hb_font_set_scale (hb_font_t *font,
296 hb_16dot16_t x_scale,
297 hb_16dot16_t y_scale)
299 if (HB_OBJECT_IS_INERT (font))
302 font->x_scale = x_scale;
303 font->y_scale = y_scale;
307 hb_font_set_ppem (hb_font_t *font,
311 if (HB_OBJECT_IS_INERT (font))
314 font->x_ppem = x_ppem;
315 font->y_ppem = y_ppem;