From 5887668b173a6a26a8779a747ed4b7be9e1d2eed Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Thu, 7 Mar 2019 17:42:47 +0800 Subject: [PATCH] add new API UCharGetBracketType --- include/gdi.h | 7 +++++++ src/font/charset.c | 28 +++++++++++++++++++++++++++- src/include/bidi.h | 4 ---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/gdi.h b/include/gdi.h index 724ede16..b1333553 100644 --- a/include/gdi.h +++ b/include/gdi.h @@ -7470,6 +7470,13 @@ MG_EXPORT UCharBreakType GUIAPI UCharGetBreakType(Uchar32 uc); /** The function determines the BIDI type of a UNICODE character. */ MG_EXPORT Uint16 GUIAPI UCharGetBIDIType(Uchar32 uc); +#define BIDICHAR_BRACKET_NONE 0 +#define BIDICHAR_BRACKET_OPEN 1 +#define BIDICHAR_BRACKET_CLOSE 2 + +/** The function returns the bracket type of a UNICODE character. */ +MG_EXPORT Uint8 GUIAPI UCharGetBracketType(Uchar32 uc); + /** The function returns the mirror character of a UNICODE character. */ MG_EXPORT BOOL GUIAPI UCharGetMirror(Uchar32 uc, Uchar32* mirrored); diff --git a/src/font/charset.c b/src/font/charset.c index 803694d8..070f6ede 100644 --- a/src/font/charset.c +++ b/src/font/charset.c @@ -4406,6 +4406,32 @@ Uint16 GUIAPI UCharGetBIDIType(Uchar32 uc) return unicode_bidi_char_type(uc); } +/** The function returns the bracket type of a UNICODE character. */ +Uint8 GUIAPI UCharGetBracketType(Uchar32 uc) +{ + unsigned int lower = 0; + unsigned int upper = TABLESIZE (__mg_unicode_bracket_table) - 1; + int mid = TABLESIZE (__mg_unicode_bracket_table) / 2; + + if (uc < __mg_unicode_bracket_table[lower].chv || + uc > __mg_unicode_bracket_table[upper].chv) + return BIDICHAR_BRACKET_NONE; + + do { + if (uc < __mg_unicode_bracket_table[mid].chv) + upper = mid - 1; + else if (uc > __mg_unicode_bracket_table[mid].chv) + lower = mid + 1; + else + return __mg_unicode_bracket_table[mid].type; + + mid = (lower + upper) / 2; + + } while (lower <= upper); + + return BIDICHAR_BRACKET_NONE; +} + /** The function returns the mirror character of a UNICODE character. */ BOOL GUIAPI UCharGetMirror(Uchar32 uc, Uchar32* mirrored) { @@ -4881,7 +4907,7 @@ Uchar32 GUIAPI UCharToSmallKana (Uchar32 uc) int mid = TABLESIZE (kana_small_to_full_size_table) / 2; if (uc < kana_small_to_full_size_table[lower].other - || uc < kana_small_to_full_size_table[upper].other) + || uc > kana_small_to_full_size_table[upper].other) return uc; do { diff --git a/src/include/bidi.h b/src/include/bidi.h index 727537dd..6f441f76 100644 --- a/src/include/bidi.h +++ b/src/include/bidi.h @@ -67,10 +67,6 @@ typedef struct _BIDICHAR_TYPE_MAP { typedef struct _TYPERUN TYPERUN; -#define BIDICHAR_BRACKET_NONE 0 -#define BIDICHAR_BRACKET_OPEN 1 -#define BIDICHAR_BRACKET_CLOSE 2 - // NOTE: It is enough to use Uint16 for Unicode bracket table typedef struct _BIDICHAR_BRACKET { Uint16 chv;