Behdad Esfahbod | 83f3467 | 2010-05-21 13:43:49 +0100 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2009,2010 Red Hat, Inc. |
Behdad Esfahbod | cad3821 | 2012-03-07 17:13:25 -0500 | [diff] [blame] | 3 | * Copyright © 2011,2012 Google, Inc. |
Behdad Esfahbod | 83f3467 | 2010-05-21 13:43:49 +0100 | [diff] [blame] | 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 |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | 83f3467 | 2010-05-21 13:43:49 +0100 | [diff] [blame] | 27 | */ |
| 28 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 29 | #include "hb.hh" |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 30 | #include "hb-machinery.hh" |
Behdad Esfahbod | b8d6183 | 2011-05-05 15:14:04 -0400 | [diff] [blame] | 31 | |
Behdad Esfahbod | 34fb552 | 2011-05-06 00:04:28 -0400 | [diff] [blame] | 32 | #include <locale.h> |
| 33 | |
Ebrahim Byagowi | 19b8eb0 | 2019-06-11 01:33:30 +0430 | [diff] [blame] | 34 | #ifdef HB_NO_SETLOCALE |
| 35 | #define setlocale(Category, Locale) "C" |
| 36 | #endif |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 37 | |
Behdad Esfahbod | 00cf4e5 | 2018-10-27 04:07:33 -0700 | [diff] [blame] | 38 | /** |
| 39 | * SECTION:hb-common |
Behdad Esfahbod | cf5fa57 | 2018-10-27 04:50:38 -0700 | [diff] [blame] | 40 | * @title: hb-common |
Behdad Esfahbod | 00cf4e5 | 2018-10-27 04:07:33 -0700 | [diff] [blame] | 41 | * @short_description: Common data types |
| 42 | * @include: hb.h |
| 43 | * |
| 44 | * Common data types used across HarfBuzz are defined here. |
| 45 | **/ |
| 46 | |
| 47 | |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 48 | /* hb_options_t */ |
| 49 | |
Behdad Esfahbod | 4bc16ac | 2018-07-31 21:05:51 -0700 | [diff] [blame] | 50 | hb_atomic_int_t _hb_options; |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 51 | |
| 52 | void |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 53 | _hb_options_init () |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 54 | { |
| 55 | hb_options_union_t u; |
| 56 | u.i = 0; |
Bruce Mitchener | 8d1e479 | 2018-10-18 22:18:42 +0700 | [diff] [blame] | 57 | u.opts.initialized = true; |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 58 | |
Behdad Esfahbod | 38a7a8a | 2018-10-10 17:44:46 -0400 | [diff] [blame] | 59 | const char *c = getenv ("HB_OPTIONS"); |
| 60 | if (c) |
| 61 | { |
| 62 | while (*c) |
| 63 | { |
| 64 | const char *p = strchr (c, ':'); |
| 65 | if (!p) |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 66 | p = c + strlen (c); |
Behdad Esfahbod | 38a7a8a | 2018-10-10 17:44:46 -0400 | [diff] [blame] | 67 | |
| 68 | #define OPTION(name, symbol) \ |
GaryQian | ccf1448 | 2019-06-24 12:57:13 -0700 | [diff] [blame] | 69 | if (0 == strncmp (c, name, p - c) && strlen (name) == static_cast<size_t>(p - c)) do { u.opts.symbol = true; } while (0) |
Behdad Esfahbod | 38a7a8a | 2018-10-10 17:44:46 -0400 | [diff] [blame] | 70 | |
| 71 | OPTION ("uniscribe-bug-compatible", uniscribe_bug_compatible); |
Behdad Esfahbod | 38a7a8a | 2018-10-10 17:44:46 -0400 | [diff] [blame] | 72 | |
| 73 | #undef OPTION |
| 74 | |
| 75 | c = *p ? p + 1 : p; |
| 76 | } |
| 77 | |
| 78 | } |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 79 | |
| 80 | /* This is idempotent and threadsafe. */ |
Behdad Esfahbod | 4bc16ac | 2018-07-31 21:05:51 -0700 | [diff] [blame] | 81 | _hb_options.set_relaxed (u.i); |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 84 | |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 85 | /* hb_tag_t */ |
| 86 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 87 | /** |
| 88 | * hb_tag_from_string: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 89 | * @str: (array length=len) (element-type uint8_t): String to convert |
| 90 | * @len: Length of @str, or -1 if it is %NULL-terminated |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 91 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 92 | * Converts a string into an #hb_tag_t. Valid tags |
| 93 | * are four characters. Shorter input strings will be |
| 94 | * padded with spaces. Longer input strings will be |
| 95 | * truncated. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 96 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 97 | * Return value: The #hb_tag_t corresponding to @str |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 98 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 99 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 100 | **/ |
Behdad Esfahbod | 83f3467 | 2010-05-21 13:43:49 +0100 | [diff] [blame] | 101 | hb_tag_t |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 102 | hb_tag_from_string (const char *str, int len) |
Behdad Esfahbod | 83f3467 | 2010-05-21 13:43:49 +0100 | [diff] [blame] | 103 | { |
| 104 | char tag[4]; |
| 105 | unsigned int i; |
| 106 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 107 | if (!str || !len || !*str) |
Behdad Esfahbod | 7ff7401 | 2011-04-11 13:27:30 -0400 | [diff] [blame] | 108 | return HB_TAG_NONE; |
| 109 | |
Behdad Esfahbod | 4c9fe88 | 2011-08-26 09:18:53 +0200 | [diff] [blame] | 110 | if (len < 0 || len > 4) |
| 111 | len = 4; |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 112 | for (i = 0; i < (unsigned) len && str[i]; i++) |
| 113 | tag[i] = str[i]; |
Behdad Esfahbod | 83f3467 | 2010-05-21 13:43:49 +0100 | [diff] [blame] | 114 | for (; i < 4; i++) |
| 115 | tag[i] = ' '; |
| 116 | |
Behdad Esfahbod | 8eaff98 | 2017-10-31 15:30:06 -0600 | [diff] [blame] | 117 | return HB_TAG (tag[0], tag[1], tag[2], tag[3]); |
Behdad Esfahbod | 83f3467 | 2010-05-21 13:43:49 +0100 | [diff] [blame] | 118 | } |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 119 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 120 | /** |
| 121 | * hb_tag_to_string: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 122 | * @tag: #hb_tag_t to convert |
| 123 | * @buf: (out caller-allocates) (array fixed-size=4) (element-type uint8_t): Converted string |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 124 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 125 | * Converts an #hb_tag_t to a string and returns it in @buf. |
| 126 | * Strings will be four characters long. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 127 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 128 | * Since: 0.9.5 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 129 | **/ |
Behdad Esfahbod | e30ebd2 | 2012-09-06 22:09:06 -0400 | [diff] [blame] | 130 | void |
| 131 | hb_tag_to_string (hb_tag_t tag, char *buf) |
| 132 | { |
| 133 | buf[0] = (char) (uint8_t) (tag >> 24); |
| 134 | buf[1] = (char) (uint8_t) (tag >> 16); |
| 135 | buf[2] = (char) (uint8_t) (tag >> 8); |
| 136 | buf[3] = (char) (uint8_t) (tag >> 0); |
| 137 | } |
| 138 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 139 | |
Behdad Esfahbod | 39a840a | 2011-04-27 14:48:19 -0400 | [diff] [blame] | 140 | /* hb_direction_t */ |
| 141 | |
| 142 | const char direction_strings[][4] = { |
| 143 | "ltr", |
| 144 | "rtl", |
| 145 | "ttb", |
| 146 | "btt" |
| 147 | }; |
| 148 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 149 | /** |
| 150 | * hb_direction_from_string: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 151 | * @str: (array length=len) (element-type uint8_t): String to convert |
| 152 | * @len: Length of @str, or -1 if it is %NULL-terminated |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 153 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 154 | * Converts a string to an #hb_direction_t. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 155 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 156 | * Matching is loose and applies only to the first letter. For |
| 157 | * examples, "LTR" and "left-to-right" will both return #HB_DIRECTION_LTR. |
Ebrahim Byagowi | 70d3654 | 2018-03-30 05:00:28 +0430 | [diff] [blame] | 158 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 159 | * Unmatched strings will return #HB_DIRECTION_INVALID. |
| 160 | * |
| 161 | * Return value: The #hb_direction_t matching @str |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 162 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 163 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 164 | **/ |
Behdad Esfahbod | 39a840a | 2011-04-27 14:48:19 -0400 | [diff] [blame] | 165 | hb_direction_t |
Behdad Esfahbod | 4c9fe88 | 2011-08-26 09:18:53 +0200 | [diff] [blame] | 166 | hb_direction_from_string (const char *str, int len) |
Behdad Esfahbod | 39a840a | 2011-04-27 14:48:19 -0400 | [diff] [blame] | 167 | { |
Behdad Esfahbod | 4c9fe88 | 2011-08-26 09:18:53 +0200 | [diff] [blame] | 168 | if (unlikely (!str || !len || !*str)) |
Behdad Esfahbod | 39a840a | 2011-04-27 14:48:19 -0400 | [diff] [blame] | 169 | return HB_DIRECTION_INVALID; |
| 170 | |
| 171 | /* Lets match loosely: just match the first letter, such that |
| 172 | * all of "ltr", "left-to-right", etc work! |
| 173 | */ |
| 174 | char c = TOLOWER (str[0]); |
| 175 | for (unsigned int i = 0; i < ARRAY_LENGTH (direction_strings); i++) |
| 176 | if (c == direction_strings[i][0]) |
Behdad Esfahbod | 4bf90f6 | 2012-04-12 17:38:23 -0400 | [diff] [blame] | 177 | return (hb_direction_t) (HB_DIRECTION_LTR + i); |
Behdad Esfahbod | 39a840a | 2011-04-27 14:48:19 -0400 | [diff] [blame] | 178 | |
| 179 | return HB_DIRECTION_INVALID; |
| 180 | } |
| 181 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 182 | /** |
| 183 | * hb_direction_to_string: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 184 | * @direction: The #hb_direction_t to convert |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 185 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 186 | * Converts an #hb_direction_t to a string. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 187 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 188 | * Return value: (transfer none): The string corresponding to @direction |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 189 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 190 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 191 | **/ |
Behdad Esfahbod | 39a840a | 2011-04-27 14:48:19 -0400 | [diff] [blame] | 192 | const char * |
| 193 | hb_direction_to_string (hb_direction_t direction) |
| 194 | { |
Behdad Esfahbod | 4bf90f6 | 2012-04-12 17:38:23 -0400 | [diff] [blame] | 195 | if (likely ((unsigned int) (direction - HB_DIRECTION_LTR) |
| 196 | < ARRAY_LENGTH (direction_strings))) |
| 197 | return direction_strings[direction - HB_DIRECTION_LTR]; |
Behdad Esfahbod | 39a840a | 2011-04-27 14:48:19 -0400 | [diff] [blame] | 198 | |
| 199 | return "invalid"; |
| 200 | } |
| 201 | |
| 202 | |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 203 | /* hb_language_t */ |
| 204 | |
Behdad Esfahbod | 1bc1cb3 | 2012-06-16 15:21:55 -0400 | [diff] [blame] | 205 | struct hb_language_impl_t { |
Behdad Esfahbod | 3cbdf70 | 2011-04-15 12:32:06 -0400 | [diff] [blame] | 206 | const char s[1]; |
| 207 | }; |
| 208 | |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 209 | static const char canon_map[256] = { |
| 210 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 211 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 212 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, |
| 213 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0, |
David Corbett | 018ba46 | 2018-11-23 13:21:22 -0500 | [diff] [blame] | 214 | 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 215 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, '-', |
| 216 | 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', |
| 217 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, 0 |
| 218 | }; |
| 219 | |
Behdad Esfahbod | f3b170b | 2015-04-08 16:26:24 -0700 | [diff] [blame] | 220 | static bool |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 221 | lang_equal (hb_language_t v1, |
| 222 | const void *v2) |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 223 | { |
Behdad Esfahbod | c57d454 | 2011-04-20 18:50:27 -0400 | [diff] [blame] | 224 | const unsigned char *p1 = (const unsigned char *) v1; |
| 225 | const unsigned char *p2 = (const unsigned char *) v2; |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 226 | |
Chris Peterson | aacca37 | 2017-04-17 23:25:24 -0700 | [diff] [blame] | 227 | while (*p1 && *p1 == canon_map[*p2]) { |
| 228 | p1++; |
| 229 | p2++; |
| 230 | } |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 231 | |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 232 | return *p1 == canon_map[*p2]; |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | #if 0 |
| 236 | static unsigned int |
| 237 | lang_hash (const void *key) |
| 238 | { |
| 239 | const unsigned char *p = key; |
| 240 | unsigned int h = 0; |
| 241 | while (canon_map[*p]) |
| 242 | { |
| 243 | h = (h << 5) - h + canon_map[*p]; |
| 244 | p++; |
| 245 | } |
| 246 | |
| 247 | return h; |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | |
Behdad Esfahbod | b45f32e | 2011-05-05 15:00:43 -0400 | [diff] [blame] | 252 | struct hb_language_item_t { |
| 253 | |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 254 | struct hb_language_item_t *next; |
Behdad Esfahbod | b45f32e | 2011-05-05 15:00:43 -0400 | [diff] [blame] | 255 | hb_language_t lang; |
| 256 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 257 | bool operator == (const char *s) const |
| 258 | { return lang_equal (lang, s); } |
Behdad Esfahbod | b45f32e | 2011-05-05 15:00:43 -0400 | [diff] [blame] | 259 | |
Behdad Esfahbod | bb48bf5 | 2021-07-08 10:53:45 -0600 | [diff] [blame] | 260 | hb_language_item_t & operator = (const char *s) |
| 261 | { |
| 262 | /* We can't call strdup(), because we allow custom allocators. */ |
Sebastian Rasmussen | 92e2c4b | 2017-05-29 12:53:30 -0500 | [diff] [blame] | 263 | size_t len = strlen(s) + 1; |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 264 | lang = (hb_language_t) hb_malloc(len); |
Behdad Esfahbod | 7dba306 | 2017-06-01 11:44:42 -0400 | [diff] [blame] | 265 | if (likely (lang)) |
| 266 | { |
| 267 | memcpy((unsigned char *) lang, s, len); |
| 268 | for (unsigned char *p = (unsigned char *) lang; *p; p++) |
| 269 | *p = canon_map[*p]; |
| 270 | } |
Behdad Esfahbod | b45f32e | 2011-05-05 15:00:43 -0400 | [diff] [blame] | 271 | |
| 272 | return *this; |
| 273 | } |
| 274 | |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 275 | void fini () { hb_free ((void *) lang); } |
Behdad Esfahbod | b45f32e | 2011-05-05 15:00:43 -0400 | [diff] [blame] | 276 | }; |
| 277 | |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 278 | |
Behdad Esfahbod | bb48bf5 | 2021-07-08 10:53:45 -0600 | [diff] [blame] | 279 | /* Thread-safe lockfree language list */ |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 280 | |
Behdad Esfahbod | 1f73809 | 2018-08-09 00:22:37 -0700 | [diff] [blame] | 281 | static hb_atomic_ptr_t <hb_language_item_t> langs; |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 282 | |
Behdad Esfahbod | b89c7fd | 2018-11-21 12:32:48 -0500 | [diff] [blame] | 283 | #if HB_USE_ATEXIT |
Behdad Esfahbod | 3ca69c8 | 2017-09-14 20:50:35 -0400 | [diff] [blame] | 284 | static void |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 285 | free_langs () |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 286 | { |
Behdad Esfahbod | 5aa2c6e | 2018-03-28 15:33:51 -0700 | [diff] [blame] | 287 | retry: |
Behdad Esfahbod | f6fc557 | 2018-11-05 13:23:54 -0500 | [diff] [blame] | 288 | hb_language_item_t *first_lang = langs; |
Behdad Esfahbod | 1f73809 | 2018-08-09 00:22:37 -0700 | [diff] [blame] | 289 | if (unlikely (!langs.cmpexch (first_lang, nullptr))) |
Behdad Esfahbod | 5aa2c6e | 2018-03-28 15:33:51 -0700 | [diff] [blame] | 290 | goto retry; |
| 291 | |
| 292 | while (first_lang) { |
| 293 | hb_language_item_t *next = first_lang->next; |
Behdad Esfahbod | a60ba79 | 2018-05-01 19:01:25 -0400 | [diff] [blame] | 294 | first_lang->fini (); |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 295 | hb_free (first_lang); |
Behdad Esfahbod | 5aa2c6e | 2018-03-28 15:33:51 -0700 | [diff] [blame] | 296 | first_lang = next; |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 297 | } |
| 298 | } |
jfkthame | 0082dbe | 2014-03-16 08:25:17 +0000 | [diff] [blame] | 299 | #endif |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 300 | |
| 301 | static hb_language_item_t * |
| 302 | lang_find_or_insert (const char *key) |
| 303 | { |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 304 | retry: |
Behdad Esfahbod | f6fc557 | 2018-11-05 13:23:54 -0500 | [diff] [blame] | 305 | hb_language_item_t *first_lang = langs; |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 306 | |
| 307 | for (hb_language_item_t *lang = first_lang; lang; lang = lang->next) |
| 308 | if (*lang == key) |
| 309 | return lang; |
| 310 | |
| 311 | /* Not found; allocate one. */ |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 312 | hb_language_item_t *lang = (hb_language_item_t *) hb_calloc (1, sizeof (hb_language_item_t)); |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 313 | if (unlikely (!lang)) |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 314 | return nullptr; |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 315 | lang->next = first_lang; |
| 316 | *lang = key; |
Behdad Esfahbod | 7dba306 | 2017-06-01 11:44:42 -0400 | [diff] [blame] | 317 | if (unlikely (!lang->lang)) |
| 318 | { |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 319 | hb_free (lang); |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 320 | return nullptr; |
Behdad Esfahbod | 7dba306 | 2017-06-01 11:44:42 -0400 | [diff] [blame] | 321 | } |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 322 | |
Behdad Esfahbod | 1f73809 | 2018-08-09 00:22:37 -0700 | [diff] [blame] | 323 | if (unlikely (!langs.cmpexch (first_lang, lang))) |
| 324 | { |
Behdad Esfahbod | a60ba79 | 2018-05-01 19:01:25 -0400 | [diff] [blame] | 325 | lang->fini (); |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 326 | hb_free (lang); |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 327 | goto retry; |
| 328 | } |
| 329 | |
Behdad Esfahbod | b89c7fd | 2018-11-21 12:32:48 -0500 | [diff] [blame] | 330 | #if HB_USE_ATEXIT |
Behdad Esfahbod | 04aed57 | 2012-06-05 18:30:19 -0400 | [diff] [blame] | 331 | if (!first_lang) |
| 332 | atexit (free_langs); /* First person registers atexit() callback. */ |
Behdad Esfahbod | 093171c | 2012-06-05 18:00:45 -0400 | [diff] [blame] | 333 | #endif |
| 334 | |
| 335 | return lang; |
| 336 | } |
| 337 | |
Behdad Esfahbod | b8d6183 | 2011-05-05 15:14:04 -0400 | [diff] [blame] | 338 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 339 | /** |
| 340 | * hb_language_from_string: |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 341 | * @str: (array length=len) (element-type uint8_t): a string representing |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 342 | * a BCP 47 language tag |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 343 | * @len: length of the @str, or -1 if it is %NULL-terminated. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 344 | * |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 345 | * Converts @str representing a BCP 47 language tag to the corresponding |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 346 | * #hb_language_t. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 347 | * |
Khaled Hosny | 04f89e8 | 2015-04-10 17:49:01 +0200 | [diff] [blame] | 348 | * Return value: (transfer none): |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 349 | * The #hb_language_t corresponding to the BCP 47 language tag. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 350 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 351 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 352 | **/ |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 353 | hb_language_t |
Behdad Esfahbod | 4c9fe88 | 2011-08-26 09:18:53 +0200 | [diff] [blame] | 354 | hb_language_from_string (const char *str, int len) |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 355 | { |
Behdad Esfahbod | 4c9fe88 | 2011-08-26 09:18:53 +0200 | [diff] [blame] | 356 | if (!str || !len || !*str) |
Behdad Esfahbod | 1a64f6e | 2011-05-13 22:55:32 -0400 | [diff] [blame] | 357 | return HB_LANGUAGE_INVALID; |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 358 | |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 359 | hb_language_item_t *item = nullptr; |
Behdad Esfahbod | 48360ec | 2013-09-26 16:48:42 -0400 | [diff] [blame] | 360 | if (len >= 0) |
| 361 | { |
Behdad Esfahbod | dac8602 | 2014-06-03 17:57:00 -0400 | [diff] [blame] | 362 | /* NUL-terminate it. */ |
Behdad Esfahbod | f3159ba | 2015-09-29 14:34:56 +0100 | [diff] [blame] | 363 | char strbuf[64]; |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 364 | len = hb_min (len, (int) sizeof (strbuf) - 1); |
Behdad Esfahbod | dac8602 | 2014-06-03 17:57:00 -0400 | [diff] [blame] | 365 | memcpy (strbuf, str, len); |
Behdad Esfahbod | 4c9fe88 | 2011-08-26 09:18:53 +0200 | [diff] [blame] | 366 | strbuf[len] = '\0'; |
Behdad Esfahbod | f3159ba | 2015-09-29 14:34:56 +0100 | [diff] [blame] | 367 | item = lang_find_or_insert (strbuf); |
Behdad Esfahbod | 4c9fe88 | 2011-08-26 09:18:53 +0200 | [diff] [blame] | 368 | } |
Behdad Esfahbod | f3159ba | 2015-09-29 14:34:56 +0100 | [diff] [blame] | 369 | else |
| 370 | item = lang_find_or_insert (str); |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 371 | |
Behdad Esfahbod | 1a64f6e | 2011-05-13 22:55:32 -0400 | [diff] [blame] | 372 | return likely (item) ? item->lang : HB_LANGUAGE_INVALID; |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 373 | } |
| 374 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 375 | /** |
| 376 | * hb_language_to_string: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 377 | * @language: The #hb_language_t to convert |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 378 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 379 | * Converts an #hb_language_t to a string. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 380 | * |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 381 | * Return value: (transfer none): |
| 382 | * A %NULL-terminated string representing the @language. Must not be freed by |
| 383 | * the caller. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 384 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 385 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 386 | **/ |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 387 | const char * |
| 388 | hb_language_to_string (hb_language_t language) |
| 389 | { |
Ebrahim Byagowi | e6909ee | 2019-09-18 22:12:25 +0430 | [diff] [blame] | 390 | if (unlikely (!language)) return nullptr; |
Ebrahim Byagowi | d8af9ee | 2019-09-18 00:47:55 +0430 | [diff] [blame] | 391 | |
Behdad Esfahbod | 3cbdf70 | 2011-04-15 12:32:06 -0400 | [diff] [blame] | 392 | return language->s; |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 393 | } |
| 394 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 395 | /** |
| 396 | * hb_language_get_default: |
| 397 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 398 | * Fetch the default language from current locale. |
Ebrahim Byagowi | 70d3654 | 2018-03-30 05:00:28 +0430 | [diff] [blame] | 399 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 400 | * <note>Note that the first time this function is called, it calls |
Behdad Esfahbod | ba0f0f1 | 2018-09-30 03:49:52 -0400 | [diff] [blame] | 401 | * "setlocale (LC_CTYPE, nullptr)" to fetch current locale. The underlying |
| 402 | * setlocale function is, in many implementations, NOT threadsafe. To avoid |
| 403 | * problems, call this function once before multiple threads can call it. |
| 404 | * This function is only used from hb_buffer_guess_segment_properties() by |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 405 | * HarfBuzz itself.</note> |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 406 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 407 | * Return value: (transfer none): The default language of the locale as |
| 408 | * an #hb_language_t |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 409 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 410 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 411 | **/ |
Behdad Esfahbod | 34fb552 | 2011-05-06 00:04:28 -0400 | [diff] [blame] | 412 | hb_language_t |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 413 | hb_language_get_default () |
Behdad Esfahbod | 34fb552 | 2011-05-06 00:04:28 -0400 | [diff] [blame] | 414 | { |
Behdad Esfahbod | 1f73809 | 2018-08-09 00:22:37 -0700 | [diff] [blame] | 415 | static hb_atomic_ptr_t <hb_language_t> default_language; |
Behdad Esfahbod | 34fb552 | 2011-05-06 00:04:28 -0400 | [diff] [blame] | 416 | |
Behdad Esfahbod | f6fc557 | 2018-11-05 13:23:54 -0500 | [diff] [blame] | 417 | hb_language_t language = default_language; |
Behdad Esfahbod | 1f73809 | 2018-08-09 00:22:37 -0700 | [diff] [blame] | 418 | if (unlikely (language == HB_LANGUAGE_INVALID)) |
| 419 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 420 | language = hb_language_from_string (setlocale (LC_CTYPE, nullptr), -1); |
Behdad Esfahbod | 1f73809 | 2018-08-09 00:22:37 -0700 | [diff] [blame] | 421 | (void) default_language.cmpexch (HB_LANGUAGE_INVALID, language); |
Behdad Esfahbod | 34fb552 | 2011-05-06 00:04:28 -0400 | [diff] [blame] | 422 | } |
| 423 | |
Behdad Esfahbod | 1f73809 | 2018-08-09 00:22:37 -0700 | [diff] [blame] | 424 | return language; |
Behdad Esfahbod | 34fb552 | 2011-05-06 00:04:28 -0400 | [diff] [blame] | 425 | } |
| 426 | |
Behdad Esfahbod | 8e4bb3c | 2011-04-11 17:55:58 -0400 | [diff] [blame] | 427 | |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 428 | /* hb_script_t */ |
| 429 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 430 | /** |
| 431 | * hb_script_from_iso15924_tag: |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 432 | * @tag: an #hb_tag_t representing an ISO 15924 tag. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 433 | * |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 434 | * Converts an ISO 15924 script tag to a corresponding #hb_script_t. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 435 | * |
Ebrahim Byagowi | 70d3654 | 2018-03-30 05:00:28 +0430 | [diff] [blame] | 436 | * Return value: |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 437 | * An #hb_script_t corresponding to the ISO 15924 tag. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 438 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 439 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 440 | **/ |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 441 | hb_script_t |
| 442 | hb_script_from_iso15924_tag (hb_tag_t tag) |
| 443 | { |
Behdad Esfahbod | f144a8e | 2011-04-20 02:54:42 -0400 | [diff] [blame] | 444 | if (unlikely (tag == HB_TAG_NONE)) |
| 445 | return HB_SCRIPT_INVALID; |
| 446 | |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 447 | /* Be lenient, adjust case (one capital letter followed by three small letters) */ |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 448 | tag = (tag & 0xDFDFDFDFu) | 0x00202020u; |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 449 | |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 450 | switch (tag) { |
Behdad Esfahbod | d02985e | 2011-05-02 12:35:14 -0400 | [diff] [blame] | 451 | |
| 452 | /* These graduated from the 'Q' private-area codes, but |
| 453 | * the old code is still aliased by Unicode, and the Qaai |
| 454 | * one in use by ICU. */ |
| 455 | case HB_TAG('Q','a','a','i'): return HB_SCRIPT_INHERITED; |
| 456 | case HB_TAG('Q','a','a','c'): return HB_SCRIPT_COPTIC; |
| 457 | |
Ebrahim Byagowi | f24b0b9 | 2018-04-12 13:40:45 +0430 | [diff] [blame] | 458 | /* Script variants from https://unicode.org/iso15924/ */ |
David Corbett | 3bd43bd | 2020-11-16 21:55:02 -0500 | [diff] [blame] | 459 | case HB_TAG('A','r','a','n'): return HB_SCRIPT_ARABIC; |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 460 | case HB_TAG('C','y','r','s'): return HB_SCRIPT_CYRILLIC; |
David Corbett | 3bd43bd | 2020-11-16 21:55:02 -0500 | [diff] [blame] | 461 | case HB_TAG('G','e','o','k'): return HB_SCRIPT_GEORGIAN; |
| 462 | case HB_TAG('H','a','n','s'): return HB_SCRIPT_HAN; |
| 463 | case HB_TAG('H','a','n','t'): return HB_SCRIPT_HAN; |
| 464 | case HB_TAG('J','a','m','o'): return HB_SCRIPT_HANGUL; |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 465 | case HB_TAG('L','a','t','f'): return HB_SCRIPT_LATIN; |
| 466 | case HB_TAG('L','a','t','g'): return HB_SCRIPT_LATIN; |
| 467 | case HB_TAG('S','y','r','e'): return HB_SCRIPT_SYRIAC; |
| 468 | case HB_TAG('S','y','r','j'): return HB_SCRIPT_SYRIAC; |
| 469 | case HB_TAG('S','y','r','n'): return HB_SCRIPT_SYRIAC; |
| 470 | } |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 471 | |
| 472 | /* If it looks right, just use the tag as a script */ |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 473 | if (((uint32_t) tag & 0xE0E0E0E0u) == 0x40606060u) |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 474 | return (hb_script_t) tag; |
| 475 | |
| 476 | /* Otherwise, return unknown */ |
| 477 | return HB_SCRIPT_UNKNOWN; |
| 478 | } |
| 479 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 480 | /** |
| 481 | * hb_script_from_string: |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 482 | * @str: (array length=len) (element-type uint8_t): a string representing an |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 483 | * ISO 15924 tag. |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 484 | * @len: length of the @str, or -1 if it is %NULL-terminated. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 485 | * |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 486 | * Converts a string @str representing an ISO 15924 script tag to a |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 487 | * corresponding #hb_script_t. Shorthand for hb_tag_from_string() then |
| 488 | * hb_script_from_iso15924_tag(). |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 489 | * |
Ebrahim Byagowi | 70d3654 | 2018-03-30 05:00:28 +0430 | [diff] [blame] | 490 | * Return value: |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 491 | * An #hb_script_t corresponding to the ISO 15924 tag. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 492 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 493 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 494 | **/ |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 495 | hb_script_t |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 496 | hb_script_from_string (const char *str, int len) |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 497 | { |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 498 | return hb_script_from_iso15924_tag (hb_tag_from_string (str, len)); |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 499 | } |
| 500 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 501 | /** |
| 502 | * hb_script_to_iso15924_tag: |
David Corbett | 5daeff3 | 2019-04-17 09:11:44 -0400 | [diff] [blame] | 503 | * @script: an #hb_script_t to convert. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 504 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 505 | * Converts an #hb_script_t to a corresponding ISO 15924 script tag. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 506 | * |
Khaled Hosny | 8ab797c | 2015-12-29 17:42:16 +0400 | [diff] [blame] | 507 | * Return value: |
Evgeniy Reizner | b618e0a | 2019-12-15 16:26:50 +0200 | [diff] [blame] | 508 | * An #hb_tag_t representing an ISO 15924 script tag. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 509 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 510 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 511 | **/ |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 512 | hb_tag_t |
| 513 | hb_script_to_iso15924_tag (hb_script_t script) |
| 514 | { |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 515 | return (hb_tag_t) script; |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 518 | /** |
| 519 | * hb_script_get_horizontal_direction: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 520 | * @script: The #hb_script_t to query |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 521 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 522 | * Fetches the #hb_direction_t of a script when it is |
| 523 | * set horizontally. All right-to-left scripts will return |
| 524 | * #HB_DIRECTION_RTL. All left-to-right scripts will return |
Khaled Hosny | 8586f15 | 2020-12-24 22:23:47 +0200 | [diff] [blame] | 525 | * #HB_DIRECTION_LTR. Scripts that can be written either |
| 526 | * horizontally or vertically will return #HB_DIRECTION_INVALID. |
| 527 | * Unknown scripts will return #HB_DIRECTION_LTR. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 528 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 529 | * Return value: The horizontal #hb_direction_t of @script |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 530 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 531 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 532 | **/ |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 533 | hb_direction_t |
| 534 | hb_script_get_horizontal_direction (hb_script_t script) |
| 535 | { |
Ebrahim Byagowi | f24b0b9 | 2018-04-12 13:40:45 +0430 | [diff] [blame] | 536 | /* https://docs.google.com/spreadsheets/d/1Y90M0Ie3MUJ6UVCRDOypOtijlMDLNNyyLk36T6iMu0o */ |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 537 | switch ((hb_tag_t) script) |
| 538 | { |
Behdad Esfahbod | fa2673c | 2012-03-07 15:52:02 -0500 | [diff] [blame] | 539 | /* Unicode-1.1 additions */ |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 540 | case HB_SCRIPT_ARABIC: |
| 541 | case HB_SCRIPT_HEBREW: |
Behdad Esfahbod | fa2673c | 2012-03-07 15:52:02 -0500 | [diff] [blame] | 542 | |
| 543 | /* Unicode-3.0 additions */ |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 544 | case HB_SCRIPT_SYRIAC: |
| 545 | case HB_SCRIPT_THAANA: |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 546 | |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 547 | /* Unicode-4.0 additions */ |
| 548 | case HB_SCRIPT_CYPRIOT: |
| 549 | |
Behdad Esfahbod | 50e810c | 2012-03-07 12:49:08 -0500 | [diff] [blame] | 550 | /* Unicode-4.1 additions */ |
| 551 | case HB_SCRIPT_KHAROSHTHI: |
| 552 | |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 553 | /* Unicode-5.0 additions */ |
| 554 | case HB_SCRIPT_PHOENICIAN: |
| 555 | case HB_SCRIPT_NKO: |
| 556 | |
Behdad Esfahbod | 50e810c | 2012-03-07 12:49:08 -0500 | [diff] [blame] | 557 | /* Unicode-5.1 additions */ |
| 558 | case HB_SCRIPT_LYDIAN: |
| 559 | |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 560 | /* Unicode-5.2 additions */ |
| 561 | case HB_SCRIPT_AVESTAN: |
| 562 | case HB_SCRIPT_IMPERIAL_ARAMAIC: |
| 563 | case HB_SCRIPT_INSCRIPTIONAL_PAHLAVI: |
| 564 | case HB_SCRIPT_INSCRIPTIONAL_PARTHIAN: |
| 565 | case HB_SCRIPT_OLD_SOUTH_ARABIAN: |
| 566 | case HB_SCRIPT_OLD_TURKIC: |
| 567 | case HB_SCRIPT_SAMARITAN: |
| 568 | |
| 569 | /* Unicode-6.0 additions */ |
| 570 | case HB_SCRIPT_MANDAIC: |
| 571 | |
Behdad Esfahbod | fa2673c | 2012-03-07 15:52:02 -0500 | [diff] [blame] | 572 | /* Unicode-6.1 additions */ |
| 573 | case HB_SCRIPT_MEROITIC_CURSIVE: |
| 574 | case HB_SCRIPT_MEROITIC_HIEROGLYPHS: |
| 575 | |
Behdad Esfahbod | a4a7899 | 2014-04-28 15:06:42 -0700 | [diff] [blame] | 576 | /* Unicode-7.0 additions */ |
| 577 | case HB_SCRIPT_MANICHAEAN: |
| 578 | case HB_SCRIPT_MENDE_KIKAKUI: |
| 579 | case HB_SCRIPT_NABATAEAN: |
| 580 | case HB_SCRIPT_OLD_NORTH_ARABIAN: |
| 581 | case HB_SCRIPT_PALMYRENE: |
| 582 | case HB_SCRIPT_PSALTER_PAHLAVI: |
| 583 | |
Behdad Esfahbod | 64a2726 | 2015-07-15 01:36:39 +0100 | [diff] [blame] | 584 | /* Unicode-8.0 additions */ |
Cosimo Lupo | c8f2a4f | 2018-01-18 22:49:40 +0100 | [diff] [blame] | 585 | case HB_SCRIPT_HATRAN: |
Behdad Esfahbod | 64a2726 | 2015-07-15 01:36:39 +0100 | [diff] [blame] | 586 | |
Behdad Esfahbod | 691086f | 2016-05-06 12:08:18 +0100 | [diff] [blame] | 587 | /* Unicode-9.0 additions */ |
| 588 | case HB_SCRIPT_ADLAM: |
| 589 | |
Behdad Esfahbod | 060e6b4 | 2018-06-05 17:31:46 -0700 | [diff] [blame] | 590 | /* Unicode-11.0 additions */ |
| 591 | case HB_SCRIPT_HANIFI_ROHINGYA: |
| 592 | case HB_SCRIPT_OLD_SOGDIAN: |
| 593 | case HB_SCRIPT_SOGDIAN: |
| 594 | |
David Corbett | 665483c | 2020-04-01 17:28:12 -0400 | [diff] [blame] | 595 | /* Unicode-12.0 additions */ |
| 596 | case HB_SCRIPT_ELYMAIC: |
| 597 | |
David Corbett | fd748fa | 2020-03-15 15:59:31 -0400 | [diff] [blame] | 598 | /* Unicode-13.0 additions */ |
| 599 | case HB_SCRIPT_CHORASMIAN: |
| 600 | case HB_SCRIPT_YEZIDI: |
| 601 | |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 602 | return HB_DIRECTION_RTL; |
Behdad Esfahbod | f673cfb | 2018-05-07 13:58:32 -0700 | [diff] [blame] | 603 | |
| 604 | |
| 605 | /* https://github.com/harfbuzz/harfbuzz/issues/1000 */ |
David Corbett | d8d1e7d | 2018-09-17 11:09:51 -0400 | [diff] [blame] | 606 | case HB_SCRIPT_OLD_HUNGARIAN: |
Behdad Esfahbod | f673cfb | 2018-05-07 13:58:32 -0700 | [diff] [blame] | 607 | case HB_SCRIPT_OLD_ITALIC: |
David Corbett | 46d8f0d | 2018-07-06 15:47:03 -0400 | [diff] [blame] | 608 | case HB_SCRIPT_RUNIC: |
Behdad Esfahbod | f673cfb | 2018-05-07 13:58:32 -0700 | [diff] [blame] | 609 | |
| 610 | return HB_DIRECTION_INVALID; |
Behdad Esfahbod | 62879ee | 2011-04-18 23:40:21 -0400 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | return HB_DIRECTION_LTR; |
Behdad Esfahbod | 00bec2c | 2011-04-15 19:16:54 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | |
Behdad Esfahbod | c78f448 | 2011-05-05 21:31:04 -0400 | [diff] [blame] | 617 | /* hb_version */ |
| 618 | |
Behdad Esfahbod | 00cf4e5 | 2018-10-27 04:07:33 -0700 | [diff] [blame] | 619 | |
| 620 | /** |
| 621 | * SECTION:hb-version |
Behdad Esfahbod | cf5fa57 | 2018-10-27 04:50:38 -0700 | [diff] [blame] | 622 | * @title: hb-version |
Behdad Esfahbod | 00cf4e5 | 2018-10-27 04:07:33 -0700 | [diff] [blame] | 623 | * @short_description: Information about the version of HarfBuzz in use |
| 624 | * @include: hb.h |
| 625 | * |
| 626 | * These functions and macros allow accessing version of the HarfBuzz |
| 627 | * library used at compile- as well as run-time, and to direct code |
| 628 | * conditionally based on those versions, again, at compile- or run-time. |
| 629 | **/ |
| 630 | |
| 631 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 632 | /** |
| 633 | * hb_version: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 634 | * @major: (out): Library major version component |
| 635 | * @minor: (out): Library minor version component |
| 636 | * @micro: (out): Library micro version component |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 637 | * |
| 638 | * Returns library version as three integer components. |
| 639 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 640 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 641 | **/ |
Behdad Esfahbod | c78f448 | 2011-05-05 21:31:04 -0400 | [diff] [blame] | 642 | void |
| 643 | hb_version (unsigned int *major, |
| 644 | unsigned int *minor, |
| 645 | unsigned int *micro) |
| 646 | { |
| 647 | *major = HB_VERSION_MAJOR; |
| 648 | *minor = HB_VERSION_MINOR; |
| 649 | *micro = HB_VERSION_MICRO; |
| 650 | } |
| 651 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 652 | /** |
| 653 | * hb_version_string: |
| 654 | * |
| 655 | * Returns library version as a string with three components. |
| 656 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 657 | * Return value: Library version string |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 658 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 659 | * Since: 0.9.2 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 660 | **/ |
Behdad Esfahbod | c78f448 | 2011-05-05 21:31:04 -0400 | [diff] [blame] | 661 | const char * |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 662 | hb_version_string () |
Behdad Esfahbod | c78f448 | 2011-05-05 21:31:04 -0400 | [diff] [blame] | 663 | { |
| 664 | return HB_VERSION_STRING; |
| 665 | } |
| 666 | |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 667 | /** |
Behdad Esfahbod | 2b051c6 | 2014-06-20 14:09:57 -0400 | [diff] [blame] | 668 | * hb_version_atleast: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 669 | * @major: Library major version component |
| 670 | * @minor: Library minor version component |
| 671 | * @micro: Library micro version component |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 672 | * |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 673 | * Tests the library version against a minimum value, |
| 674 | * as three integer components. |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 675 | * |
Khaled Hosny | a8e72ee | 2020-12-30 23:08:40 +0200 | [diff] [blame] | 676 | * Return value: %true if the library is equal to or greater than |
| 677 | * the test value, %false otherwise |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 678 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 679 | * Since: 0.9.30 |
Behdad Esfahbod | 70303cf | 2013-09-06 17:35:57 -0400 | [diff] [blame] | 680 | **/ |
Behdad Esfahbod | c78f448 | 2011-05-05 21:31:04 -0400 | [diff] [blame] | 681 | hb_bool_t |
Behdad Esfahbod | 2b051c6 | 2014-06-20 14:09:57 -0400 | [diff] [blame] | 682 | hb_version_atleast (unsigned int major, |
| 683 | unsigned int minor, |
| 684 | unsigned int micro) |
Behdad Esfahbod | c78f448 | 2011-05-05 21:31:04 -0400 | [diff] [blame] | 685 | { |
Behdad Esfahbod | 2b051c6 | 2014-06-20 14:09:57 -0400 | [diff] [blame] | 686 | return HB_VERSION_ATLEAST (major, minor, micro); |
Behdad Esfahbod | c78f448 | 2011-05-05 21:31:04 -0400 | [diff] [blame] | 687 | } |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 688 | |
| 689 | |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 690 | |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 691 | /* hb_feature_t and hb_variation_t */ |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 692 | |
| 693 | static bool |
| 694 | parse_space (const char **pp, const char *end) |
| 695 | { |
| 696 | while (*pp < end && ISSPACE (**pp)) |
| 697 | (*pp)++; |
| 698 | return true; |
| 699 | } |
| 700 | |
| 701 | static bool |
| 702 | parse_char (const char **pp, const char *end, char c) |
| 703 | { |
| 704 | parse_space (pp, end); |
| 705 | |
| 706 | if (*pp == end || **pp != c) |
| 707 | return false; |
| 708 | |
| 709 | (*pp)++; |
| 710 | return true; |
| 711 | } |
| 712 | |
| 713 | static bool |
| 714 | parse_uint (const char **pp, const char *end, unsigned int *pv) |
| 715 | { |
Ebrahim Byagowi | b5e6805 | 2019-09-03 15:23:40 +0430 | [diff] [blame] | 716 | /* Intentionally use hb_parse_int inside instead of hb_parse_uint, |
| 717 | * such that -1 turns into "big number"... */ |
Ebrahim Byagowi | 43372fb | 2019-09-03 01:02:40 +0430 | [diff] [blame] | 718 | int v; |
Ebrahim Byagowi | b5e6805 | 2019-09-03 15:23:40 +0430 | [diff] [blame] | 719 | if (unlikely (!hb_parse_int (pp, end, &v))) return false; |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 720 | |
| 721 | *pv = v; |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 722 | return true; |
| 723 | } |
| 724 | |
| 725 | static bool |
Ebrahim Byagowi | 3b0e47c | 2017-06-19 14:47:09 +0430 | [diff] [blame] | 726 | parse_uint32 (const char **pp, const char *end, uint32_t *pv) |
| 727 | { |
Ebrahim Byagowi | b5e6805 | 2019-09-03 15:23:40 +0430 | [diff] [blame] | 728 | /* Intentionally use hb_parse_int inside instead of hb_parse_uint, |
| 729 | * such that -1 turns into "big number"... */ |
Ebrahim Byagowi | 43372fb | 2019-09-03 01:02:40 +0430 | [diff] [blame] | 730 | int v; |
Ebrahim Byagowi | b5e6805 | 2019-09-03 15:23:40 +0430 | [diff] [blame] | 731 | if (unlikely (!hb_parse_int (pp, end, &v))) return false; |
Ebrahim Byagowi | 3b0e47c | 2017-06-19 14:47:09 +0430 | [diff] [blame] | 732 | |
| 733 | *pv = v; |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 734 | return true; |
| 735 | } |
| 736 | |
| 737 | static bool |
Ebrahim Byagowi | 3b0e47c | 2017-06-19 14:47:09 +0430 | [diff] [blame] | 738 | parse_bool (const char **pp, const char *end, uint32_t *pv) |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 739 | { |
| 740 | parse_space (pp, end); |
| 741 | |
| 742 | const char *p = *pp; |
| 743 | while (*pp < end && ISALPHA(**pp)) |
| 744 | (*pp)++; |
| 745 | |
| 746 | /* CSS allows on/off as aliases 1/0. */ |
David Corbett | 45adc18 | 2019-02-18 22:30:40 -0500 | [diff] [blame] | 747 | if (*pp - p == 2 |
| 748 | && TOLOWER (p[0]) == 'o' |
| 749 | && TOLOWER (p[1]) == 'n') |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 750 | *pv = 1; |
David Corbett | 45adc18 | 2019-02-18 22:30:40 -0500 | [diff] [blame] | 751 | else if (*pp - p == 3 |
| 752 | && TOLOWER (p[0]) == 'o' |
| 753 | && TOLOWER (p[1]) == 'f' |
| 754 | && TOLOWER (p[2]) == 'f') |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 755 | *pv = 0; |
| 756 | else |
| 757 | return false; |
| 758 | |
| 759 | return true; |
| 760 | } |
| 761 | |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 762 | /* hb_feature_t */ |
| 763 | |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 764 | static bool |
| 765 | parse_feature_value_prefix (const char **pp, const char *end, hb_feature_t *feature) |
| 766 | { |
| 767 | if (parse_char (pp, end, '-')) |
| 768 | feature->value = 0; |
| 769 | else { |
| 770 | parse_char (pp, end, '+'); |
| 771 | feature->value = 1; |
| 772 | } |
| 773 | |
| 774 | return true; |
| 775 | } |
| 776 | |
| 777 | static bool |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 778 | parse_tag (const char **pp, const char *end, hb_tag_t *tag) |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 779 | { |
| 780 | parse_space (pp, end); |
| 781 | |
| 782 | char quote = 0; |
| 783 | |
| 784 | if (*pp < end && (**pp == '\'' || **pp == '"')) |
| 785 | { |
| 786 | quote = **pp; |
| 787 | (*pp)++; |
| 788 | } |
| 789 | |
| 790 | const char *p = *pp; |
Martin Hosken | 39607dc | 2018-08-09 15:16:32 +0700 | [diff] [blame] | 791 | while (*pp < end && (ISALNUM(**pp) || **pp == '_')) |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 792 | (*pp)++; |
| 793 | |
| 794 | if (p == *pp || *pp - p > 4) |
| 795 | return false; |
| 796 | |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 797 | *tag = hb_tag_from_string (p, *pp - p); |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 798 | |
| 799 | if (quote) |
| 800 | { |
| 801 | /* CSS expects exactly four bytes. And we only allow quotations for |
| 802 | * CSS compatibility. So, enforce the length. */ |
| 803 | if (*pp - p != 4) |
| 804 | return false; |
| 805 | if (*pp == end || **pp != quote) |
| 806 | return false; |
| 807 | (*pp)++; |
| 808 | } |
| 809 | |
| 810 | return true; |
| 811 | } |
| 812 | |
| 813 | static bool |
| 814 | parse_feature_indices (const char **pp, const char *end, hb_feature_t *feature) |
| 815 | { |
| 816 | parse_space (pp, end); |
| 817 | |
| 818 | bool has_start; |
| 819 | |
Behdad Esfahbod | becd84a | 2018-09-11 01:26:18 +0200 | [diff] [blame] | 820 | feature->start = HB_FEATURE_GLOBAL_START; |
| 821 | feature->end = HB_FEATURE_GLOBAL_END; |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 822 | |
| 823 | if (!parse_char (pp, end, '[')) |
| 824 | return true; |
| 825 | |
| 826 | has_start = parse_uint (pp, end, &feature->start); |
| 827 | |
Behdad Esfahbod | 8869436 | 2018-10-23 03:07:48 -0700 | [diff] [blame] | 828 | if (parse_char (pp, end, ':') || parse_char (pp, end, ';')) { |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 829 | parse_uint (pp, end, &feature->end); |
| 830 | } else { |
| 831 | if (has_start) |
| 832 | feature->end = feature->start + 1; |
| 833 | } |
| 834 | |
| 835 | return parse_char (pp, end, ']'); |
| 836 | } |
| 837 | |
| 838 | static bool |
| 839 | parse_feature_value_postfix (const char **pp, const char *end, hb_feature_t *feature) |
| 840 | { |
| 841 | bool had_equal = parse_char (pp, end, '='); |
Ebrahim Byagowi | 3b0e47c | 2017-06-19 14:47:09 +0430 | [diff] [blame] | 842 | bool had_value = parse_uint32 (pp, end, &feature->value) || |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 843 | parse_bool (pp, end, &feature->value); |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 844 | /* CSS doesn't use equal-sign between tag and value. |
| 845 | * If there was an equal-sign, then there *must* be a value. |
Bruce Mitchener | 90218fa | 2018-01-31 20:44:45 +0700 | [diff] [blame] | 846 | * A value without an equal-sign is ok, but not required. */ |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 847 | return !had_equal || had_value; |
| 848 | } |
| 849 | |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 850 | static bool |
| 851 | parse_one_feature (const char **pp, const char *end, hb_feature_t *feature) |
| 852 | { |
| 853 | return parse_feature_value_prefix (pp, end, feature) && |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 854 | parse_tag (pp, end, &feature->tag) && |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 855 | parse_feature_indices (pp, end, feature) && |
| 856 | parse_feature_value_postfix (pp, end, feature) && |
| 857 | parse_space (pp, end) && |
| 858 | *pp == end; |
| 859 | } |
| 860 | |
| 861 | /** |
| 862 | * hb_feature_from_string: |
| 863 | * @str: (array length=len) (element-type uint8_t): a string to parse |
| 864 | * @len: length of @str, or -1 if string is %NULL terminated |
| 865 | * @feature: (out): the #hb_feature_t to initialize with the parsed values |
| 866 | * |
| 867 | * Parses a string into a #hb_feature_t. |
| 868 | * |
Khaled Hosny | 6bd4c08 | 2019-02-19 02:23:58 +0200 | [diff] [blame] | 869 | * The format for specifying feature strings follows. All valid CSS |
David Corbett | 45adc18 | 2019-02-18 22:30:40 -0500 | [diff] [blame] | 870 | * font-feature-settings values other than 'normal' and the global values are |
| 871 | * also accepted, though not documented below. CSS string escapes are not |
| 872 | * supported. |
Khaled Hosny | 6bd4c08 | 2019-02-19 02:23:58 +0200 | [diff] [blame] | 873 | * |
| 874 | * The range indices refer to the positions between Unicode characters. The |
| 875 | * position before the first character is always 0. |
| 876 | * |
| 877 | * The format is Python-esque. Here is how it all works: |
| 878 | * |
| 879 | * <informaltable pgwide='1' align='left' frame='none'> |
| 880 | * <tgroup cols='5'> |
| 881 | * <thead> |
| 882 | * <row><entry>Syntax</entry> <entry>Value</entry> <entry>Start</entry> <entry>End</entry></row> |
| 883 | * </thead> |
| 884 | * <tbody> |
| 885 | * <row><entry>Setting value:</entry></row> |
| 886 | * <row><entry>kern</entry> <entry>1</entry> <entry>0</entry> <entry>∞</entry> <entry>Turn feature on</entry></row> |
| 887 | * <row><entry>+kern</entry> <entry>1</entry> <entry>0</entry> <entry>∞</entry> <entry>Turn feature on</entry></row> |
| 888 | * <row><entry>-kern</entry> <entry>0</entry> <entry>0</entry> <entry>∞</entry> <entry>Turn feature off</entry></row> |
| 889 | * <row><entry>kern=0</entry> <entry>0</entry> <entry>0</entry> <entry>∞</entry> <entry>Turn feature off</entry></row> |
| 890 | * <row><entry>kern=1</entry> <entry>1</entry> <entry>0</entry> <entry>∞</entry> <entry>Turn feature on</entry></row> |
| 891 | * <row><entry>aalt=2</entry> <entry>2</entry> <entry>0</entry> <entry>∞</entry> <entry>Choose 2nd alternate</entry></row> |
| 892 | * <row><entry>Setting index:</entry></row> |
| 893 | * <row><entry>kern[]</entry> <entry>1</entry> <entry>0</entry> <entry>∞</entry> <entry>Turn feature on</entry></row> |
| 894 | * <row><entry>kern[:]</entry> <entry>1</entry> <entry>0</entry> <entry>∞</entry> <entry>Turn feature on</entry></row> |
| 895 | * <row><entry>kern[5:]</entry> <entry>1</entry> <entry>5</entry> <entry>∞</entry> <entry>Turn feature on, partial</entry></row> |
| 896 | * <row><entry>kern[:5]</entry> <entry>1</entry> <entry>0</entry> <entry>5</entry> <entry>Turn feature on, partial</entry></row> |
| 897 | * <row><entry>kern[3:5]</entry> <entry>1</entry> <entry>3</entry> <entry>5</entry> <entry>Turn feature on, range</entry></row> |
| 898 | * <row><entry>kern[3]</entry> <entry>1</entry> <entry>3</entry> <entry>3+1</entry> <entry>Turn feature on, single char</entry></row> |
| 899 | * <row><entry>Mixing it all:</entry></row> |
| 900 | * <row><entry>aalt[3:5]=2</entry> <entry>2</entry> <entry>3</entry> <entry>5</entry> <entry>Turn 2nd alternate on for range</entry></row> |
| 901 | * </tbody> |
| 902 | * </tgroup> |
| 903 | * </informaltable> |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 904 | * |
| 905 | * Return value: |
Nathan Willis | 4cdb12a | 2019-04-21 20:31:09 +0100 | [diff] [blame] | 906 | * %true if @str is successfully parsed, %false otherwise |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 907 | * |
| 908 | * Since: 0.9.5 |
| 909 | **/ |
| 910 | hb_bool_t |
| 911 | hb_feature_from_string (const char *str, int len, |
| 912 | hb_feature_t *feature) |
| 913 | { |
| 914 | hb_feature_t feat; |
| 915 | |
| 916 | if (len < 0) |
| 917 | len = strlen (str); |
| 918 | |
| 919 | if (likely (parse_one_feature (&str, str + len, &feat))) |
| 920 | { |
| 921 | if (feature) |
| 922 | *feature = feat; |
| 923 | return true; |
| 924 | } |
| 925 | |
| 926 | if (feature) |
| 927 | memset (feature, 0, sizeof (*feature)); |
| 928 | return false; |
| 929 | } |
| 930 | |
| 931 | /** |
| 932 | * hb_feature_to_string: |
| 933 | * @feature: an #hb_feature_t to convert |
| 934 | * @buf: (array length=size) (out): output string |
| 935 | * @size: the allocated size of @buf |
| 936 | * |
| 937 | * Converts a #hb_feature_t into a %NULL-terminated string in the format |
| 938 | * understood by hb_feature_from_string(). The client in responsible for |
| 939 | * allocating big enough size for @buf, 128 bytes is more than enough. |
| 940 | * |
| 941 | * Since: 0.9.5 |
| 942 | **/ |
| 943 | void |
| 944 | hb_feature_to_string (hb_feature_t *feature, |
| 945 | char *buf, unsigned int size) |
| 946 | { |
| 947 | if (unlikely (!size)) return; |
| 948 | |
| 949 | char s[128]; |
| 950 | unsigned int len = 0; |
| 951 | if (feature->value == 0) |
| 952 | s[len++] = '-'; |
| 953 | hb_tag_to_string (feature->tag, s + len); |
| 954 | len += 4; |
| 955 | while (len && s[len - 1] == ' ') |
| 956 | len--; |
Evgeniy Reizner | b79ceac | 2019-12-15 16:50:01 +0200 | [diff] [blame] | 957 | if (feature->start != HB_FEATURE_GLOBAL_START || feature->end != HB_FEATURE_GLOBAL_END) |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 958 | { |
| 959 | s[len++] = '['; |
| 960 | if (feature->start) |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 961 | len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->start)); |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 962 | if (feature->end != feature->start + 1) { |
| 963 | s[len++] = ':'; |
Evgeniy Reizner | b79ceac | 2019-12-15 16:50:01 +0200 | [diff] [blame] | 964 | if (feature->end != HB_FEATURE_GLOBAL_END) |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 965 | len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->end)); |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 966 | } |
| 967 | s[len++] = ']'; |
| 968 | } |
| 969 | if (feature->value > 1) |
| 970 | { |
| 971 | s[len++] = '='; |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 972 | len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->value)); |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 973 | } |
| 974 | assert (len < ARRAY_LENGTH (s)); |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 975 | len = hb_min (len, size - 1); |
Behdad Esfahbod | 7236410 | 2017-01-20 20:16:53 -0800 | [diff] [blame] | 976 | memcpy (buf, s, len); |
| 977 | buf[len] = '\0'; |
| 978 | } |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 979 | |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 980 | /* hb_variation_t */ |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 981 | |
| 982 | static bool |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 983 | parse_variation_value (const char **pp, const char *end, hb_variation_t *variation) |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 984 | { |
| 985 | parse_char (pp, end, '='); /* Optional. */ |
Ebrahim Byagowi | 57f88e1 | 2019-09-04 01:20:50 +0430 | [diff] [blame] | 986 | double v; |
| 987 | if (unlikely (!hb_parse_double (pp, end, &v))) return false; |
| 988 | |
| 989 | variation->value = v; |
| 990 | return true; |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | static bool |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 994 | parse_one_variation (const char **pp, const char *end, hb_variation_t *variation) |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 995 | { |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 996 | return parse_tag (pp, end, &variation->tag) && |
| 997 | parse_variation_value (pp, end, variation) && |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 998 | parse_space (pp, end) && |
| 999 | *pp == end; |
| 1000 | } |
| 1001 | |
Behdad Esfahbod | d2f249e | 2017-01-22 17:42:33 -0800 | [diff] [blame] | 1002 | /** |
| 1003 | * hb_variation_from_string: |
Khaled Hosny | 9b602e8 | 2020-12-30 23:28:54 +0200 | [diff] [blame] | 1004 | * @str: (array length=len) (element-type uint8_t): a string to parse |
| 1005 | * @len: length of @str, or -1 if string is %NULL terminated |
| 1006 | * @variation: (out): the #hb_variation_t to initialize with the parsed values |
| 1007 | * |
| 1008 | * Parses a string into a #hb_variation_t. |
| 1009 | * |
| 1010 | * The format for specifying variation settings follows. All valid CSS |
| 1011 | * font-variation-settings values other than 'normal' and 'inherited' are also |
| 1012 | * accepted, though, not documented below. |
| 1013 | * |
| 1014 | * The format is a tag, optionally followed by an equals sign, followed by a |
| 1015 | * number. For example `wght=500`, or `slnt=-7.5`. |
| 1016 | * |
| 1017 | * Return value: |
| 1018 | * %true if @str is successfully parsed, %false otherwise |
Behdad Esfahbod | d2f249e | 2017-01-22 17:42:33 -0800 | [diff] [blame] | 1019 | * |
| 1020 | * Since: 1.4.2 |
| 1021 | */ |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1022 | hb_bool_t |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 1023 | hb_variation_from_string (const char *str, int len, |
| 1024 | hb_variation_t *variation) |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1025 | { |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 1026 | hb_variation_t var; |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1027 | |
| 1028 | if (len < 0) |
| 1029 | len = strlen (str); |
| 1030 | |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 1031 | if (likely (parse_one_variation (&str, str + len, &var))) |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1032 | { |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 1033 | if (variation) |
| 1034 | *variation = var; |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1035 | return true; |
| 1036 | } |
| 1037 | |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 1038 | if (variation) |
| 1039 | memset (variation, 0, sizeof (*variation)); |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1040 | return false; |
| 1041 | } |
| 1042 | |
Behdad Esfahbod | d2f249e | 2017-01-22 17:42:33 -0800 | [diff] [blame] | 1043 | /** |
| 1044 | * hb_variation_to_string: |
Khaled Hosny | 9b602e8 | 2020-12-30 23:28:54 +0200 | [diff] [blame] | 1045 | * @variation: an #hb_variation_t to convert |
| 1046 | * @buf: (array length=size) (out): output string |
| 1047 | * @size: the allocated size of @buf |
| 1048 | * |
| 1049 | * Converts an #hb_variation_t into a %NULL-terminated string in the format |
| 1050 | * understood by hb_variation_from_string(). The client in responsible for |
| 1051 | * allocating big enough size for @buf, 128 bytes is more than enough. |
Behdad Esfahbod | d2f249e | 2017-01-22 17:42:33 -0800 | [diff] [blame] | 1052 | * |
| 1053 | * Since: 1.4.2 |
| 1054 | */ |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1055 | void |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 1056 | hb_variation_to_string (hb_variation_t *variation, |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1057 | char *buf, unsigned int size) |
| 1058 | { |
| 1059 | if (unlikely (!size)) return; |
| 1060 | |
| 1061 | char s[128]; |
| 1062 | unsigned int len = 0; |
Behdad Esfahbod | bb1e192 | 2017-01-21 17:41:37 -0800 | [diff] [blame] | 1063 | hb_tag_to_string (variation->tag, s + len); |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1064 | len += 4; |
| 1065 | while (len && s[len - 1] == ' ') |
| 1066 | len--; |
| 1067 | s[len++] = '='; |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 1068 | len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%g", (double) variation->value)); |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1069 | |
| 1070 | assert (len < ARRAY_LENGTH (s)); |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 1071 | len = hb_min (len, size - 1); |
Behdad Esfahbod | b3c0714 | 2017-01-20 20:30:03 -0800 | [diff] [blame] | 1072 | memcpy (buf, s, len); |
| 1073 | buf[len] = '\0'; |
| 1074 | } |
Behdad Esfahbod | e22a48a | 2018-07-23 13:24:26 -0700 | [diff] [blame] | 1075 | |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1076 | /** |
| 1077 | * hb_color_get_alpha: |
Khaled Hosny | 9b602e8 | 2020-12-30 23:28:54 +0200 | [diff] [blame] | 1078 | * @color: an #hb_color_t we are interested in its channels. |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1079 | * |
Khaled Hosny | 4bfa0b3 | 2020-12-31 16:30:05 +0200 | [diff] [blame] | 1080 | * Fetches the alpha channel of the given @color. |
| 1081 | * |
| 1082 | * Return value: Alpha channel value |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1083 | * |
Behdad Esfahbod | 1da0891 | 2019-05-24 15:41:34 -0400 | [diff] [blame] | 1084 | * Since: 2.1.0 |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1085 | */ |
| 1086 | uint8_t |
| 1087 | (hb_color_get_alpha) (hb_color_t color) |
| 1088 | { |
| 1089 | return hb_color_get_alpha (color); |
| 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * hb_color_get_red: |
Khaled Hosny | 9b602e8 | 2020-12-30 23:28:54 +0200 | [diff] [blame] | 1094 | * @color: an #hb_color_t we are interested in its channels. |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1095 | * |
Khaled Hosny | 4bfa0b3 | 2020-12-31 16:30:05 +0200 | [diff] [blame] | 1096 | * Fetches the red channel of the given @color. |
| 1097 | * |
| 1098 | * Return value: Red channel value |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1099 | * |
Behdad Esfahbod | 1da0891 | 2019-05-24 15:41:34 -0400 | [diff] [blame] | 1100 | * Since: 2.1.0 |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1101 | */ |
| 1102 | uint8_t |
| 1103 | (hb_color_get_red) (hb_color_t color) |
| 1104 | { |
| 1105 | return hb_color_get_red (color); |
| 1106 | } |
| 1107 | |
| 1108 | /** |
| 1109 | * hb_color_get_green: |
Khaled Hosny | 9b602e8 | 2020-12-30 23:28:54 +0200 | [diff] [blame] | 1110 | * @color: an #hb_color_t we are interested in its channels. |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1111 | * |
Khaled Hosny | 4bfa0b3 | 2020-12-31 16:30:05 +0200 | [diff] [blame] | 1112 | * Fetches the green channel of the given @color. |
| 1113 | * |
| 1114 | * Return value: Green channel value |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1115 | * |
Behdad Esfahbod | 1da0891 | 2019-05-24 15:41:34 -0400 | [diff] [blame] | 1116 | * Since: 2.1.0 |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1117 | */ |
| 1118 | uint8_t |
| 1119 | (hb_color_get_green) (hb_color_t color) |
| 1120 | { |
| 1121 | return hb_color_get_green (color); |
| 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * hb_color_get_blue: |
Khaled Hosny | 9b602e8 | 2020-12-30 23:28:54 +0200 | [diff] [blame] | 1126 | * @color: an #hb_color_t we are interested in its channels. |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1127 | * |
Khaled Hosny | 4bfa0b3 | 2020-12-31 16:30:05 +0200 | [diff] [blame] | 1128 | * Fetches the blue channel of the given @color. |
| 1129 | * |
| 1130 | * Return value: Blue channel value |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1131 | * |
Behdad Esfahbod | 1da0891 | 2019-05-24 15:41:34 -0400 | [diff] [blame] | 1132 | * Since: 2.1.0 |
Ebrahim Byagowi | 9542bdd | 2019-04-29 14:52:28 -0700 | [diff] [blame] | 1133 | */ |
| 1134 | uint8_t |
| 1135 | (hb_color_get_blue) (hb_color_t color) |
| 1136 | { |
| 1137 | return hb_color_get_blue (color); |
| 1138 | } |
| 1139 | |
| 1140 | |
Behdad Esfahbod | e22a48a | 2018-07-23 13:24:26 -0700 | [diff] [blame] | 1141 | /* If there is no visibility control, then hb-static.cc will NOT |
| 1142 | * define anything. Instead, we get it to define one set in here |
| 1143 | * only, so only libharfbuzz.so defines them, not other libs. */ |
| 1144 | #ifdef HB_NO_VISIBILITY |
| 1145 | #undef HB_NO_VISIBILITY |
| 1146 | #include "hb-static.cc" |
| 1147 | #define HB_NO_VISIBILITY 1 |
| 1148 | #endif |