Home | History | Annotate | Download | only in contrib
      1 /*
      2  * Copyright 2010, The Android Open Source Project
      3  * Copyright 2010, Google Inc. All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *  * Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  *  * Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #include "harfbuzz-external.h"
     28 
     29 #include   <unicode/uchar.h>
     30 #include   <unicode/utypes.h>
     31 
     32 /*
     33    We use ICU APIs to get the character's Unicode property.
     34    This module replaces the harfbuzz-unicode-tables.c which is
     35    using static Unicode tables.
     36 */
     37 
     38 static int
     39 hb_category_for_char(HB_UChar32 ch) {
     40   switch (u_charType(ch)) {
     41     case U_CONTROL_CHAR:
     42       return HB_Other_Control;
     43     case U_FORMAT_CHAR:
     44       return HB_Other_Format;
     45     case U_UNASSIGNED:
     46       return HB_Other_NotAssigned;
     47     case U_PRIVATE_USE_CHAR:
     48       return HB_Other_PrivateUse;
     49     case U_SURROGATE:
     50       return HB_Other_Surrogate;
     51     case U_LOWERCASE_LETTER:
     52       return HB_Letter_Lowercase;
     53     case U_MODIFIER_LETTER:
     54       return HB_Letter_Modifier;
     55     case U_OTHER_LETTER:
     56       return HB_Letter_Other;
     57     case U_TITLECASE_LETTER:
     58       return HB_Letter_Titlecase;
     59     case U_UPPERCASE_LETTER:
     60       return HB_Letter_Uppercase;
     61     case U_COMBINING_SPACING_MARK:
     62       return HB_Mark_SpacingCombining;
     63     case U_ENCLOSING_MARK:
     64       return HB_Mark_Enclosing;
     65     case U_NON_SPACING_MARK:
     66       return HB_Mark_NonSpacing;
     67     case U_DECIMAL_DIGIT_NUMBER :
     68       return HB_Number_DecimalDigit;
     69     case U_LETTER_NUMBER:
     70       return HB_Number_Letter;
     71     case U_OTHER_NUMBER:
     72       return HB_Number_Other;
     73     case U_CONNECTOR_PUNCTUATION:
     74       return HB_Punctuation_Connector;
     75     case U_DASH_PUNCTUATION:
     76       return HB_Punctuation_Dash;
     77     case U_END_PUNCTUATION:
     78       return HB_Punctuation_Close;
     79     case U_FINAL_PUNCTUATION:
     80       return HB_Punctuation_FinalQuote;
     81     case U_INITIAL_PUNCTUATION:
     82       return HB_Punctuation_InitialQuote;
     83     case U_OTHER_PUNCTUATION:
     84       return HB_Punctuation_Other;
     85     case U_START_PUNCTUATION:
     86       return HB_Punctuation_Open;
     87     case U_CURRENCY_SYMBOL:
     88       return HB_Symbol_Currency;
     89     case U_MODIFIER_SYMBOL:
     90       return HB_Symbol_Modifier;
     91     case U_MATH_SYMBOL:
     92       return HB_Symbol_Math;
     93     case U_OTHER_SYMBOL:
     94       return HB_Symbol_Other;
     95     case U_LINE_SEPARATOR:
     96       return HB_Separator_Line;
     97     case U_PARAGRAPH_SEPARATOR:
     98       return HB_Separator_Paragraph;
     99     case U_SPACE_SEPARATOR:
    100       return HB_Separator_Space;
    101     default:
    102       return HB_Symbol_Other;
    103   }
    104 }
    105 
    106 HB_LineBreakClass
    107 HB_GetLineBreakClass(HB_UChar32 ch) {
    108   switch ((ULineBreak)u_getIntPropertyValue(ch, UCHAR_LINE_BREAK)) {
    109     case U_LB_MANDATORY_BREAK:
    110       return HB_LineBreak_BK;
    111     case U_LB_CARRIAGE_RETURN:
    112       return HB_LineBreak_CR;
    113     case U_LB_LINE_FEED:
    114       return HB_LineBreak_LF;
    115     case U_LB_COMBINING_MARK:
    116       return HB_LineBreak_CM;
    117     case U_LB_SURROGATE:
    118       return HB_LineBreak_SG;
    119     case U_LB_ZWSPACE:
    120       return HB_LineBreak_ZW;
    121     case U_LB_INSEPARABLE:
    122       return HB_LineBreak_IN;
    123     case U_LB_GLUE:
    124       return HB_LineBreak_GL;
    125     case U_LB_CONTINGENT_BREAK:
    126       return HB_LineBreak_AL;
    127     case U_LB_SPACE:
    128       return HB_LineBreak_SP;
    129     case U_LB_BREAK_AFTER:
    130       return HB_LineBreak_BA;
    131     case U_LB_BREAK_BEFORE:
    132       return HB_LineBreak_BB;
    133     case U_LB_BREAK_BOTH:
    134       return HB_LineBreak_B2;
    135     case U_LB_HYPHEN:
    136       return HB_LineBreak_HY;
    137     case U_LB_NONSTARTER:
    138       return HB_LineBreak_NS;
    139     case U_LB_OPEN_PUNCTUATION:
    140       return HB_LineBreak_OP;
    141     case U_LB_CLOSE_PUNCTUATION:
    142       return HB_LineBreak_CL;
    143     case U_LB_QUOTATION:
    144       return HB_LineBreak_QU;
    145     case U_LB_EXCLAMATION:
    146       return HB_LineBreak_EX;
    147     case U_LB_IDEOGRAPHIC:
    148       return HB_LineBreak_ID;
    149     case U_LB_NUMERIC:
    150       return HB_LineBreak_NU;
    151     case U_LB_INFIX_NUMERIC:
    152       return HB_LineBreak_IS;
    153     case U_LB_BREAK_SYMBOLS:
    154       return HB_LineBreak_SY;
    155     case U_LB_ALPHABETIC:
    156       return HB_LineBreak_AL;
    157     case U_LB_PREFIX_NUMERIC:
    158       return HB_LineBreak_PR;
    159     case U_LB_POSTFIX_NUMERIC:
    160       return HB_LineBreak_PO;
    161     case U_LB_COMPLEX_CONTEXT:
    162       return HB_LineBreak_SA;
    163     case U_LB_AMBIGUOUS:
    164       return HB_LineBreak_AL;
    165     case U_LB_UNKNOWN:
    166       return HB_LineBreak_AL;
    167     case U_LB_NEXT_LINE:
    168       return HB_LineBreak_AL;
    169     case U_LB_WORD_JOINER:
    170       return HB_LineBreak_WJ;
    171     case U_LB_JL:
    172       return HB_LineBreak_JL;
    173     case U_LB_JV:
    174       return HB_LineBreak_JV;
    175     case U_LB_JT:
    176       return HB_LineBreak_JT;
    177     case U_LB_H2:
    178       return HB_LineBreak_H2;
    179     case U_LB_H3:
    180       return HB_LineBreak_H3;
    181     default:
    182       return HB_LineBreak_AL;
    183   }
    184 }
    185 
    186 int
    187 HB_GetUnicodeCharCombiningClass(HB_UChar32 ch) {
    188   return u_getCombiningClass(ch);
    189 }
    190 
    191 void
    192 HB_GetUnicodeCharProperties(HB_UChar32 ch,
    193                             HB_CharCategory *category,
    194                             int *combiningClass) {
    195   *category = hb_category_for_char(ch);
    196   *combiningClass = u_getCombiningClass(ch);
    197 }
    198 
    199 HB_CharCategory
    200 HB_GetUnicodeCharCategory(HB_UChar32 ch) {
    201   return hb_category_for_char(ch);
    202 }
    203