9 * software and its documentation for any purpose, provided that the 10 * above copyright notice and the following two paragraphs appear in 11 * all copies of this software. 12 * 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 * DAMAGE. 18 * 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24 * 25 * Red Hat Author(s): Behdad Esfahbod 26 * Google Author(s): Behdad Esfahbod 27 */ 28 29 #include "hb-private.hh" 30 31 #include "hb-shaper-private.hh" 32 #include "hb-shape-plan-private.hh" 33 #include "hb-buffer-private.hh" 34 #include "hb-font-private.hh" 35 36 /** 37 * SECTION:hb-shape 38 * @title: Shaping 39 * @short_description: Conversion of text strings into positioned glyphs 40 * @include: hb.h 41 * 42 * Shaping is the central operation of HarfBuzz. Shaping operates on buffers, 43 * which are sequences of Unicode characters that use the same font and have 44 * the same text direction, script and language. After shaping the buffer 45 * contains the output glyphs and their positions. 46 **/ 47 48 static const char **static_shaper_list; 49 50 #ifdef HB_USE_ATEXIT 51 static 52 void free_static_shaper_list (void) 53 { 54 retry: 55 const char **shaper_list = (const char **) hb_atomic_ptr_get (&static_shaper_list); 56 if (!hb_atomic_ptr_cmpexch (&static_shaper_list, shaper_list, nullptr)) 57 goto retry; 58 59 free (shaper_list); 60 } 61 #endif 62 63 /** 64 * hb_shape_list_shapers: 65 * 66 * Retrieves the list of shapers supported by HarfBuzz. 67 * 68 * Return value: (transfer none) (array zero-terminated=1): an array of 69 * constant strings 70 * 71 * Since: 0.9.2 72 **/ 73 const char ** 74 hb_shape_list_shapers (void) 75 { 76 retry: 77 const char **shaper_list = (const char **) hb_atomic_ptr_get (&static_shaper_list); 78 79 if (unlikely (!shaper_list)) 80 { 81 /* Not found; allocate one. */ 82 shaper_list = (const char **) calloc (1 + HB_SHAPERS_COUNT, sizeof (const char *)); 83 if (unlikely (!shaper_list)) { 84 static const char *nil_shaper_list[] = {nullptr}; 85 return nil_shaper_list; 86 } 87 88 const hb_shaper_pair_t *shapers = _hb_shapers_get (); 89 unsigned int i; 90 for (i = 0; i < HB_SHAPERS_COUNT; i++) 91 shaper_list[i] = shapers[i].name; 92 shaper_list[i] = nullptr; 93 94 if (!hb_atomic_ptr_cmpexch (&static_shaper_list, nullptr, shaper_list)) { 95 free (shaper_list); 96 goto retry; 97 } 98 99 #ifdef HB_USE_ATEXIT 100 atexit (free_static_shaper_list); /* First person registers atexit() callback. */ 101 #endif 102 } 103 104 return shaper_list; 105 } 106 107 108 /** 109 * hb_shape_full: 110 * @font: an #hb_font_t to use for shaping 111 * @buffer: an #hb_buffer_t to shape 112 * @features: (array length=num_features) (allow-none): an array of user 113 * specified #hb_feature_t or %NULL 114 * @num_features: the length of @features array 115 * @shaper_list: (array zero-terminated=1) (allow-none): a %NULL-terminated 116 * array of shapers to use or %NULL 117 * 118 * See hb_shape() for details. If @shaper_list is not %NULL, the specified 119 * shapers will be used in the given order, otherwise the default shapers list 120 * will be used. 121 * 122 * Return value: false if all shapers failed, true otherwise 123 * 124 * Since: 0.9.2 | 9 * software and its documentation for any purpose, provided that the 10 * above copyright notice and the following two paragraphs appear in 11 * all copies of this software. 12 * 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 * DAMAGE. 18 * 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24 * 25 * Red Hat Author(s): Behdad Esfahbod 26 * Google Author(s): Behdad Esfahbod 27 */ 28 29 #include "hb.hh" 30 31 #include "hb-shaper.hh" 32 #include "hb-shape-plan.hh" 33 #include "hb-buffer.hh" 34 #include "hb-font.hh" 35 #include "hb-machinery.hh" 36 37 38 /** 39 * SECTION:hb-shape 40 * @title: hb-shape 41 * @short_description: Conversion of text strings into positioned glyphs 42 * @include: hb.h 43 * 44 * Shaping is the central operation of HarfBuzz. Shaping operates on buffers, 45 * which are sequences of Unicode characters that use the same font and have 46 * the same text direction, script, and language. After shaping the buffer 47 * contains the output glyphs and their positions. 48 **/ 49 50 51 #if HB_USE_ATEXIT 52 static void free_static_shaper_list (); 53 #endif 54 55 static const char *nil_shaper_list[] = {nullptr}; 56 57 static struct hb_shaper_list_lazy_loader_t : hb_lazy_loader_t<const char *, 58 hb_shaper_list_lazy_loader_t> 59 { 60 static const char ** create () 61 { 62 const char **shaper_list = (const char **) calloc (1 + HB_SHAPERS_COUNT, sizeof (const char *)); 63 if (unlikely (!shaper_list)) 64 return nullptr; 65 66 const hb_shaper_entry_t *shapers = _hb_shapers_get (); 67 unsigned int i; 68 for (i = 0; i < HB_SHAPERS_COUNT; i++) 69 shaper_list[i] = shapers[i].name; 70 shaper_list[i] = nullptr; 71 72 #if HB_USE_ATEXIT 73 atexit (free_static_shaper_list); 74 #endif 75 76 return shaper_list; 77 } 78 static void destroy (const char **l) 79 { free (l); } 80 static const char ** get_null () 81 { return nil_shaper_list; } 82 } static_shaper_list; 83 84 #if HB_USE_ATEXIT 85 static 86 void free_static_shaper_list () 87 { 88 static_shaper_list.free_instance (); 89 } 90 #endif 91 92 93 /** 94 * hb_shape_list_shapers: 95 * 96 * Retrieves the list of shapers supported by HarfBuzz. 97 * 98 * Return value: (transfer none) (array zero-terminated=1): an array of 99 * constant strings 100 * 101 * Since: 0.9.2 102 **/ 103 const char ** 104 hb_shape_list_shapers () 105 { 106 return static_shaper_list.get_unconst (); 107 } 108 109 110 /** 111 * hb_shape_full: 112 * @font: an #hb_font_t to use for shaping 113 * @buffer: an #hb_buffer_t to shape 114 * @features: (array length=num_features) (allow-none): an array of user 115 * specified #hb_feature_t or %NULL 116 * @num_features: the length of @features array 117 * @shaper_list: (array zero-terminated=1) (allow-none): a %NULL-terminated 118 * array of shapers to use or %NULL 119 * 120 * See hb_shape() for details. If @shaper_list is not %NULL, the specified 121 * shapers will be used in the given order, otherwise the default shapers list 122 * will be used. 123 * 124 * Return value: false if all shapers failed, true otherwise 125 * 126 * Since: 0.9.2 |