blob: 08a4054cd0c648454e609e96060e72ef946f008f [file] [log] [blame]
Behdad Esfahbodfb194b82011-04-20 02:00:47 -04001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2009 Red Hat, Inc.
Behdad Esfahbod6adf4172012-08-01 18:07:42 -04003 * Copyright © 2011 Codethink Limited
4 * Copyright © 2010,2011,2012 Google, Inc.
Behdad Esfahbodfb194b82011-04-20 02:00:47 -04005 *
6 * This is part of HarfBuzz, a text shaping library.
7 *
8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software.
13 *
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE.
19 *
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 *
26 * Red Hat Author(s): Behdad Esfahbod
27 * Codethink Author(s): Ryan Lortie
28 * Google Author(s): Behdad Esfahbod
29 */
30
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070031#include "hb.hh"
Behdad Esfahbodfb194b82011-04-20 02:00:47 -040032
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070033#include "hb-unicode.hh"
Behdad Esfahbodfb194b82011-04-20 02:00:47 -040034
Behdad Esfahbodfb194b82011-04-20 02:00:47 -040035
Behdad Esfahbod00cf4e52018-10-27 04:07:33 -070036/**
37 * SECTION: hb-unicode
Behdad Esfahbodcf5fa572018-10-27 04:50:38 -070038 * @title: hb-unicode
Behdad Esfahbod00cf4e52018-10-27 04:07:33 -070039 * @short_description: Unicode character property access
40 * @include: hb.h
41 *
42 * Unicode functions are used to access Unicode character properties.
43 * Client can pass its own Unicode functions to HarfBuzz, or access
44 * the built-in Unicode functions that come with HarfBuzz.
45 *
46 * With the Unicode functions, one can query variour Unicode character
47 * properties, such as General Category, Script, Combining Class, etc.
48 **/
49
Behdad Esfahbodfb194b82011-04-20 02:00:47 -040050
51/*
52 * hb_unicode_funcs_t
53 */
54
Behdad Esfahbod21fdcee2012-08-01 16:23:44 -040055static hb_unicode_combining_class_t
Behdad Esfahbodc4641722011-07-07 23:47:19 -040056hb_unicode_combining_class_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
57 hb_codepoint_t unicode HB_UNUSED,
58 void *user_data HB_UNUSED)
Behdad Esfahbod891c4752011-07-07 23:19:27 -040059{
Behdad Esfahbod21fdcee2012-08-01 16:23:44 -040060 return HB_UNICODE_COMBINING_CLASS_NOT_REORDERED;
Behdad Esfahbodfb194b82011-04-20 02:00:47 -040061}
62
Behdad Esfahbodfca27862019-05-11 00:37:01 -070063#ifndef HB_DISABLE_DEPRECATED
Behdad Esfahbod891c4752011-07-07 23:19:27 -040064static unsigned int
Behdad Esfahbodc4641722011-07-07 23:47:19 -040065hb_unicode_eastasian_width_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
66 hb_codepoint_t unicode HB_UNUSED,
67 void *user_data HB_UNUSED)
Behdad Esfahbod891c4752011-07-07 23:19:27 -040068{
69 return 1;
70}
Behdad Esfahbodfca27862019-05-11 00:37:01 -070071#endif
Behdad Esfahbod891c4752011-07-07 23:19:27 -040072
73static hb_unicode_general_category_t
Behdad Esfahbodc4641722011-07-07 23:47:19 -040074hb_unicode_general_category_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
75 hb_codepoint_t unicode HB_UNUSED,
76 void *user_data HB_UNUSED)
Behdad Esfahbod891c4752011-07-07 23:19:27 -040077{
78 return HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER;
79}
80
81static hb_codepoint_t
Behdad Esfahbodc4641722011-07-07 23:47:19 -040082hb_unicode_mirroring_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
Ebrahim Byagowi24b8b9b2018-04-23 19:03:57 +043083 hb_codepoint_t unicode,
Behdad Esfahbodc4641722011-07-07 23:47:19 -040084 void *user_data HB_UNUSED)
Behdad Esfahbod891c4752011-07-07 23:19:27 -040085{
86 return unicode;
87}
88
89static hb_script_t
Behdad Esfahbodc4641722011-07-07 23:47:19 -040090hb_unicode_script_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
91 hb_codepoint_t unicode HB_UNUSED,
92 void *user_data HB_UNUSED)
Behdad Esfahbod891c4752011-07-07 23:19:27 -040093{
94 return HB_SCRIPT_UNKNOWN;
95}
Behdad Esfahbodfb194b82011-04-20 02:00:47 -040096
Behdad Esfahbodc4641722011-07-07 23:47:19 -040097static hb_bool_t
Behdad Esfahbod22fdc662011-07-20 21:51:37 -040098hb_unicode_compose_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
Behdad Esfahbodc4641722011-07-07 23:47:19 -040099 hb_codepoint_t a HB_UNUSED,
100 hb_codepoint_t b HB_UNUSED,
101 hb_codepoint_t *ab HB_UNUSED,
102 void *user_data HB_UNUSED)
103{
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400104 return false;
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400105}
106
107static hb_bool_t
Behdad Esfahbod22fdc662011-07-20 21:51:37 -0400108hb_unicode_decompose_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400109 hb_codepoint_t ab HB_UNUSED,
110 hb_codepoint_t *a HB_UNUSED,
111 hb_codepoint_t *b HB_UNUSED,
112 void *user_data HB_UNUSED)
113{
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400114 return false;
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400115}
116
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400117
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700118#ifndef HB_DISABLE_DEPRECATED
Behdad Esfahbod378d2792012-07-31 21:36:16 -0400119static unsigned int
120hb_unicode_decompose_compatibility_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
121 hb_codepoint_t u HB_UNUSED,
122 hb_codepoint_t *decomposed HB_UNUSED,
123 void *user_data HB_UNUSED)
124{
125 return 0;
126}
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700127#endif
Behdad Esfahbod378d2792012-07-31 21:36:16 -0400128
Behdad Esfahbod25e25622019-07-17 09:35:56 -0700129#if !defined(HB_NO_UNICODE_FUNCS) && defined(HAVE_GLIB)
130#include "hb-glib.h"
131#endif
132#if !defined(HB_NO_UNICODE_FUNCS) && defined(HAVE_ICU) && defined(HAVE_ICU_BUILTIN)
133#include "hb-icu.h"
134#endif
Dominik Röttsches2e7021d2019-07-08 10:19:49 +0300135
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400136hb_unicode_funcs_t *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330137hb_unicode_funcs_get_default ()
Behdad Esfahbodd4bee9f2011-04-27 09:24:37 -0400138{
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400139#if !defined(HB_NO_UNICODE_FUNCS) && !defined(HB_NO_UCD)
140 return hb_ucd_get_unicode_funcs ();
Behdad Esfahbodb111b3d2019-04-10 15:38:15 -0400141#elif !defined(HB_NO_UNICODE_FUNCS) && defined(HAVE_GLIB)
Behdad Esfahbod4ef671f2018-10-29 22:46:19 -0700142 return hb_glib_get_unicode_funcs ();
Behdad Esfahbodb111b3d2019-04-10 15:38:15 -0400143#elif !defined(HB_NO_UNICODE_FUNCS) && defined(HAVE_ICU) && defined(HAVE_ICU_BUILTIN)
Behdad Esfahbod4ef671f2018-10-29 22:46:19 -0700144 return hb_icu_get_unicode_funcs ();
Behdad Esfahbodd5045a52012-08-11 21:26:25 -0400145#else
146#define HB_UNICODE_FUNCS_NIL 1
Behdad Esfahbod4ef671f2018-10-29 22:46:19 -0700147 return hb_unicode_funcs_get_empty ();
Behdad Esfahbodd5045a52012-08-11 21:26:25 -0400148#endif
Behdad Esfahbodd4bee9f2011-04-27 09:24:37 -0400149}
150
Behdad Esfahbodd5045a52012-08-11 21:26:25 -0400151#if !defined(HB_NO_UNICODE_FUNCS) && defined(HB_UNICODE_FUNCS_NIL)
Behdad Esfahbodcdcdfe62015-04-08 13:25:04 -0700152#error "Could not find any Unicode functions implementation, you have to provide your own"
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400153#error "Consider building hb-ucd.cc. If you absolutely want to build without any, check the code."
Behdad Esfahbod09732cc2014-03-19 12:00:17 -0700154#endif
Behdad Esfahbodd5045a52012-08-11 21:26:25 -0400155
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400156/**
Behdad Esfahbod085d4292013-09-12 17:14:33 -0400157 * hb_unicode_funcs_create: (Xconstructor)
Behdad Esfahbodb91904a2015-01-06 15:43:14 -0800158 * @parent: (nullable):
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400159 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330160 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400161 *
162 * Return value: (transfer full):
163 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430164 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400165 **/
Behdad Esfahbodd4bee9f2011-04-27 09:24:37 -0400166hb_unicode_funcs_t *
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400167hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
168{
169 hb_unicode_funcs_t *ufuncs;
170
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400171 if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400172 return hb_unicode_funcs_get_empty ();
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400173
Behdad Esfahbodc784c672011-05-02 15:59:57 -0400174 if (!parent)
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400175 parent = hb_unicode_funcs_get_empty ();
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400176
Behdad Esfahbodc784c672011-05-02 15:59:57 -0400177 hb_unicode_funcs_make_immutable (parent);
178 ufuncs->parent = hb_unicode_funcs_reference (parent);
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400179
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400180 ufuncs->func = parent->func;
Behdad Esfahbodc784c672011-05-02 15:59:57 -0400181
182 /* We can safely copy user_data from parent since we hold a reference
183 * onto it and it's immutable. We should not copy the destroy notifiers
184 * though. */
185 ufuncs->user_data = parent->user_data;
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400186
187 return ufuncs;
188}
189
Behdad Esfahbodbe4560a2012-06-05 18:14:03 -0400190
Behdad Esfahbod35066722018-08-06 06:17:48 -0700191DEFINE_NULL_INSTANCE (hb_unicode_funcs_t) =
192{
Behdad Esfahbodbe4560a2012-06-05 18:14:03 -0400193 HB_OBJECT_HEADER_STATIC,
194
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200195 nullptr, /* parent */
Behdad Esfahbodbe4560a2012-06-05 18:14:03 -0400196 {
197#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil,
198 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
199#undef HB_UNICODE_FUNC_IMPLEMENT
200 }
201};
202
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400203/**
204 * hb_unicode_funcs_get_empty:
205 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330206 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400207 *
208 * Return value: (transfer full):
209 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430210 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400211 **/
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400212hb_unicode_funcs_t *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330213hb_unicode_funcs_get_empty ()
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400214{
Behdad Esfahbod35066722018-08-06 06:17:48 -0700215 return const_cast<hb_unicode_funcs_t *> (&Null(hb_unicode_funcs_t));
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400216}
217
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400218/**
219 * hb_unicode_funcs_reference: (skip)
220 * @ufuncs: Unicode functions.
221 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330222 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400223 *
224 * Return value: (transfer full):
225 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430226 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400227 **/
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400228hb_unicode_funcs_t *
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400229hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
230{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400231 return hb_object_reference (ufuncs);
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400232}
233
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400234/**
235 * hb_unicode_funcs_destroy: (skip)
236 * @ufuncs: Unicode functions.
237 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330238 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400239 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430240 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400241 **/
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400242void
243hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
244{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400245 if (!hb_object_destroy (ufuncs)) return;
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400246
Behdad Esfahbod891c4752011-07-07 23:19:27 -0400247#define HB_UNICODE_FUNC_IMPLEMENT(name) \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400248 if (ufuncs->destroy.name) ufuncs->destroy.name (ufuncs->user_data.name);
249 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
250#undef HB_UNICODE_FUNC_IMPLEMENT
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400251
Behdad Esfahbodc784c672011-05-02 15:59:57 -0400252 hb_unicode_funcs_destroy (ufuncs->parent);
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400253
254 free (ufuncs);
255}
256
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400257/**
258 * hb_unicode_funcs_set_user_data: (skip)
259 * @ufuncs: Unicode functions.
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330260 * @key:
261 * @data:
262 * @destroy:
263 * @replace:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400264 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400265 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330266 *
267 * Return value:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400268 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430269 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400270 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400271hb_bool_t
272hb_unicode_funcs_set_user_data (hb_unicode_funcs_t *ufuncs,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330273 hb_user_data_key_t *key,
274 void * data,
275 hb_destroy_func_t destroy,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200276 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400277{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200278 return hb_object_set_user_data (ufuncs, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400279}
280
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400281/**
282 * hb_unicode_funcs_get_user_data: (skip)
283 * @ufuncs: Unicode functions.
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330284 * @key:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400285 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330286 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400287 *
288 * Return value: (transfer none):
289 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430290 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400291 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400292void *
293hb_unicode_funcs_get_user_data (hb_unicode_funcs_t *ufuncs,
Ebrahim Byagowi05584132019-10-01 13:49:55 +0330294 hb_user_data_key_t *key)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400295{
296 return hb_object_get_user_data (ufuncs, key);
297}
298
299
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400300/**
301 * hb_unicode_funcs_make_immutable:
302 * @ufuncs: Unicode functions.
303 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330304 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400305 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430306 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400307 **/
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400308void
309hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
310{
Behdad Esfahbod5570c872018-11-03 14:51:38 -0400311 if (hb_object_is_immutable (ufuncs))
Behdad Esfahbod90a0f9f2018-09-26 15:03:07 -0400312 return;
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400313
Behdad Esfahbod5570c872018-11-03 14:51:38 -0400314 hb_object_make_immutable (ufuncs);
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400315}
316
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400317/**
318 * hb_unicode_funcs_is_immutable:
319 * @ufuncs: Unicode functions.
320 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400321 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330322 *
323 * Return value:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400324 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430325 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400326 **/
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400327hb_bool_t
328hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs)
329{
Behdad Esfahbod5570c872018-11-03 14:51:38 -0400330 return hb_object_is_immutable (ufuncs);
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400331}
332
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400333/**
334 * hb_unicode_funcs_get_parent:
335 * @ufuncs: Unicode functions.
336 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400337 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330338 *
339 * Return value:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400340 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430341 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400342 **/
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400343hb_unicode_funcs_t *
344hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs)
345{
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400346 return ufuncs->parent ? ufuncs->parent : hb_unicode_funcs_get_empty ();
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400347}
348
349
Behdad Esfahbod891c4752011-07-07 23:19:27 -0400350#define HB_UNICODE_FUNC_IMPLEMENT(name) \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400351 \
352void \
353hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400354 hb_unicode_##name##_func_t func, \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400355 void *user_data, \
356 hb_destroy_func_t destroy) \
357{ \
Behdad Esfahbod5570c872018-11-03 14:51:38 -0400358 if (hb_object_is_immutable (ufuncs)) \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400359 return; \
360 \
361 if (ufuncs->destroy.name) \
362 ufuncs->destroy.name (ufuncs->user_data.name); \
363 \
364 if (func) { \
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400365 ufuncs->func.name = func; \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400366 ufuncs->user_data.name = user_data; \
367 ufuncs->destroy.name = destroy; \
368 } else { \
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400369 ufuncs->func.name = ufuncs->parent->func.name; \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400370 ufuncs->user_data.name = ufuncs->parent->user_data.name; \
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200371 ufuncs->destroy.name = nullptr; \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400372 } \
Behdad Esfahbod891c4752011-07-07 23:19:27 -0400373}
374
Behdad Esfahbod74703152012-08-01 17:01:59 -0400375HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
Behdad Esfahbod891c4752011-07-07 23:19:27 -0400376#undef HB_UNICODE_FUNC_IMPLEMENT
377
378
379#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400380 \
381return_type \
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400382hb_unicode_##name (hb_unicode_funcs_t *ufuncs, \
383 hb_codepoint_t unicode) \
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400384{ \
Behdad Esfahbod74703152012-08-01 17:01:59 -0400385 return ufuncs->name (unicode); \
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400386}
Behdad Esfahbod74703152012-08-01 17:01:59 -0400387HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400388#undef HB_UNICODE_FUNC_IMPLEMENT
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400389
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400390/**
391 * hb_unicode_compose:
392 * @ufuncs: Unicode functions.
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330393 * @a:
394 * @b:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400395 * @ab: (out):
396 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400397 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330398 *
399 * Return value:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400400 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200401 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400402 **/
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400403hb_bool_t
404hb_unicode_compose (hb_unicode_funcs_t *ufuncs,
405 hb_codepoint_t a,
406 hb_codepoint_t b,
407 hb_codepoint_t *ab)
408{
Behdad Esfahbod74703152012-08-01 17:01:59 -0400409 return ufuncs->compose (a, b, ab);
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400410}
411
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400412/**
413 * hb_unicode_decompose:
414 * @ufuncs: Unicode functions.
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330415 * @ab:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400416 * @a: (out):
417 * @b: (out):
418 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400419 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330420 *
421 * Return value:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400422 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200423 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400424 **/
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400425hb_bool_t
426hb_unicode_decompose (hb_unicode_funcs_t *ufuncs,
427 hb_codepoint_t ab,
428 hb_codepoint_t *a,
429 hb_codepoint_t *b)
430{
Behdad Esfahbod74703152012-08-01 17:01:59 -0400431 return ufuncs->decompose (ab, a, b);
Behdad Esfahbodc4641722011-07-07 23:47:19 -0400432}
Behdad Esfahbodfb194b82011-04-20 02:00:47 -0400433
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700434#ifndef HB_DISABLE_DEPRECATED
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400435/**
436 * hb_unicode_decompose_compatibility:
437 * @ufuncs: Unicode functions.
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330438 * @u:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400439 * @decomposed: (out):
440 *
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400441 *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330442 *
443 * Return value:
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400444 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200445 * Since: 0.9.2
Behdad Esfahbod314b1af2018-10-20 16:49:16 -0700446 * Deprecated: 2.0.0
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400447 **/
Behdad Esfahbod378d2792012-07-31 21:36:16 -0400448unsigned int
449hb_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs,
450 hb_codepoint_t u,
451 hb_codepoint_t *decomposed)
452{
Behdad Esfahbod74703152012-08-01 17:01:59 -0400453 return ufuncs->decompose_compatibility (u, decomposed);
Behdad Esfahbod378d2792012-07-31 21:36:16 -0400454}
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700455#endif
Behdad Esfahbod2db2a562012-04-05 16:40:37 -0400456
457
Behdad Esfahbod72987162019-06-26 14:51:17 -0700458#ifndef HB_NO_OT_SHAPE
Behdad Esfahbodc77ae402018-08-25 22:36:36 -0700459/* See hb-unicode.hh for details. */
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400460const uint8_t
461_hb_modified_combining_class[256] =
Behdad Esfahbod2db2a562012-04-05 16:40:37 -0400462{
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400463 0, /* HB_UNICODE_COMBINING_CLASS_NOT_REORDERED */
464 1, /* HB_UNICODE_COMBINING_CLASS_OVERLAY */
465 2, 3, 4, 5, 6,
466 7, /* HB_UNICODE_COMBINING_CLASS_NUKTA */
467 8, /* HB_UNICODE_COMBINING_CLASS_KANA_VOICING */
468 9, /* HB_UNICODE_COMBINING_CLASS_VIRAMA */
Behdad Esfahbod2db2a562012-04-05 16:40:37 -0400469
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400470 /* Hebrew */
Behdad Esfahbod21756932012-08-08 01:20:45 -0400471 HB_MODIFIED_COMBINING_CLASS_CCC10,
472 HB_MODIFIED_COMBINING_CLASS_CCC11,
473 HB_MODIFIED_COMBINING_CLASS_CCC12,
474 HB_MODIFIED_COMBINING_CLASS_CCC13,
475 HB_MODIFIED_COMBINING_CLASS_CCC14,
476 HB_MODIFIED_COMBINING_CLASS_CCC15,
477 HB_MODIFIED_COMBINING_CLASS_CCC16,
478 HB_MODIFIED_COMBINING_CLASS_CCC17,
479 HB_MODIFIED_COMBINING_CLASS_CCC18,
480 HB_MODIFIED_COMBINING_CLASS_CCC19,
481 HB_MODIFIED_COMBINING_CLASS_CCC20,
482 HB_MODIFIED_COMBINING_CLASS_CCC21,
483 HB_MODIFIED_COMBINING_CLASS_CCC22,
484 HB_MODIFIED_COMBINING_CLASS_CCC23,
485 HB_MODIFIED_COMBINING_CLASS_CCC24,
486 HB_MODIFIED_COMBINING_CLASS_CCC25,
487 HB_MODIFIED_COMBINING_CLASS_CCC26,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400488
489 /* Arabic */
Behdad Esfahbod21756932012-08-08 01:20:45 -0400490 HB_MODIFIED_COMBINING_CLASS_CCC27,
491 HB_MODIFIED_COMBINING_CLASS_CCC28,
492 HB_MODIFIED_COMBINING_CLASS_CCC29,
493 HB_MODIFIED_COMBINING_CLASS_CCC30,
494 HB_MODIFIED_COMBINING_CLASS_CCC31,
495 HB_MODIFIED_COMBINING_CLASS_CCC32,
496 HB_MODIFIED_COMBINING_CLASS_CCC33,
497 HB_MODIFIED_COMBINING_CLASS_CCC34,
498 HB_MODIFIED_COMBINING_CLASS_CCC35,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400499
500 /* Syriac */
Behdad Esfahbod21756932012-08-08 01:20:45 -0400501 HB_MODIFIED_COMBINING_CLASS_CCC36,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400502
503 37, 38, 39,
504 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
505 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
506 80, 81, 82, 83,
507
508 /* Telugu */
Behdad Esfahbod21756932012-08-08 01:20:45 -0400509 HB_MODIFIED_COMBINING_CLASS_CCC84,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400510 85, 86, 87, 88, 89, 90,
Behdad Esfahbod21756932012-08-08 01:20:45 -0400511 HB_MODIFIED_COMBINING_CLASS_CCC91,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400512 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
513
514 /* Thai */
Behdad Esfahbod21756932012-08-08 01:20:45 -0400515 HB_MODIFIED_COMBINING_CLASS_CCC103,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400516 104, 105, 106,
Behdad Esfahbod21756932012-08-08 01:20:45 -0400517 HB_MODIFIED_COMBINING_CLASS_CCC107,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400518 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
519
520 /* Lao */
Behdad Esfahbod21756932012-08-08 01:20:45 -0400521 HB_MODIFIED_COMBINING_CLASS_CCC118,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400522 119, 120, 121,
Behdad Esfahbod21756932012-08-08 01:20:45 -0400523 HB_MODIFIED_COMBINING_CLASS_CCC122,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400524 123, 124, 125, 126, 127, 128,
525
526 /* Tibetan */
Behdad Esfahbod21756932012-08-08 01:20:45 -0400527 HB_MODIFIED_COMBINING_CLASS_CCC129,
528 HB_MODIFIED_COMBINING_CLASS_CCC130,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400529 131,
Behdad Esfahbod56c9e7c2012-08-09 21:12:30 -0400530 HB_MODIFIED_COMBINING_CLASS_CCC132,
Behdad Esfahbod6adf4172012-08-01 18:07:42 -0400531 133, 134, 135, 136, 137, 138, 139,
532
533
534 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
535 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
536 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
537 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
538 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
539 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
540
541 200, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT */
542 201,
543 202, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW */
544 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
545 214, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE */
546 215,
547 216, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT */
548 217,
549 218, /* HB_UNICODE_COMBINING_CLASS_BELOW_LEFT */
550 219,
551 220, /* HB_UNICODE_COMBINING_CLASS_BELOW */
552 221,
553 222, /* HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT */
554 223,
555 224, /* HB_UNICODE_COMBINING_CLASS_LEFT */
556 225,
557 226, /* HB_UNICODE_COMBINING_CLASS_RIGHT */
558 227,
559 228, /* HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT */
560 229,
561 230, /* HB_UNICODE_COMBINING_CLASS_ABOVE */
562 231,
563 232, /* HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT */
564 233, /* HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW */
565 234, /* HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE */
566 235, 236, 237, 238, 239,
567 240, /* HB_UNICODE_COMBINING_CLASS_IOTA_SUBSCRIPT */
568 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
569 255, /* HB_UNICODE_COMBINING_CLASS_INVALID */
570};
Behdad Esfahbod72987162019-06-26 14:51:17 -0700571#endif
Behdad Esfahbod1e8f1952018-10-03 17:46:48 +0200572
573
574/*
575 * Emoji
576 */
Behdad Esfahbodcd653052019-06-26 14:57:48 -0700577#ifndef HB_NO_EMOJI_SEQUENCES
Behdad Esfahbod1e8f1952018-10-03 17:46:48 +0200578
579#include "hb-unicode-emoji-table.hh"
580
581bool
582_hb_unicode_is_emoji_Extended_Pictographic (hb_codepoint_t cp)
583{
Behdad Esfahbod1cdd0fa2019-06-26 14:49:15 -0700584 return _hb_emoji_is_Extended_Pictographic (cp);
Behdad Esfahbod1e8f1952018-10-03 17:46:48 +0200585}
Behdad Esfahbod5130c902019-06-26 14:29:39 -0700586#endif