Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/harfbuzz/src/hb-shape.cc @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 * Copyright © 2009 Red Hat, Inc. | |
| 3 * Copyright © 2012 Google, Inc. | |
| 4 * | |
| 5 * This is part of HarfBuzz, a text shaping library. | |
| 6 * | |
| 7 * Permission is hereby granted, without written agreement and without | |
| 8 * license or royalty fees, to use, copy, modify, and distribute this | |
| 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 #ifndef HB_NO_SHAPER | |
| 39 | |
| 40 /** | |
| 41 * SECTION:hb-shape | |
| 42 * @title: hb-shape | |
| 43 * @short_description: Conversion of text strings into positioned glyphs | |
| 44 * @include: hb.h | |
| 45 * | |
| 46 * Shaping is the central operation of HarfBuzz. Shaping operates on buffers, | |
| 47 * which are sequences of Unicode characters that use the same font and have | |
| 48 * the same text direction, script, and language. After shaping the buffer | |
| 49 * contains the output glyphs and their positions. | |
| 50 **/ | |
| 51 | |
| 52 | |
| 53 static inline void free_static_shaper_list (); | |
| 54 | |
| 55 static const char * const 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 **) hb_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 hb_atexit (free_static_shaper_list); | |
| 73 | |
| 74 return shaper_list; | |
| 75 } | |
| 76 static void destroy (const char **l) | |
| 77 { hb_free (l); } | |
| 78 static const char * const * get_null () | |
| 79 { return nil_shaper_list; } | |
| 80 } static_shaper_list; | |
| 81 | |
| 82 static inline | |
| 83 void free_static_shaper_list () | |
| 84 { | |
| 85 static_shaper_list.free_instance (); | |
| 86 } | |
| 87 | |
| 88 | |
| 89 /** | |
| 90 * hb_shape_list_shapers: | |
| 91 * | |
| 92 * Retrieves the list of shapers supported by HarfBuzz. | |
| 93 * | |
| 94 * Return value: (transfer none) (array zero-terminated=1): an array of | |
| 95 * constant strings | |
| 96 * | |
| 97 * Since: 0.9.2 | |
| 98 **/ | |
| 99 const char ** | |
| 100 hb_shape_list_shapers () | |
| 101 { | |
| 102 return static_shaper_list.get_unconst (); | |
| 103 } | |
| 104 | |
| 105 | |
| 106 /** | |
| 107 * hb_shape_full: | |
| 108 * @font: an #hb_font_t to use for shaping | |
| 109 * @buffer: an #hb_buffer_t to shape | |
| 110 * @features: (array length=num_features) (nullable): an array of user | |
| 111 * specified #hb_feature_t or `NULL` | |
| 112 * @num_features: the length of @features array | |
| 113 * @shaper_list: (array zero-terminated=1) (nullable): a `NULL`-terminated | |
| 114 * array of shapers to use or `NULL` | |
| 115 * | |
| 116 * See hb_shape() for details. If @shaper_list is not `NULL`, the specified | |
| 117 * shapers will be used in the given order, otherwise the default shapers list | |
| 118 * will be used. | |
| 119 * | |
| 120 * Return value: false if all shapers failed, true otherwise | |
| 121 * | |
| 122 * Since: 0.9.2 | |
| 123 **/ | |
| 124 hb_bool_t | |
| 125 hb_shape_full (hb_font_t *font, | |
| 126 hb_buffer_t *buffer, | |
| 127 const hb_feature_t *features, | |
| 128 unsigned int num_features, | |
| 129 const char * const *shaper_list) | |
| 130 { | |
| 131 if (unlikely (!buffer->len)) | |
| 132 return true; | |
| 133 | |
| 134 buffer->enter (); | |
| 135 | |
| 136 hb_buffer_t *text_buffer = nullptr; | |
| 137 if (buffer->flags & HB_BUFFER_FLAG_VERIFY) | |
| 138 { | |
| 139 text_buffer = hb_buffer_create (); | |
| 140 hb_buffer_append (text_buffer, buffer, 0, -1); | |
| 141 } | |
| 142 | |
| 143 hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached2 (font->face, &buffer->props, | |
| 144 features, num_features, | |
| 145 font->coords, font->num_coords, | |
| 146 shaper_list); | |
| 147 | |
| 148 hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features); | |
| 149 | |
| 150 if (buffer->max_ops <= 0) | |
| 151 buffer->shaping_failed = true; | |
| 152 | |
| 153 hb_shape_plan_destroy (shape_plan); | |
| 154 | |
| 155 if (text_buffer) | |
| 156 { | |
| 157 if (res && buffer->successful && !buffer->shaping_failed | |
| 158 && text_buffer->successful | |
| 159 && !buffer->verify (text_buffer, | |
| 160 font, | |
| 161 features, | |
| 162 num_features, | |
| 163 shaper_list)) | |
| 164 res = false; | |
| 165 hb_buffer_destroy (text_buffer); | |
| 166 } | |
| 167 | |
| 168 buffer->leave (); | |
| 169 | |
| 170 return res; | |
| 171 } | |
| 172 | |
| 173 /** | |
| 174 * hb_shape: | |
| 175 * @font: an #hb_font_t to use for shaping | |
| 176 * @buffer: an #hb_buffer_t to shape | |
| 177 * @features: (array length=num_features) (nullable): an array of user | |
| 178 * specified #hb_feature_t or `NULL` | |
| 179 * @num_features: the length of @features array | |
| 180 * | |
| 181 * Shapes @buffer using @font turning its Unicode characters content to | |
| 182 * positioned glyphs. If @features is not `NULL`, it will be used to control the | |
| 183 * features applied during shaping. If two @features have the same tag but | |
| 184 * overlapping ranges the value of the feature with the higher index takes | |
| 185 * precedence. | |
| 186 * | |
| 187 * Since: 0.9.2 | |
| 188 **/ | |
| 189 void | |
| 190 hb_shape (hb_font_t *font, | |
| 191 hb_buffer_t *buffer, | |
| 192 const hb_feature_t *features, | |
| 193 unsigned int num_features) | |
| 194 { | |
| 195 hb_shape_full (font, buffer, features, num_features, nullptr); | |
| 196 } | |
| 197 | |
| 198 | |
| 199 #endif |
