author | prr |
Fri, 01 Mar 2019 16:59:19 -0800 | |
changeset 54232 | 7c11a7cc7c1d |
parent 50826 | f5b95be8b6e2 |
permissions | -rw-r--r-- |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
2 |
* Copyright © 2009 Red Hat, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
3 |
* Copyright © 2012 Google, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
4 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
5 |
* This is part of HarfBuzz, a text shaping library. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
6 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
7 |
* Permission is hereby granted, without written agreement and without |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
8 |
* license or royalty fees, to use, copy, modify, and distribute this |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
9 |
* software and its documentation for any purpose, provided that the |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
10 |
* above copyright notice and the following two paragraphs appear in |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
11 |
* all copies of this software. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
12 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
13 |
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
14 |
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
15 |
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
16 |
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
17 |
* DAMAGE. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
18 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
19 |
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
20 |
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
21 |
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
22 |
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
23 |
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
24 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
25 |
* Red Hat Author(s): Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
26 |
* Google Author(s): Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
27 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
28 |
|
54232 | 29 |
#include "hb.hh" |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
30 |
|
54232 | 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 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
37 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
38 |
/** |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
39 |
* SECTION:hb-shape |
54232 | 40 |
* @title: hb-shape |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
41 |
* @short_description: Conversion of text strings into positioned glyphs |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
42 |
* @include: hb.h |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
43 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
44 |
* Shaping is the central operation of HarfBuzz. Shaping operates on buffers, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
45 |
* which are sequences of Unicode characters that use the same font and have |
54232 | 46 |
* the same text direction, script, and language. After shaping the buffer |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
47 |
* contains the output glyphs and their positions. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
48 |
**/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
49 |
|
54232 | 50 |
|
51 |
#if HB_USE_ATEXIT |
|
52 |
static void free_static_shaper_list (); |
|
53 |
#endif |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
54 |
|
54232 | 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> |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
59 |
{ |
54232 | 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; |
|
50826 | 71 |
|
54232 | 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 (); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
89 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
90 |
#endif |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
91 |
|
54232 | 92 |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
93 |
/** |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
94 |
* hb_shape_list_shapers: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
95 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
96 |
* Retrieves the list of shapers supported by HarfBuzz. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
97 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
98 |
* Return value: (transfer none) (array zero-terminated=1): an array of |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
99 |
* constant strings |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
100 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
101 |
* Since: 0.9.2 |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
102 |
**/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
103 |
const char ** |
54232 | 104 |
hb_shape_list_shapers () |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
105 |
{ |
54232 | 106 |
return static_shaper_list.get_unconst (); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
107 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
108 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
109 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
110 |
/** |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
111 |
* hb_shape_full: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
112 |
* @font: an #hb_font_t to use for shaping |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
113 |
* @buffer: an #hb_buffer_t to shape |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
114 |
* @features: (array length=num_features) (allow-none): an array of user |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
115 |
* specified #hb_feature_t or %NULL |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
116 |
* @num_features: the length of @features array |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
117 |
* @shaper_list: (array zero-terminated=1) (allow-none): a %NULL-terminated |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
118 |
* array of shapers to use or %NULL |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
119 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
120 |
* See hb_shape() for details. If @shaper_list is not %NULL, the specified |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
121 |
* shapers will be used in the given order, otherwise the default shapers list |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
122 |
* will be used. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
123 |
* |
48274 | 124 |
* Return value: false if all shapers failed, true otherwise |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
125 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
126 |
* Since: 0.9.2 |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
127 |
**/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
128 |
hb_bool_t |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
129 |
hb_shape_full (hb_font_t *font, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
130 |
hb_buffer_t *buffer, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
131 |
const hb_feature_t *features, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
132 |
unsigned int num_features, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
133 |
const char * const *shaper_list) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
134 |
{ |
43232 | 135 |
hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached2 (font->face, &buffer->props, |
136 |
features, num_features, |
|
137 |
font->coords, font->num_coords, |
|
138 |
shaper_list); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
139 |
hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
140 |
hb_shape_plan_destroy (shape_plan); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
141 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
142 |
if (res) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
143 |
buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
144 |
return res; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
145 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
146 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
147 |
/** |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
148 |
* hb_shape: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
149 |
* @font: an #hb_font_t to use for shaping |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
150 |
* @buffer: an #hb_buffer_t to shape |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
151 |
* @features: (array length=num_features) (allow-none): an array of user |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
152 |
* specified #hb_feature_t or %NULL |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
153 |
* @num_features: the length of @features array |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
154 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
155 |
* Shapes @buffer using @font turning its Unicode characters content to |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
156 |
* positioned glyphs. If @features is not %NULL, it will be used to control the |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
157 |
* features applied during shaping. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
158 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
159 |
* Since: 0.9.2 |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
160 |
**/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
161 |
void |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
162 |
hb_shape (hb_font_t *font, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
163 |
hb_buffer_t *buffer, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
164 |
const hb_feature_t *features, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
165 |
unsigned int num_features) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
166 |
{ |
48274 | 167 |
hb_shape_full (font, buffer, features, num_features, nullptr); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
168 |
} |