hb-glib.cc 6.0 KB
Newer Older
B
Behdad Esfahbod 已提交
1 2 3
/*
 * Copyright (C) 2009  Red Hat, Inc.
 *
B
Behdad Esfahbod 已提交
4
 *  This is part of HarfBuzz, a text shaping library.
B
Behdad Esfahbod 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Red Hat Author(s): Behdad Esfahbod
 */

#include "hb-private.h"

#include "hb-glib.h"

31
#include "hb-unicode-private.hh"
B
Behdad Esfahbod 已提交
32

33 34
#include <glib.h>

B
Behdad Esfahbod 已提交
35 36 37
HB_BEGIN_DECLS


38 39 40 41 42
static unsigned int
hb_glib_get_combining_class (hb_unicode_funcs_t *ufuncs,
                             hb_codepoint_t      unicode,
                             void               *user_data)

43
{
44 45 46 47 48 49 50 51 52
  return g_unichar_combining_class (unicode);
}

static unsigned int
hb_glib_get_eastasian_width (hb_unicode_funcs_t *ufuncs,
                             hb_codepoint_t      unicode,
                             void               *user_data)
{
  return g_unichar_iswide (unicode) ? 2 : 1;
53 54 55 56 57 58 59 60
}

static hb_unicode_general_category_t
hb_glib_get_general_category (hb_unicode_funcs_t *ufuncs,
                              hb_codepoint_t      unicode,
                              void               *user_data)

{
61 62 63 64 65 66 67 68 69 70 71
  /* hb_unicode_general_category_t and GUnicodeType are identical */
  return (hb_unicode_general_category_t) g_unichar_type (unicode);
}

static hb_codepoint_t
hb_glib_get_mirroring (hb_unicode_funcs_t *ufuncs,
                       hb_codepoint_t      unicode,
                       void               *user_data)
{
  g_unichar_get_mirror_char (unicode, &unicode);
  return unicode;
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
}

static hb_script_t
hb_glib_get_script (hb_unicode_funcs_t *ufuncs,
                    hb_codepoint_t      unicode,
                    void               *user_data)
{
  GUnicodeScript script = g_unichar_get_script (unicode);
  switch (script)
  {
#define MATCH_SCRIPT(C) case G_UNICODE_SCRIPT_##C: return HB_SCRIPT_##C
#define MATCH_SCRIPT2(C1, C2) case G_UNICODE_SCRIPT_##C1: return HB_SCRIPT_##C2

  MATCH_SCRIPT2(INVALID_CODE, INVALID);

B
Behdad Esfahbod 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
  MATCH_SCRIPT (COMMON);
  MATCH_SCRIPT (INHERITED);
  MATCH_SCRIPT (ARABIC);
  MATCH_SCRIPT (ARMENIAN);
  MATCH_SCRIPT (BENGALI);
  MATCH_SCRIPT (BOPOMOFO);
  MATCH_SCRIPT (CHEROKEE);
  MATCH_SCRIPT (COPTIC);
  MATCH_SCRIPT (CYRILLIC);
  MATCH_SCRIPT (DESERET);
  MATCH_SCRIPT (DEVANAGARI);
  MATCH_SCRIPT (ETHIOPIC);
  MATCH_SCRIPT (GEORGIAN);
  MATCH_SCRIPT (GOTHIC);
  MATCH_SCRIPT (GREEK);
  MATCH_SCRIPT (GUJARATI);
  MATCH_SCRIPT (GURMUKHI);
  MATCH_SCRIPT (HAN);
  MATCH_SCRIPT (HANGUL);
  MATCH_SCRIPT (HEBREW);
  MATCH_SCRIPT (HIRAGANA);
  MATCH_SCRIPT (KANNADA);
  MATCH_SCRIPT (KATAKANA);
  MATCH_SCRIPT (KHMER);
  MATCH_SCRIPT (LAO);
  MATCH_SCRIPT (LATIN);
  MATCH_SCRIPT (MALAYALAM);
  MATCH_SCRIPT (MONGOLIAN);
  MATCH_SCRIPT (MYANMAR);
  MATCH_SCRIPT (OGHAM);
  MATCH_SCRIPT (OLD_ITALIC);
  MATCH_SCRIPT (ORIYA);
  MATCH_SCRIPT (RUNIC);
  MATCH_SCRIPT (SINHALA);
  MATCH_SCRIPT (SYRIAC);
  MATCH_SCRIPT (TAMIL);
  MATCH_SCRIPT (TELUGU);
  MATCH_SCRIPT (THAANA);
  MATCH_SCRIPT (THAI);
  MATCH_SCRIPT (TIBETAN);
  MATCH_SCRIPT (CANADIAN_ABORIGINAL);
  MATCH_SCRIPT (YI);
  MATCH_SCRIPT (TAGALOG);
  MATCH_SCRIPT (HANUNOO);
  MATCH_SCRIPT (BUHID);
  MATCH_SCRIPT (TAGBANWA);
133 134

  /* Unicode-4.0 additions */
B
Behdad Esfahbod 已提交
135 136 137 138 139 140 141 142
  MATCH_SCRIPT (BRAILLE);
  MATCH_SCRIPT (CYPRIOT);
  MATCH_SCRIPT (LIMBU);
  MATCH_SCRIPT (OSMANYA);
  MATCH_SCRIPT (SHAVIAN);
  MATCH_SCRIPT (LINEAR_B);
  MATCH_SCRIPT (TAI_LE);
  MATCH_SCRIPT (UGARITIC);
143 144

  /* Unicode-4.1 additions */
B
Behdad Esfahbod 已提交
145 146 147 148 149 150 151
  MATCH_SCRIPT (NEW_TAI_LUE);
  MATCH_SCRIPT (BUGINESE);
  MATCH_SCRIPT (GLAGOLITIC);
  MATCH_SCRIPT (TIFINAGH);
  MATCH_SCRIPT (SYLOTI_NAGRI);
  MATCH_SCRIPT (OLD_PERSIAN);
  MATCH_SCRIPT (KHAROSHTHI);
152 153

  /* Unicode-5.0 additions */
B
Behdad Esfahbod 已提交
154 155 156 157 158 159
  MATCH_SCRIPT (UNKNOWN);
  MATCH_SCRIPT (BALINESE);
  MATCH_SCRIPT (CUNEIFORM);
  MATCH_SCRIPT (PHOENICIAN);
  MATCH_SCRIPT (PHAGS_PA);
  MATCH_SCRIPT (NKO);
B
Behdad Esfahbod 已提交
160

161
  /* Unicode-5.1 additions */
B
Behdad Esfahbod 已提交
162 163 164 165 166 167 168 169 170 171 172
  MATCH_SCRIPT (KAYAH_LI);
  MATCH_SCRIPT (LEPCHA);
  MATCH_SCRIPT (REJANG);
  MATCH_SCRIPT (SUNDANESE);
  MATCH_SCRIPT (SAURASHTRA);
  MATCH_SCRIPT (CHAM);
  MATCH_SCRIPT (OL_CHIKI);
  MATCH_SCRIPT (VAI);
  MATCH_SCRIPT (CARIAN);
  MATCH_SCRIPT (LYCIAN);
  MATCH_SCRIPT (LYDIAN);
173 174 175

  /* Unicode-5.2 additions */
#if GLIB_CHECK_VERSION(2,26,0)
B
Behdad Esfahbod 已提交
176 177 178 179 180 181 182 183 184 185 186 187
  MATCH_SCRIPT (AVESTAN);
  MATCH_SCRIPT (BAMUM);
  MATCH_SCRIPT (EGYPTIAN_HIEROGLYPHS);
  MATCH_SCRIPT (IMPERIAL_ARAMAIC);
  MATCH_SCRIPT (INSCRIPTIONAL_PAHLAVI);
  MATCH_SCRIPT (INSCRIPTIONAL_PARTHIAN);
  MATCH_SCRIPT (JAVANESE);
  MATCH_SCRIPT (KAITHI);
  MATCH_SCRIPT (TAI_THAM);
  MATCH_SCRIPT (LISU);
  MATCH_SCRIPT (MEETEI_MAYEK);
  MATCH_SCRIPT (OLD_SOUTH_ARABIAN);
188
#if GLIB_CHECK_VERSION(2,27,92)
B
Behdad Esfahbod 已提交
189
  MATCH_SCRIPT (OLD_TURKIC);
190
#else
B
Behdad Esfahbod 已提交
191
  MATCH_SCRIPT2(OLD_TURKISH, OLD_TURKIC);
192
#endif
B
Behdad Esfahbod 已提交
193 194
  MATCH_SCRIPT (SAMARITAN);
  MATCH_SCRIPT (TAI_VIET);
195 196 197 198
#endif

  /* Unicode-6.0 additions */
#if GLIB_CHECK_VERSION(2,28,0)
B
Behdad Esfahbod 已提交
199 200 201
  MATCH_SCRIPT (BATAK);
  MATCH_SCRIPT (BRAHMI);
  MATCH_SCRIPT (MANDAIC);
202 203 204 205 206 207 208 209 210
#endif

#undef MATCH_SCRIPT
#undef MATCH_SCRIPT2
  }

  return HB_SCRIPT_UNKNOWN;
}

211 212
static hb_unicode_funcs_t glib_ufuncs = {
  HB_REFERENCE_COUNT_INVALID, /* ref_count */
213
  NULL, /* parent */
214
  TRUE, /* immutable */
B
Behdad Esfahbod 已提交
215
  {
216 217 218 219 220
    hb_glib_get_combining_class,
    hb_glib_get_eastasian_width,
    hb_glib_get_general_category,
    hb_glib_get_mirroring,
    hb_glib_get_script
B
Behdad Esfahbod 已提交
221
  }
222
};
B
Behdad Esfahbod 已提交
223 224

hb_unicode_funcs_t *
B
Behdad Esfahbod 已提交
225
hb_glib_get_unicode_funcs (void)
B
Behdad Esfahbod 已提交
226
{
227
  return &glib_ufuncs;
B
Behdad Esfahbod 已提交
228
}
B
Behdad Esfahbod 已提交
229 230 231


HB_END_DECLS