Home | History | Annotate | Download | only in contrib
      1 #include <stdlib.h>
      2 #include <stdint.h>
      3 
      4 #include <harfbuzz-external.h>
      5 
      6 #include "tables/category-properties.h"
      7 #include "tables/combining-properties.h"
      8 
      9 HB_LineBreakClass
     10 HB_GetLineBreakClass(HB_UChar32 ch) {
     11   abort();
     12   return 0;
     13 }
     14 
     15 static int
     16 combining_property_cmp(const void *vkey, const void *vcandidate) {
     17   const uint32_t key = (uint32_t) (intptr_t) vkey;
     18   const struct combining_property *candidate = vcandidate;
     19 
     20   if (key < candidate->range_start) {
     21     return -1;
     22   } else if (key > candidate->range_end) {
     23     return 1;
     24   } else {
     25     return 0;
     26   }
     27 }
     28 
     29 static int
     30 code_point_to_combining_class(HB_UChar32 cp) {
     31   const void *vprop = bsearch((void *) (intptr_t) cp, combining_properties,
     32                               combining_properties_count,
     33                               sizeof(struct combining_property),
     34                               combining_property_cmp);
     35   if (!vprop)
     36     return 0;
     37 
     38   return ((const struct combining_property *) vprop)->klass;
     39 }
     40 
     41 int
     42 HB_GetUnicodeCharCombiningClass(HB_UChar32 ch) {
     43   return code_point_to_combining_class(ch);
     44   return 0;
     45 }
     46 
     47 static int
     48 category_property_cmp(const void *vkey, const void *vcandidate) {
     49   const uint32_t key = (uint32_t) (intptr_t) vkey;
     50   const struct category_property *candidate = vcandidate;
     51 
     52   if (key < candidate->range_start) {
     53     return -1;
     54   } else if (key > candidate->range_end) {
     55     return 1;
     56   } else {
     57     return 0;
     58   }
     59 }
     60 
     61 static HB_CharCategory
     62 code_point_to_category(HB_UChar32 cp) {
     63   const void *vprop = bsearch((void *) (intptr_t) cp, category_properties,
     64                               category_properties_count,
     65                               sizeof(struct category_property),
     66                               category_property_cmp);
     67   if (!vprop)
     68     return HB_NoCategory;
     69 
     70   return ((const struct category_property *) vprop)->category;
     71 }
     72 
     73 void
     74 HB_GetUnicodeCharProperties(HB_UChar32 ch,
     75                             HB_CharCategory *category,
     76                             int *combiningClass) {
     77   *category = code_point_to_category(ch);
     78   *combiningClass = code_point_to_combining_class(ch);
     79 }
     80 
     81 HB_CharCategory
     82 HB_GetUnicodeCharCategory(HB_UChar32 ch) {
     83   return code_point_to_category(ch);
     84 }
     85