Home | History | Annotate | Download | only in hb-ucdn
      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 
     21 
     22 #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
     23 # define HB_BEGIN_VISIBILITY _Pragma ("GCC visibility push(hidden)")
     24 # define HB_END_VISIBILITY _Pragma ("GCC visibility pop")
     25 #else
     26 # define HB_BEGIN_VISIBILITY
     27 # define HB_END_VISIBILITY
     28 #endif
     29 #ifdef __cplusplus
     30 # define HB_BEGIN_HEADER  extern "C" { HB_BEGIN_VISIBILITY
     31 # define HB_END_HEADER  HB_END_VISIBILITY }
     32 #else
     33 # define HB_BEGIN_HEADER  HB_BEGIN_VISIBILITY
     34 # define HB_END_HEADER  HB_END_VISIBILITY
     35 #endif
     36 
     37 HB_BEGIN_HEADER
     38 
     39 #if !defined (HB_DONT_DEFINE_STDINT)
     40 
     41 #if defined (_SVR4) || defined (SVR4) || defined (__OpenBSD__) || \
     42     defined (_sgi) || defined (__sun) || defined (sun) || \
     43     defined (__digital__) || defined (__HP_cc)
     44 #  include <inttypes.h>
     45 #elif defined (_AIX)
     46 #  include <sys/inttypes.h>
     47 /* VS 2010 (_MSC_VER 1600) has stdint.h */
     48 #elif defined (_MSC_VER) && _MSC_VER < 1600
     49 typedef __int8 int8_t;
     50 typedef unsigned __int8 uint8_t;
     51 typedef __int16 int16_t;
     52 typedef unsigned __int16 uint16_t;
     53 typedef __int32 int32_t;
     54 typedef unsigned __int32 uint32_t;
     55 typedef __int64 int64_t;
     56 typedef unsigned __int64 uint64_t;
     57 #else
     58 #  include <stdint.h>
     59 #endif
     60 
     61 #endif
     62 
     63 
     64 #define UCDN_EAST_ASIAN_F 0
     65 #define UCDN_EAST_ASIAN_H 1
     66 #define UCDN_EAST_ASIAN_W 2
     67 #define UCDN_EAST_ASIAN_NA 3
     68 #define UCDN_EAST_ASIAN_A 4
     69 #define UCDN_EAST_ASIAN_N 5
     70 
     71 #define UCDN_SCRIPT_COMMON 0
     72 #define UCDN_SCRIPT_LATIN 1
     73 #define UCDN_SCRIPT_GREEK 2
     74 #define UCDN_SCRIPT_CYRILLIC 3
     75 #define UCDN_SCRIPT_ARMENIAN 4
     76 #define UCDN_SCRIPT_HEBREW 5
     77 #define UCDN_SCRIPT_ARABIC 6
     78 #define UCDN_SCRIPT_SYRIAC 7
     79 #define UCDN_SCRIPT_THAANA 8
     80 #define UCDN_SCRIPT_DEVANAGARI 9
     81 #define UCDN_SCRIPT_BENGALI 10
     82 #define UCDN_SCRIPT_GURMUKHI 11
     83 #define UCDN_SCRIPT_GUJARATI 12
     84 #define UCDN_SCRIPT_ORIYA 13
     85 #define UCDN_SCRIPT_TAMIL 14
     86 #define UCDN_SCRIPT_TELUGU 15
     87 #define UCDN_SCRIPT_KANNADA 16
     88 #define UCDN_SCRIPT_MALAYALAM 17
     89 #define UCDN_SCRIPT_SINHALA 18
     90 #define UCDN_SCRIPT_THAI 19
     91 #define UCDN_SCRIPT_LAO 20
     92 #define UCDN_SCRIPT_TIBETAN 21
     93 #define UCDN_SCRIPT_MYANMAR 22
     94 #define UCDN_SCRIPT_GEORGIAN 23
     95 #define UCDN_SCRIPT_HANGUL 24
     96 #define UCDN_SCRIPT_ETHIOPIC 25
     97 #define UCDN_SCRIPT_CHEROKEE 26
     98 #define UCDN_SCRIPT_CANADIAN_ABORIGINAL 27
     99 #define UCDN_SCRIPT_OGHAM 28
    100 #define UCDN_SCRIPT_RUNIC 29
    101 #define UCDN_SCRIPT_KHMER 30
    102 #define UCDN_SCRIPT_MONGOLIAN 31
    103 #define UCDN_SCRIPT_HIRAGANA 32
    104 #define UCDN_SCRIPT_KATAKANA 33
    105 #define UCDN_SCRIPT_BOPOMOFO 34
    106 #define UCDN_SCRIPT_HAN 35
    107 #define UCDN_SCRIPT_YI 36
    108 #define UCDN_SCRIPT_OLD_ITALIC 37
    109 #define UCDN_SCRIPT_GOTHIC 38
    110 #define UCDN_SCRIPT_DESERET 39
    111 #define UCDN_SCRIPT_INHERITED 40
    112 #define UCDN_SCRIPT_TAGALOG 41
    113 #define UCDN_SCRIPT_HANUNOO 42
    114 #define UCDN_SCRIPT_BUHID 43
    115 #define UCDN_SCRIPT_TAGBANWA 44
    116 #define UCDN_SCRIPT_LIMBU 45
    117 #define UCDN_SCRIPT_TAI_LE 46
    118 #define UCDN_SCRIPT_LINEAR_B 47
    119 #define UCDN_SCRIPT_UGARITIC 48
    120 #define UCDN_SCRIPT_SHAVIAN 49
    121 #define UCDN_SCRIPT_OSMANYA 50
    122 #define UCDN_SCRIPT_CYPRIOT 51
    123 #define UCDN_SCRIPT_BRAILLE 52
    124 #define UCDN_SCRIPT_BUGINESE 53
    125 #define UCDN_SCRIPT_COPTIC 54
    126 #define UCDN_SCRIPT_NEW_TAI_LUE 55
    127 #define UCDN_SCRIPT_GLAGOLITIC 56
    128 #define UCDN_SCRIPT_TIFINAGH 57
    129 #define UCDN_SCRIPT_SYLOTI_NAGRI 58
    130 #define UCDN_SCRIPT_OLD_PERSIAN 59
    131 #define UCDN_SCRIPT_KHAROSHTHI 60
    132 #define UCDN_SCRIPT_BALINESE 61
    133 #define UCDN_SCRIPT_CUNEIFORM 62
    134 #define UCDN_SCRIPT_PHOENICIAN 63
    135 #define UCDN_SCRIPT_PHAGS_PA 64
    136 #define UCDN_SCRIPT_NKO 65
    137 #define UCDN_SCRIPT_SUNDANESE 66
    138 #define UCDN_SCRIPT_LEPCHA 67
    139 #define UCDN_SCRIPT_OL_CHIKI 68
    140 #define UCDN_SCRIPT_VAI 69
    141 #define UCDN_SCRIPT_SAURASHTRA 70
    142 #define UCDN_SCRIPT_KAYAH_LI 71
    143 #define UCDN_SCRIPT_REJANG 72
    144 #define UCDN_SCRIPT_LYCIAN 73
    145 #define UCDN_SCRIPT_CARIAN 74
    146 #define UCDN_SCRIPT_LYDIAN 75
    147 #define UCDN_SCRIPT_CHAM 76
    148 #define UCDN_SCRIPT_TAI_THAM 77
    149 #define UCDN_SCRIPT_TAI_VIET 78
    150 #define UCDN_SCRIPT_AVESTAN 79
    151 #define UCDN_SCRIPT_EGYPTIAN_HIEROGLYPHS 80
    152 #define UCDN_SCRIPT_SAMARITAN 81
    153 #define UCDN_SCRIPT_LISU 82
    154 #define UCDN_SCRIPT_BAMUM 83
    155 #define UCDN_SCRIPT_JAVANESE 84
    156 #define UCDN_SCRIPT_MEETEI_MAYEK 85
    157 #define UCDN_SCRIPT_IMPERIAL_ARAMAIC 86
    158 #define UCDN_SCRIPT_OLD_SOUTH_ARABIAN 87
    159 #define UCDN_SCRIPT_INSCRIPTIONAL_PARTHIAN 88
    160 #define UCDN_SCRIPT_INSCRIPTIONAL_PAHLAVI 89
    161 #define UCDN_SCRIPT_OLD_TURKIC 90
    162 #define UCDN_SCRIPT_KAITHI 91
    163 #define UCDN_SCRIPT_BATAK 92
    164 #define UCDN_SCRIPT_BRAHMI 93
    165 #define UCDN_SCRIPT_MANDAIC 94
    166 #define UCDN_SCRIPT_CHAKMA 95
    167 #define UCDN_SCRIPT_MEROITIC_CURSIVE 96
    168 #define UCDN_SCRIPT_MEROITIC_HIEROGLYPHS 97
    169 #define UCDN_SCRIPT_MIAO 98
    170 #define UCDN_SCRIPT_SHARADA 99
    171 #define UCDN_SCRIPT_SORA_SOMPENG 100
    172 #define UCDN_SCRIPT_TAKRI 101
    173 #define UCDN_SCRIPT_UNKNOWN 102
    174 #define UCDN_SCRIPT_BASSA_VAH 103
    175 #define UCDN_SCRIPT_CAUCASIAN_ALBANIAN 104
    176 #define UCDN_SCRIPT_DUPLOYAN 105
    177 #define UCDN_SCRIPT_ELBASAN 106
    178 #define UCDN_SCRIPT_GRANTHA 107
    179 #define UCDN_SCRIPT_KHOJKI 108
    180 #define UCDN_SCRIPT_KHUDAWADI 109
    181 #define UCDN_SCRIPT_LINEAR_A 110
    182 #define UCDN_SCRIPT_MAHAJANI 111
    183 #define UCDN_SCRIPT_MANICHAEAN 112
    184 #define UCDN_SCRIPT_MENDE_KIKAKUI 113
    185 #define UCDN_SCRIPT_MODI 114
    186 #define UCDN_SCRIPT_MRO 115
    187 #define UCDN_SCRIPT_NABATAEAN 116
    188 #define UCDN_SCRIPT_OLD_NORTH_ARABIAN 117
    189 #define UCDN_SCRIPT_OLD_PERMIC 118
    190 #define UCDN_SCRIPT_PAHAWH_HMONG 119
    191 #define UCDN_SCRIPT_PALMYRENE 120
    192 #define UCDN_SCRIPT_PAU_CIN_HAU 121
    193 #define UCDN_SCRIPT_PSALTER_PAHLAVI 122
    194 #define UCDN_SCRIPT_SIDDHAM 123
    195 #define UCDN_SCRIPT_TIRHUTA 124
    196 #define UCDN_SCRIPT_WARANG_CITI 125
    197 #define UCDN_SCRIPT_AHOM 126
    198 #define UCDN_SCRIPT_ANATOLIAN_HIEROGLYPHS 127
    199 #define UCDN_SCRIPT_HATRAN 128
    200 #define UCDN_SCRIPT_MULTANI 129
    201 #define UCDN_SCRIPT_OLD_HUNGARIAN 130
    202 #define UCDN_SCRIPT_SIGNWRITING 131
    203 #define UCDN_SCRIPT_ADLAM 132
    204 #define UCDN_SCRIPT_BHAIKSUKI 133
    205 #define UCDN_SCRIPT_MARCHEN 134
    206 #define UCDN_SCRIPT_NEWA 135
    207 #define UCDN_SCRIPT_OSAGE 136
    208 #define UCDN_SCRIPT_TANGUT 137
    209 
    210 #define UCDN_LINEBREAK_CLASS_OP 0
    211 #define UCDN_LINEBREAK_CLASS_CL 1
    212 #define UCDN_LINEBREAK_CLASS_CP 2
    213 #define UCDN_LINEBREAK_CLASS_QU 3
    214 #define UCDN_LINEBREAK_CLASS_GL 4
    215 #define UCDN_LINEBREAK_CLASS_NS 5
    216 #define UCDN_LINEBREAK_CLASS_EX 6
    217 #define UCDN_LINEBREAK_CLASS_SY 7
    218 #define UCDN_LINEBREAK_CLASS_IS 8
    219 #define UCDN_LINEBREAK_CLASS_PR 9
    220 #define UCDN_LINEBREAK_CLASS_PO 10
    221 #define UCDN_LINEBREAK_CLASS_NU 11
    222 #define UCDN_LINEBREAK_CLASS_AL 12
    223 #define UCDN_LINEBREAK_CLASS_HL 13
    224 #define UCDN_LINEBREAK_CLASS_ID 14
    225 #define UCDN_LINEBREAK_CLASS_IN 15
    226 #define UCDN_LINEBREAK_CLASS_HY 16
    227 #define UCDN_LINEBREAK_CLASS_BA 17
    228 #define UCDN_LINEBREAK_CLASS_BB 18
    229 #define UCDN_LINEBREAK_CLASS_B2 19
    230 #define UCDN_LINEBREAK_CLASS_ZW 20
    231 #define UCDN_LINEBREAK_CLASS_CM 21
    232 #define UCDN_LINEBREAK_CLASS_WJ 22
    233 #define UCDN_LINEBREAK_CLASS_H2 23
    234 #define UCDN_LINEBREAK_CLASS_H3 24
    235 #define UCDN_LINEBREAK_CLASS_JL 25
    236 #define UCDN_LINEBREAK_CLASS_JV 26
    237 #define UCDN_LINEBREAK_CLASS_JT 27
    238 #define UCDN_LINEBREAK_CLASS_RI 28
    239 #define UCDN_LINEBREAK_CLASS_AI 29
    240 #define UCDN_LINEBREAK_CLASS_BK 30
    241 #define UCDN_LINEBREAK_CLASS_CB 31
    242 #define UCDN_LINEBREAK_CLASS_CJ 32
    243 #define UCDN_LINEBREAK_CLASS_CR 33
    244 #define UCDN_LINEBREAK_CLASS_LF 34
    245 #define UCDN_LINEBREAK_CLASS_NL 35
    246 #define UCDN_LINEBREAK_CLASS_SA 36
    247 #define UCDN_LINEBREAK_CLASS_SG 37
    248 #define UCDN_LINEBREAK_CLASS_SP 38
    249 #define UCDN_LINEBREAK_CLASS_XX 39
    250 
    251 #define UCDN_GENERAL_CATEGORY_CC 0
    252 #define UCDN_GENERAL_CATEGORY_CF 1
    253 #define UCDN_GENERAL_CATEGORY_CN 2
    254 #define UCDN_GENERAL_CATEGORY_CO 3
    255 #define UCDN_GENERAL_CATEGORY_CS 4
    256 #define UCDN_GENERAL_CATEGORY_LL 5
    257 #define UCDN_GENERAL_CATEGORY_LM 6
    258 #define UCDN_GENERAL_CATEGORY_LO 7
    259 #define UCDN_GENERAL_CATEGORY_LT 8
    260 #define UCDN_GENERAL_CATEGORY_LU 9
    261 #define UCDN_GENERAL_CATEGORY_MC 10
    262 #define UCDN_GENERAL_CATEGORY_ME 11
    263 #define UCDN_GENERAL_CATEGORY_MN 12
    264 #define UCDN_GENERAL_CATEGORY_ND 13
    265 #define UCDN_GENERAL_CATEGORY_NL 14
    266 #define UCDN_GENERAL_CATEGORY_NO 15
    267 #define UCDN_GENERAL_CATEGORY_PC 16
    268 #define UCDN_GENERAL_CATEGORY_PD 17
    269 #define UCDN_GENERAL_CATEGORY_PE 18
    270 #define UCDN_GENERAL_CATEGORY_PF 19
    271 #define UCDN_GENERAL_CATEGORY_PI 20
    272 #define UCDN_GENERAL_CATEGORY_PO 21
    273 #define UCDN_GENERAL_CATEGORY_PS 22
    274 #define UCDN_GENERAL_CATEGORY_SC 23
    275 #define UCDN_GENERAL_CATEGORY_SK 24
    276 #define UCDN_GENERAL_CATEGORY_SM 25
    277 #define UCDN_GENERAL_CATEGORY_SO 26
    278 #define UCDN_GENERAL_CATEGORY_ZL 27
    279 #define UCDN_GENERAL_CATEGORY_ZP 28
    280 #define UCDN_GENERAL_CATEGORY_ZS 29
    281 
    282 #define UCDN_BIDI_CLASS_L 0
    283 #define UCDN_BIDI_CLASS_LRE 1
    284 #define UCDN_BIDI_CLASS_LRO 2
    285 #define UCDN_BIDI_CLASS_R 3
    286 #define UCDN_BIDI_CLASS_AL 4
    287 #define UCDN_BIDI_CLASS_RLE 5
    288 #define UCDN_BIDI_CLASS_RLO 6
    289 #define UCDN_BIDI_CLASS_PDF 7
    290 #define UCDN_BIDI_CLASS_EN 8
    291 #define UCDN_BIDI_CLASS_ES 9
    292 #define UCDN_BIDI_CLASS_ET 10
    293 #define UCDN_BIDI_CLASS_AN 11
    294 #define UCDN_BIDI_CLASS_CS 12
    295 #define UCDN_BIDI_CLASS_NSM 13
    296 #define UCDN_BIDI_CLASS_BN 14
    297 #define UCDN_BIDI_CLASS_B 15
    298 #define UCDN_BIDI_CLASS_S 16
    299 #define UCDN_BIDI_CLASS_WS 17
    300 #define UCDN_BIDI_CLASS_ON 18
    301 #define UCDN_BIDI_CLASS_LRI 19
    302 #define UCDN_BIDI_CLASS_RLI 20
    303 #define UCDN_BIDI_CLASS_FSI 21
    304 #define UCDN_BIDI_CLASS_PDI 22
    305 
    306 #define UCDN_BIDI_PAIRED_BRACKET_TYPE_OPEN 0
    307 #define UCDN_BIDI_PAIRED_BRACKET_TYPE_CLOSE 1
    308 #define UCDN_BIDI_PAIRED_BRACKET_TYPE_NONE 2
    309 
    310 /**
    311  * Return version of the Unicode database.
    312  *
    313  * @return Unicode database version
    314  */
    315 const char *ucdn_get_unicode_version(void);
    316 
    317 /**
    318  * Get combining class of a codepoint.
    319  *
    320  * @param code Unicode codepoint
    321  * @return combining class value, as defined in UAX#44
    322  */
    323 int ucdn_get_combining_class(uint32_t code);
    324 
    325 /**
    326  * Get east-asian width of a codepoint.
    327  *
    328  * @param code Unicode codepoint
    329  * @return value according to UCDN_EAST_ASIAN_* and as defined in UAX#11.
    330  */
    331 int ucdn_get_east_asian_width(uint32_t code);
    332 
    333 /**
    334  * Get general category of a codepoint.
    335  *
    336  * @param code Unicode codepoint
    337  * @return value according to UCDN_GENERAL_CATEGORY_* and as defined in
    338  * UAX#44.
    339  */
    340 int ucdn_get_general_category(uint32_t code);
    341 
    342 /**
    343  * Get bidirectional class of a codepoint.
    344  *
    345  * @param code Unicode codepoint
    346  * @return value according to UCDN_BIDI_CLASS_* and as defined in UAX#44.
    347  */
    348 int ucdn_get_bidi_class(uint32_t code);
    349 
    350 /**
    351  * Get script of a codepoint.
    352  *
    353  * @param code Unicode codepoint
    354  * @return value according to UCDN_SCRIPT_* and as defined in UAX#24.
    355  */
    356 int ucdn_get_script(uint32_t code);
    357 
    358 /**
    359  * Get unresolved linebreak class of a codepoint. This does not take
    360  * rule LB1 of UAX#14 into account. See ucdn_get_resolved_linebreak_class()
    361  * for resolved linebreak classes.
    362  *
    363  * @param code Unicode codepoint
    364  * @return value according to UCDN_LINEBREAK_* and as defined in UAX#14.
    365  */
    366 int ucdn_get_linebreak_class(uint32_t code);
    367 
    368 /**
    369  * Get resolved linebreak class of a codepoint. This resolves characters
    370  * in the AI, SG, XX, SA and CJ classes according to rule LB1 of UAX#14.
    371  * In addition the CB class is resolved as the equivalent B2 class and
    372  * the NL class is resolved as the equivalent BK class.
    373  *
    374  * @param code Unicode codepoint
    375  * @return value according to UCDN_LINEBREAK_* and as defined in UAX#14.
    376  */
    377 int ucdn_get_resolved_linebreak_class(uint32_t code);
    378 
    379 /**
    380  * Check if codepoint can be mirrored.
    381  *
    382  * @param code Unicode codepoint
    383  * @return 1 if mirrored character exists, otherwise 0
    384  */
    385 int ucdn_get_mirrored(uint32_t code);
    386 
    387 /**
    388  * Mirror a codepoint.
    389  *
    390  * @param code Unicode codepoint
    391  * @return mirrored codepoint or the original codepoint if no
    392  * mirrored character exists
    393  */
    394 uint32_t ucdn_mirror(uint32_t code);
    395 
    396 /**
    397  * Get paired bracket for a codepoint.
    398  *
    399  * @param code Unicode codepoint
    400  * @return paired bracket codepoint or the original codepoint if no
    401  * paired bracket character exists
    402  */
    403 uint32_t ucdn_paired_bracket(uint32_t code);
    404 
    405 /**
    406  * Get paired bracket type for a codepoint.
    407  *
    408  * @param code Unicode codepoint
    409  * @return value according to UCDN_BIDI_PAIRED_BRACKET_TYPE_* and as defined
    410  * in UAX#9.
    411  *
    412  */
    413 int ucdn_paired_bracket_type(uint32_t code);
    414 
    415 /**
    416  * Pairwise canonical decomposition of a codepoint. This includes
    417  * Hangul Jamo decomposition (see chapter 3.12 of the Unicode core
    418  * specification).
    419  *
    420  * Hangul is decomposed into L and V jamos for LV forms, and an
    421  * LV precomposed syllable and a T jamo for LVT forms.
    422  *
    423  * @param code Unicode codepoint
    424  * @param a filled with first codepoint of decomposition
    425  * @param b filled with second codepoint of decomposition, or 0
    426  * @return success
    427  */
    428 int ucdn_decompose(uint32_t code, uint32_t *a, uint32_t *b);
    429 
    430 /**
    431  * Compatibility decomposition of a codepoint.
    432  *
    433  * @param code Unicode codepoint
    434  * @param decomposed filled with decomposition, must be able to hold 18
    435  * characters
    436  * @return length of decomposition or 0 in case none exists
    437  */
    438 int ucdn_compat_decompose(uint32_t code, uint32_t *decomposed);
    439 
    440 /**
    441  * Pairwise canonical composition of two codepoints. This includes
    442  * Hangul Jamo composition (see chapter 3.12 of the Unicode core
    443  * specification).
    444  *
    445  * Hangul composition expects either L and V jamos, or an LV
    446  * precomposed syllable and a T jamo. This is exactly the inverse
    447  * of pairwise Hangul decomposition.
    448  *
    449  * @param code filled with composition
    450  * @param a first codepoint
    451  * @param b second codepoint
    452  * @return success
    453  */
    454 int ucdn_compose(uint32_t *code, uint32_t a, uint32_t b);
    455 
    456 #ifdef __cplusplus
    457 }
    458 #endif
    459 
    460 #endif
    461