1c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod/* 2c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * Copyright © 2011 Google, Inc. 3c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * 4c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * This is part of HarfBuzz, a text shaping library. 5c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * 6c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * Permission is hereby granted, without written agreement and without 7c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this 8c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * software and its documentation for any purpose, provided that the 9c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * above copyright notice and the following two paragraphs appear in 10c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * all copies of this software. 11c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * 12c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 13c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 14c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 15c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 16c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * DAMAGE. 17c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * 18c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 19c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 21c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 22c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 23c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * 24c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod * Google Author(s): Behdad Esfahbod 25c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod */ 26c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod 27c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#include "hb-private.hh" 28c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod 29c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod/* g++ didn't like older gtype.h gcc-only code path. */ 30c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#include <glib.h> 31c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#if !GLIB_CHECK_VERSION(2,29,16) 32c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#undef __GNUC__ 33c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#undef __GNUC_MINOR__ 34c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#define __GNUC__ 2 35c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#define __GNUC_MINOR__ 6 36c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#endif 37c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod 38c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod#include "hb-gobject.h" 39c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod 4071439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod#define HB_DEFINE_BOXED_TYPE(name,copy_func,free_func) \ 41c214cff55ce539d004d069a484dac3988953cb11Behdad EsfahbodGType \ 4271439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodhb_gobject_##name##_get_type (void) \ 43c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod{ \ 4471439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod static gsize type_id = 0; \ 4571439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod if (g_once_init_enter (&type_id)) { \ 4671439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod GType id = g_boxed_type_register_static (g_intern_static_string ("hb_" #name "_t"), \ 4771439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod (GBoxedCopyFunc) copy_func, \ 4871439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod (GBoxedFreeFunc) free_func); \ 4971439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod g_once_init_leave (&type_id, id); \ 50c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod } \ 5171439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod return type_id; \ 52c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod} 53c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod 5471439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod#define HB_DEFINE_OBJECT_TYPE(name) \ 5571439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod HB_DEFINE_BOXED_TYPE (name, hb_##name##_reference, hb_##name##_destroy); 56c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod 5771439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_OBJECT_TYPE (buffer) 5871439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_OBJECT_TYPE (blob) 5971439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_OBJECT_TYPE (face) 6071439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_OBJECT_TYPE (font) 6171439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_OBJECT_TYPE (font_funcs) 6271439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_OBJECT_TYPE (set) 6371439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_OBJECT_TYPE (shape_plan) 6471439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_OBJECT_TYPE (unicode_funcs) 65c214cff55ce539d004d069a484dac3988953cb11Behdad Esfahbod 6671439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod 6771439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic hb_feature_t *feature_reference (hb_feature_t *g) 6871439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod{ 6971439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod hb_feature_t *c = (hb_feature_t *) calloc (1, sizeof (hb_feature_t)); 7071439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod if (unlikely (!c)) return NULL; 7171439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod *c = *g; 7271439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod return c; 7371439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod} 7471439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic void feature_destroy (hb_feature_t *g) { free (g); } 7571439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_BOXED_TYPE (feature, feature_reference, feature_destroy) 7671439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod 7771439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic hb_glyph_info_t *glyph_info_reference (hb_glyph_info_t *g) 7871439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod{ 7971439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod hb_glyph_info_t *c = (hb_glyph_info_t *) calloc (1, sizeof (hb_glyph_info_t)); 8071439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod if (unlikely (!c)) return NULL; 8171439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod *c = *g; 8271439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod return c; 8371439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod} 8471439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic void glyph_info_destroy (hb_glyph_info_t *g) { free (g); } 8571439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_BOXED_TYPE (glyph_info, glyph_info_reference, glyph_info_destroy) 8671439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod 8771439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic hb_glyph_position_t *glyph_position_reference (hb_glyph_position_t *g) 8871439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod{ 8971439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod hb_glyph_position_t *c = (hb_glyph_position_t *) calloc (1, sizeof (hb_glyph_position_t)); 9071439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod if (unlikely (!c)) return NULL; 9171439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod *c = *g; 9271439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod return c; 9371439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod} 9471439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic void glyph_position_destroy (hb_glyph_position_t *g) { free (g); } 9571439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_BOXED_TYPE (glyph_position, glyph_position_reference, glyph_position_destroy) 9671439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod 9771439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic hb_segment_properties_t *segment_properties_reference (hb_segment_properties_t *g) 9871439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod{ 9971439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod hb_segment_properties_t *c = (hb_segment_properties_t *) calloc (1, sizeof (hb_segment_properties_t)); 10071439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod if (unlikely (!c)) return NULL; 10171439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod *c = *g; 10271439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod return c; 10371439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod} 10471439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic void segment_properties_destroy (hb_segment_properties_t *g) { free (g); } 10571439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_BOXED_TYPE (segment_properties, segment_properties_reference, segment_properties_destroy) 10671439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbod 10771439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic hb_user_data_key_t user_data_key_reference (hb_user_data_key_t l) { return l; } 10871439a8c7ae9df25193bc3ad0f203117d2884a19Behdad Esfahbodstatic void user_data_key_destroy (hb_user_data_key_t l) { } 10971439a8c7ae9df25193bc3ad0f203117d2884a19Behdad EsfahbodHB_DEFINE_BOXED_TYPE (user_data_key, user_data_key_reference, user_data_key_destroy) 11017905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbod 11117905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbod 11217905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbodstatic hb_language_t *language_reference (hb_language_t *l) 11317905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbod{ 11417905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbod hb_language_t *c = (hb_language_t *) calloc (1, sizeof (hb_language_t)); 11517905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbod if (unlikely (!c)) return NULL; 11617905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbod *c = *l; 11717905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbod return c; 11817905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbod} 11917905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad Esfahbodstatic void language_destroy (hb_language_t *l) { free (l); } 12017905c54f1bab9e6dfe13f59f5ec208de12832f7Behdad EsfahbodHB_DEFINE_BOXED_TYPE (language, language_reference, language_destroy) 121