michael@0: /* michael@0: * Copyright © 2011 Google, Inc. michael@0: * michael@0: * This is part of HarfBuzz, a text shaping library. michael@0: * michael@0: * Permission is hereby granted, without written agreement and without michael@0: * license or royalty fees, to use, copy, modify, and distribute this michael@0: * software and its documentation for any purpose, provided that the michael@0: * above copyright notice and the following two paragraphs appear in michael@0: * all copies of this software. michael@0: * michael@0: * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR michael@0: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES michael@0: * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN michael@0: * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH michael@0: * DAMAGE. michael@0: * michael@0: * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, michael@0: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND michael@0: * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS michael@0: * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO michael@0: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. michael@0: * michael@0: * Google Author(s): Behdad Esfahbod michael@0: */ michael@0: michael@0: #include "hb-private.hh" michael@0: michael@0: /* g++ didn't like older gtype.h gcc-only code path. */ michael@0: #include michael@0: #if !GLIB_CHECK_VERSION(2,29,16) michael@0: #undef __GNUC__ michael@0: #undef __GNUC_MINOR__ michael@0: #define __GNUC__ 2 michael@0: #define __GNUC_MINOR__ 6 michael@0: #endif michael@0: michael@0: #include "hb-gobject.h" michael@0: michael@0: #define HB_DEFINE_BOXED_TYPE(name,copy_func,free_func) \ michael@0: GType \ michael@0: hb_gobject_##name##_get_type (void) \ michael@0: { \ michael@0: static gsize type_id = 0; \ michael@0: if (g_once_init_enter (&type_id)) { \ michael@0: GType id = g_boxed_type_register_static (g_intern_static_string ("hb_" #name "_t"), \ michael@0: (GBoxedCopyFunc) copy_func, \ michael@0: (GBoxedFreeFunc) free_func); \ michael@0: g_once_init_leave (&type_id, id); \ michael@0: } \ michael@0: return type_id; \ michael@0: } michael@0: michael@0: #define HB_DEFINE_OBJECT_TYPE(name) \ michael@0: HB_DEFINE_BOXED_TYPE (name, hb_##name##_reference, hb_##name##_destroy); michael@0: michael@0: HB_DEFINE_OBJECT_TYPE (buffer) michael@0: HB_DEFINE_OBJECT_TYPE (blob) michael@0: HB_DEFINE_OBJECT_TYPE (face) michael@0: HB_DEFINE_OBJECT_TYPE (font) michael@0: HB_DEFINE_OBJECT_TYPE (font_funcs) michael@0: HB_DEFINE_OBJECT_TYPE (set) michael@0: HB_DEFINE_OBJECT_TYPE (shape_plan) michael@0: HB_DEFINE_OBJECT_TYPE (unicode_funcs) michael@0: michael@0: michael@0: static hb_feature_t *feature_reference (hb_feature_t *g) michael@0: { michael@0: hb_feature_t *c = (hb_feature_t *) calloc (1, sizeof (hb_feature_t)); michael@0: if (unlikely (!c)) return NULL; michael@0: *c = *g; michael@0: return c; michael@0: } michael@0: static void feature_destroy (hb_feature_t *g) { free (g); } michael@0: HB_DEFINE_BOXED_TYPE (feature, feature_reference, feature_destroy) michael@0: michael@0: static hb_glyph_info_t *glyph_info_reference (hb_glyph_info_t *g) michael@0: { michael@0: hb_glyph_info_t *c = (hb_glyph_info_t *) calloc (1, sizeof (hb_glyph_info_t)); michael@0: if (unlikely (!c)) return NULL; michael@0: *c = *g; michael@0: return c; michael@0: } michael@0: static void glyph_info_destroy (hb_glyph_info_t *g) { free (g); } michael@0: HB_DEFINE_BOXED_TYPE (glyph_info, glyph_info_reference, glyph_info_destroy) michael@0: michael@0: static hb_glyph_position_t *glyph_position_reference (hb_glyph_position_t *g) michael@0: { michael@0: hb_glyph_position_t *c = (hb_glyph_position_t *) calloc (1, sizeof (hb_glyph_position_t)); michael@0: if (unlikely (!c)) return NULL; michael@0: *c = *g; michael@0: return c; michael@0: } michael@0: static void glyph_position_destroy (hb_glyph_position_t *g) { free (g); } michael@0: HB_DEFINE_BOXED_TYPE (glyph_position, glyph_position_reference, glyph_position_destroy) michael@0: michael@0: static hb_segment_properties_t *segment_properties_reference (hb_segment_properties_t *g) michael@0: { michael@0: hb_segment_properties_t *c = (hb_segment_properties_t *) calloc (1, sizeof (hb_segment_properties_t)); michael@0: if (unlikely (!c)) return NULL; michael@0: *c = *g; michael@0: return c; michael@0: } michael@0: static void segment_properties_destroy (hb_segment_properties_t *g) { free (g); } michael@0: HB_DEFINE_BOXED_TYPE (segment_properties, segment_properties_reference, segment_properties_destroy) michael@0: michael@0: static hb_user_data_key_t user_data_key_reference (hb_user_data_key_t l) { return l; } michael@0: static void user_data_key_destroy (hb_user_data_key_t l) { } michael@0: HB_DEFINE_BOXED_TYPE (user_data_key, user_data_key_reference, user_data_key_destroy) michael@0: michael@0: michael@0: static hb_language_t *language_reference (hb_language_t *l) michael@0: { michael@0: hb_language_t *c = (hb_language_t *) calloc (1, sizeof (hb_language_t)); michael@0: if (unlikely (!c)) return NULL; michael@0: *c = *l; michael@0: return c; michael@0: } michael@0: static void language_destroy (hb_language_t *l) { free (l); } michael@0: HB_DEFINE_BOXED_TYPE (language, language_reference, language_destroy)