1 /* 2 * Copyright (C) 2012 Grigori Goronzy <greg (at) kinoho.net> 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef UCDN_H 18 #define UCDN_H 19 20 #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__) 21 # define HB_BEGIN_VISIBILITY _Pragma ("GCC visibility push(hidden)") 22 # define HB_END_VISIBILITY _Pragma ("GCC visibility pop") 23 #else 24 # define HB_BEGIN_VISIBILITY 25 # define HB_END_VISIBILITY 26 #endif 27 #ifdef __cplusplus 28 # define HB_BEGIN_HEADER extern "C" { HB_BEGIN_VISIBILITY 29 # define HB_END_HEADER HB_END_VISIBILITY } 30 #else 31 # define HB_BEGIN_HEADER HB_BEGIN_VISIBILITY 32 # define HB_END_HEADER HB_END_VISIBILITY 33 #endif 34 35 HB_BEGIN_HEADER 36 37 #include <stdint.h> 38 39 #define UCDN_EAST_ASIAN_F 0 40 #define UCDN_EAST_ASIAN_H 1 41 #define UCDN_EAST_ASIAN_W 2 42 #define UCDN_EAST_ASIAN_NA 3 43 #define UCDN_EAST_ASIAN_A 4 44 #define UCDN_EAST_ASIAN_N 5 45 46 #define UCDN_SCRIPT_COMMON 0 47 #define UCDN_SCRIPT_LATIN 1 48 #define UCDN_SCRIPT_GREEK 2 49 #define UCDN_SCRIPT_CYRILLIC 3 50 #define UCDN_SCRIPT_ARMENIAN 4 51 #define UCDN_SCRIPT_HEBREW 5 52 #define UCDN_SCRIPT_ARABIC 6 53 #define UCDN_SCRIPT_SYRIAC 7 54 #define UCDN_SCRIPT_THAANA 8 55 #define UCDN_SCRIPT_DEVANAGARI 9 56 #define UCDN_SCRIPT_BENGALI 10 57 #define UCDN_SCRIPT_GURMUKHI 11 58 #define UCDN_SCRIPT_GUJARATI 12 59 #define UCDN_SCRIPT_ORIYA 13 60 #define UCDN_SCRIPT_TAMIL 14 61 #define UCDN_SCRIPT_TELUGU 15 62 #define UCDN_SCRIPT_KANNADA 16 63 #define UCDN_SCRIPT_MALAYALAM 17 64 #define UCDN_SCRIPT_SINHALA 18 65 #define UCDN_SCRIPT_THAI 19 66 #define UCDN_SCRIPT_LAO 20 67 #define UCDN_SCRIPT_TIBETAN 21 68 #define UCDN_SCRIPT_MYANMAR 22 69 #define UCDN_SCRIPT_GEORGIAN 23 70 #define UCDN_SCRIPT_HANGUL 24 71 #define UCDN_SCRIPT_ETHIOPIC 25 72 #define UCDN_SCRIPT_CHEROKEE 26 73 #define UCDN_SCRIPT_CANADIAN_ABORIGINAL 27 74 #define UCDN_SCRIPT_OGHAM 28 75 #define UCDN_SCRIPT_RUNIC 29 76 #define UCDN_SCRIPT_KHMER 30 77 #define UCDN_SCRIPT_MONGOLIAN 31 78 #define UCDN_SCRIPT_HIRAGANA 32 79 #define UCDN_SCRIPT_KATAKANA 33 80 #define UCDN_SCRIPT_BOPOMOFO 34 81 #define UCDN_SCRIPT_HAN 35 82 #define UCDN_SCRIPT_YI 36 83 #define UCDN_SCRIPT_OLD_ITALIC 37 84 #define UCDN_SCRIPT_GOTHIC 38 85 #define UCDN_SCRIPT_DESERET 39 86 #define UCDN_SCRIPT_INHERITED 40 87 #define UCDN_SCRIPT_TAGALOG 41 88 #define UCDN_SCRIPT_HANUNOO 42 89 #define UCDN_SCRIPT_BUHID 43 90 #define UCDN_SCRIPT_TAGBANWA 44 91 #define UCDN_SCRIPT_LIMBU 45 92 #define UCDN_SCRIPT_TAI_LE 46 93 #define UCDN_SCRIPT_LINEAR_B 47 94 #define UCDN_SCRIPT_UGARITIC 48 95 #define UCDN_SCRIPT_SHAVIAN 49 96 #define UCDN_SCRIPT_OSMANYA 50 97 #define UCDN_SCRIPT_CYPRIOT 51 98 #define UCDN_SCRIPT_BRAILLE 52 99 #define UCDN_SCRIPT_BUGINESE 53 100 #define UCDN_SCRIPT_COPTIC 54 101 #define UCDN_SCRIPT_NEW_TAI_LUE 55 102 #define UCDN_SCRIPT_GLAGOLITIC 56 103 #define UCDN_SCRIPT_TIFINAGH 57 104 #define UCDN_SCRIPT_SYLOTI_NAGRI 58 105 #define UCDN_SCRIPT_OLD_PERSIAN 59 106 #define UCDN_SCRIPT_KHAROSHTHI 60 107 #define UCDN_SCRIPT_BALINESE 61 108 #define UCDN_SCRIPT_CUNEIFORM 62 109 #define UCDN_SCRIPT_PHOENICIAN 63 110 #define UCDN_SCRIPT_PHAGS_PA 64 111 #define UCDN_SCRIPT_NKO 65 112 #define UCDN_SCRIPT_SUNDANESE 66 113 #define UCDN_SCRIPT_LEPCHA 67 114 #define UCDN_SCRIPT_OL_CHIKI 68 115 #define UCDN_SCRIPT_VAI 69 116 #define UCDN_SCRIPT_SAURASHTRA 70 117 #define UCDN_SCRIPT_KAYAH_LI 71 118 #define UCDN_SCRIPT_REJANG 72 119 #define UCDN_SCRIPT_LYCIAN 73 120 #define UCDN_SCRIPT_CARIAN 74 121 #define UCDN_SCRIPT_LYDIAN 75 122 #define UCDN_SCRIPT_CHAM 76 123 #define UCDN_SCRIPT_TAI_THAM 77 124 #define UCDN_SCRIPT_TAI_VIET 78 125 #define UCDN_SCRIPT_AVESTAN 79 126 #define UCDN_SCRIPT_EGYPTIAN_HIEROGLYPHS 80 127 #define UCDN_SCRIPT_SAMARITAN 81 128 #define UCDN_SCRIPT_LISU 82 129 #define UCDN_SCRIPT_BAMUM 83 130 #define UCDN_SCRIPT_JAVANESE 84 131 #define UCDN_SCRIPT_MEETEI_MAYEK 85 132 #define UCDN_SCRIPT_IMPERIAL_ARAMAIC 86 133 #define UCDN_SCRIPT_OLD_SOUTH_ARABIAN 87 134 #define UCDN_SCRIPT_INSCRIPTIONAL_PARTHIAN 88 135 #define UCDN_SCRIPT_INSCRIPTIONAL_PAHLAVI 89 136 #define UCDN_SCRIPT_OLD_TURKIC 90 137 #define UCDN_SCRIPT_KAITHI 91 138 #define UCDN_SCRIPT_BATAK 92 139 #define UCDN_SCRIPT_BRAHMI 93 140 #define UCDN_SCRIPT_MANDAIC 94 141 #define UCDN_SCRIPT_CHAKMA 95 142 #define UCDN_SCRIPT_MEROITIC_CURSIVE 96 143 #define UCDN_SCRIPT_MEROITIC_HIEROGLYPHS 97 144 #define UCDN_SCRIPT_MIAO 98 145 #define UCDN_SCRIPT_SHARADA 99 146 #define UCDN_SCRIPT_SORA_SOMPENG 100 147 #define UCDN_SCRIPT_TAKRI 101 148 #define UCDN_SCRIPT_UNKNOWN 102 149 150 #define UCDN_GENERAL_CATEGORY_CC 0 151 #define UCDN_GENERAL_CATEGORY_CF 1 152 #define UCDN_GENERAL_CATEGORY_CN 2 153 #define UCDN_GENERAL_CATEGORY_CO 3 154 #define UCDN_GENERAL_CATEGORY_CS 4 155 #define UCDN_GENERAL_CATEGORY_LL 5 156 #define UCDN_GENERAL_CATEGORY_LM 6 157 #define UCDN_GENERAL_CATEGORY_LO 7 158 #define UCDN_GENERAL_CATEGORY_LT 8 159 #define UCDN_GENERAL_CATEGORY_LU 9 160 #define UCDN_GENERAL_CATEGORY_MC 10 161 #define UCDN_GENERAL_CATEGORY_ME 11 162 #define UCDN_GENERAL_CATEGORY_MN 12 163 #define UCDN_GENERAL_CATEGORY_ND 13 164 #define UCDN_GENERAL_CATEGORY_NL 14 165 #define UCDN_GENERAL_CATEGORY_NO 15 166 #define UCDN_GENERAL_CATEGORY_PC 16 167 #define UCDN_GENERAL_CATEGORY_PD 17 168 #define UCDN_GENERAL_CATEGORY_PE 18 169 #define UCDN_GENERAL_CATEGORY_PF 19 170 #define UCDN_GENERAL_CATEGORY_PI 20 171 #define UCDN_GENERAL_CATEGORY_PO 21 172 #define UCDN_GENERAL_CATEGORY_PS 22 173 #define UCDN_GENERAL_CATEGORY_SC 23 174 #define UCDN_GENERAL_CATEGORY_SK 24 175 #define UCDN_GENERAL_CATEGORY_SM 25 176 #define UCDN_GENERAL_CATEGORY_SO 26 177 #define UCDN_GENERAL_CATEGORY_ZL 27 178 #define UCDN_GENERAL_CATEGORY_ZP 28 179 #define UCDN_GENERAL_CATEGORY_ZS 29 180 181 #define UCDN_BIDI_CLASS_L 0 182 #define UCDN_BIDI_CLASS_LRE 1 183 #define UCDN_BIDI_CLASS_LRO 2 184 #define UCDN_BIDI_CLASS_R 3 185 #define UCDN_BIDI_CLASS_AL 4 186 #define UCDN_BIDI_CLASS_RLE 5 187 #define UCDN_BIDI_CLASS_RLO 6 188 #define UCDN_BIDI_CLASS_PDF 7 189 #define UCDN_BIDI_CLASS_EN 8 190 #define UCDN_BIDI_CLASS_ES 9 191 #define UCDN_BIDI_CLASS_ET 10 192 #define UCDN_BIDI_CLASS_AN 11 193 #define UCDN_BIDI_CLASS_CS 12 194 #define UCDN_BIDI_CLASS_NSM 13 195 #define UCDN_BIDI_CLASS_BN 14 196 #define UCDN_BIDI_CLASS_B 15 197 #define UCDN_BIDI_CLASS_S 16 198 #define UCDN_BIDI_CLASS_WS 17 199 #define UCDN_BIDI_CLASS_ON 18 200 201 /** 202 * Return version of the Unicode database. 203 * 204 * @return Unicode database version 205 */ 206 const char *ucdn_get_unicode_version(void); 207 208 /** 209 * Get combining class of a codepoint. 210 * 211 * @param code Unicode codepoint 212 * @return combining class value, as defined in UAX#44 213 */ 214 int ucdn_get_combining_class(uint32_t code); 215 216 /** 217 * Get east-asian width of a codepoint. 218 * 219 * @param code Unicode codepoint 220 * @return value according to UCDN_EAST_ASIAN_* and as defined in UAX#11. 221 */ 222 int ucdn_get_east_asian_width(uint32_t code); 223 224 /** 225 * Get general category of a codepoint. 226 * 227 * @param code Unicode codepoint 228 * @return value according to UCDN_GENERAL_CATEGORY_* and as defined in 229 * UAX#44. 230 */ 231 int ucdn_get_general_category(uint32_t code); 232 233 /** 234 * Get bidirectional class of a codepoint. 235 * 236 * @param code Unicode codepoint 237 * @return value according to UCDN_BIDI_CLASS_* and as defined in UAX#44. 238 */ 239 int ucdn_get_bidi_class(uint32_t code); 240 241 /** 242 * Get script of a codepoint. 243 * 244 * @param code Unicode codepoint 245 * @return value according to UCDN_SCRIPT_* and as defined in UAX#24. 246 */ 247 int ucdn_get_script(uint32_t code); 248 249 /** 250 * Check if codepoint can be mirrored. 251 * 252 * @param code Unicode codepoint 253 * @return 1 if mirrored character exists, otherwise 0 254 */ 255 int ucdn_get_mirrored(uint32_t code); 256 257 /** 258 * Mirror a codepoint. 259 * 260 * @param code Unicode codepoint 261 * @return mirrored codepoint or the original codepoint if no 262 * mirrored character exists 263 */ 264 uint32_t ucdn_mirror(uint32_t code); 265 266 /** 267 * Pairwise canonical decomposition of a codepoint. This includes 268 * Hangul Jamo decomposition (see chapter 3.12 of the Unicode core 269 * specification). 270 * 271 * Hangul is decomposed into L and V jamos for LV forms, and an 272 * LV precomposed syllable and a T jamo for LVT forms. 273 * 274 * @param code Unicode codepoint 275 * @param a filled with first codepoint of decomposition 276 * @param b filled with second codepoint of decomposition, or 0 277 * @return success 278 */ 279 int ucdn_decompose(uint32_t code, uint32_t *a, uint32_t *b); 280 281 /** 282 * Compatibility decomposition of a codepoint. 283 * 284 * @param code Unicode codepoint 285 * @param decomposed filled with decomposition, must be able to hold 18 286 * characters 287 * @return length of decomposition or 0 in case none exists 288 */ 289 int ucdn_compat_decompose(uint32_t code, uint32_t *decomposed); 290 291 /** 292 * Pairwise canonical composition of two codepoints. This includes 293 * Hangul Jamo composition (see chapter 3.12 of the Unicode core 294 * specification). 295 * 296 * Hangul composition expects either L and V jamos, or an LV 297 * precomposed syllable and a T jamo. This is exactly the inverse 298 * of pairwise Hangul decomposition. 299 * 300 * @param code filled with composition 301 * @param a first codepoint 302 * @param b second codepoint 303 * @return success 304 */ 305 int ucdn_compose(uint32_t *code, uint32_t a, uint32_t b); 306 307 HB_END_HEADER 308 309 #endif 310