1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-shaper-private.hh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +/* 1.5 + * Copyright © 2012 Google, Inc. 1.6 + * 1.7 + * This is part of HarfBuzz, a text shaping library. 1.8 + * 1.9 + * Permission is hereby granted, without written agreement and without 1.10 + * license or royalty fees, to use, copy, modify, and distribute this 1.11 + * software and its documentation for any purpose, provided that the 1.12 + * above copyright notice and the following two paragraphs appear in 1.13 + * all copies of this software. 1.14 + * 1.15 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.16 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.17 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.18 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.19 + * DAMAGE. 1.20 + * 1.21 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.22 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.23 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.24 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.25 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.26 + * 1.27 + * Google Author(s): Behdad Esfahbod 1.28 + */ 1.29 + 1.30 +#ifndef HB_SHAPER_PRIVATE_HH 1.31 +#define HB_SHAPER_PRIVATE_HH 1.32 + 1.33 +#include "hb-private.hh" 1.34 + 1.35 +typedef hb_bool_t hb_shape_func_t (hb_shape_plan_t *shape_plan, 1.36 + hb_font_t *font, 1.37 + hb_buffer_t *buffer, 1.38 + const hb_feature_t *features, 1.39 + unsigned int num_features); 1.40 + 1.41 +#define HB_SHAPER_IMPLEMENT(name) \ 1.42 + extern "C" HB_INTERNAL hb_shape_func_t _hb_##name##_shape; 1.43 +#include "hb-shaper-list.hh" 1.44 +#undef HB_SHAPER_IMPLEMENT 1.45 + 1.46 +struct hb_shaper_pair_t { 1.47 + char name[16]; 1.48 + hb_shape_func_t *func; 1.49 +}; 1.50 + 1.51 +HB_INTERNAL const hb_shaper_pair_t * 1.52 +_hb_shapers_get (void); 1.53 + 1.54 + 1.55 +/* For embedding in face / font / ... */ 1.56 +struct hb_shaper_data_t { 1.57 +#define HB_SHAPER_IMPLEMENT(shaper) void *shaper; 1.58 +#include "hb-shaper-list.hh" 1.59 +#undef HB_SHAPER_IMPLEMENT 1.60 +}; 1.61 + 1.62 +#define HB_SHAPERS_COUNT (sizeof (hb_shaper_data_t) / sizeof (void *)) 1.63 + 1.64 +/* Means: succeeded, but don't need to keep any data. */ 1.65 +#define HB_SHAPER_DATA_SUCCEEDED ((void *) +1) 1.66 + 1.67 +/* Means: tried but failed to create. */ 1.68 +#define HB_SHAPER_DATA_INVALID ((void *) -1) 1.69 +#define HB_SHAPER_DATA_IS_INVALID(data) ((void *) (data) == HB_SHAPER_DATA_INVALID) 1.70 + 1.71 +#define HB_SHAPER_DATA_TYPE(shaper, object) struct hb_##shaper##_shaper_##object##_data_t 1.72 +#define HB_SHAPER_DATA_INSTANCE(shaper, object, instance) (* (HB_SHAPER_DATA_TYPE(shaper, object) **) &(instance)->shaper_data.shaper) 1.73 +#define HB_SHAPER_DATA(shaper, object) HB_SHAPER_DATA_INSTANCE (shaper, object, object) 1.74 +#define HB_SHAPER_DATA_CREATE_FUNC(shaper, object) _hb_##shaper##_shaper_##object##_data_create 1.75 +#define HB_SHAPER_DATA_DESTROY_FUNC(shaper, object) _hb_##shaper##_shaper_##object##_data_destroy 1.76 + 1.77 +#define HB_SHAPER_DATA_PROTOTYPE(shaper, object) \ 1.78 + HB_SHAPER_DATA_TYPE (shaper, object); /* Type forward declaration. */ \ 1.79 + extern "C" HB_INTERNAL HB_SHAPER_DATA_TYPE (shaper, object) * \ 1.80 + HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (hb_##object##_t *object HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS); \ 1.81 + extern "C" HB_INTERNAL void \ 1.82 + HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (HB_SHAPER_DATA_TYPE (shaper, object) *data) 1.83 + 1.84 +#define HB_SHAPER_DATA_DESTROY(shaper, object) \ 1.85 + if (object->shaper_data.shaper && \ 1.86 + object->shaper_data.shaper != HB_SHAPER_DATA_INVALID && \ 1.87 + object->shaper_data.shaper != HB_SHAPER_DATA_SUCCEEDED) \ 1.88 + HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (HB_SHAPER_DATA (shaper, object)); 1.89 + 1.90 +#define HB_SHAPER_DATA_ENSURE_DECLARE(shaper, object) \ 1.91 +static inline bool \ 1.92 +hb_##shaper##_shaper_##object##_data_ensure (hb_##object##_t *object) \ 1.93 +{\ 1.94 + retry: \ 1.95 + HB_SHAPER_DATA_TYPE (shaper, object) *data = (HB_SHAPER_DATA_TYPE (shaper, object) *) hb_atomic_ptr_get (&HB_SHAPER_DATA (shaper, object)); \ 1.96 + if (unlikely (!data)) { \ 1.97 + data = HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (object); \ 1.98 + if (unlikely (!data)) \ 1.99 + data = (HB_SHAPER_DATA_TYPE (shaper, object) *) HB_SHAPER_DATA_INVALID; \ 1.100 + if (!hb_atomic_ptr_cmpexch (&HB_SHAPER_DATA (shaper, object), NULL, data)) { \ 1.101 + if (data && \ 1.102 + data != HB_SHAPER_DATA_INVALID && \ 1.103 + data != HB_SHAPER_DATA_SUCCEEDED) \ 1.104 + HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (data); \ 1.105 + goto retry; \ 1.106 + } \ 1.107 + } \ 1.108 + return data != NULL && !HB_SHAPER_DATA_IS_INVALID (data); \ 1.109 +} 1.110 + 1.111 + 1.112 +#endif /* HB_SHAPER_PRIVATE_HH */