diff options
author | Behnam Esfahbod ZWNJ <behnam@zwnj.org> | 2010-10-11 07:02:30 +0330 |
---|---|---|
committer | Behnam Esfahbod <behnam@esfahbod.info> | 2012-01-24 03:37:00 -0500 |
commit | ab060bb8efc09793d0a1bea70a416a60affbd44b (patch) | |
tree | 9e67605ad752ec1c1e7200361e50c1f24697d25c | |
parent | 49bb8ef7a08c6c9c1e069fc09c15996dfd4decd5 (diff) |
Create separate modulesunstable
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | fribidi/__init__.py | 10 | ||||
-rw-r--r-- | fribidi/_malloc.py | 78 | ||||
-rw-r--r-- | fribidi/_type.py | 209 | ||||
-rwxr-xr-x | fribidi/fribidi.py (renamed from fribidi.py) | 407 | ||||
l--------- | test/fribidi | 1 | ||||
l--------- | test/fribidi.py | 1 | ||||
-rwxr-xr-x | test/test1.py | 167 | ||||
-rwxr-xr-x | test/test2.py | 27 |
9 files changed, 457 insertions, 448 deletions
@@ -4,9 +4,10 @@ all: ctags tests tests: - @echo `pkg-config --libs-only-L fribidi | sed s'/^-L//'` + @pkg-config --libs-only-L fribidi + @echo python test/test1.py - python test/test2.py + @#python test/test2.py ctags: @clear diff --git a/fribidi/__init__.py b/fribidi/__init__.py new file mode 100644 index 0000000..b39f352 --- /dev/null +++ b/fribidi/__init__.py @@ -0,0 +1,10 @@ +# coding=UTF-8 + +# TODO: COPYRIGHT + +# TODO: PY3000 +try: + from fribidi import * +except: + from fribidi import * + diff --git a/fribidi/_malloc.py b/fribidi/_malloc.py new file mode 100644 index 0000000..5debd1c --- /dev/null +++ b/fribidi/_malloc.py @@ -0,0 +1,78 @@ +# coding=UTF-8 + +# TODO: COPYRIGHT + +import ctypes + + +# Memory allocation functions + +def int_array(n): + + """ + Return a pointer to allocated C int array of length `n'. + """ + + t = ctypes.c_int * n + return t() + + +def int8_array(n): + + """ + Return a pointer to allocated C int array of length `n'. + """ + + t = ctypes.c_int8 * n + return t() + + +def int32_array(n): + + """ + Return a pointer to allocated C int32 array of length `n'. + """ + + t = ctypes.c_uint32 * n + return t() + + +def int32_array_from_list(a, n=None): + + """ + Return a pointer to allocated C int32 array of length `n', initialized with `a' + + If `n' is not set, the length of `a' will be considered. + """ + + if n is None: + n = len(a) + + # Memory allocations + + m = int32_array(n) + + for i in xrange(n): + m[i] = a[i] + + return m + + +def char_array(n): + + """ + Return a pointer to allocated UTF8 (C char) array of length `n'. + """ + + t = ctypes.c_char * n + return t() + + +def char_array_from_string(s): + + """ + Return a pointer to allocated UTF8 (C char) array, initialized with `s'. + """ + + return ctypes.c_char_p(s) + diff --git a/fribidi/_type.py b/fribidi/_type.py new file mode 100644 index 0000000..eafcd5a --- /dev/null +++ b/fribidi/_type.py @@ -0,0 +1,209 @@ +# coding=UTF-8 + +# TODO: COPYRIGHT + +# ######################################################################## +# FriBidi API, Bidi, Types (fribidi-bidi-types.h) + +# Character and Paragraph Masks and Types + +class Mask: + """ + TODO. + """ + + # Mask values + + RTL = 0x00000001 # Is right to left + ARABIC = 0x00000002 # Is arabic + + # Each character can be only one of the three following: + STRONG = 0x00000010 # Is strong + WEAK = 0x00000020 # Is weak + NEUTRAL = 0x00000040 # Is neutral + SENTINEL = 0x00000080 # Is sentinel + # Sentinels are not valid chars, just identify the start/end of strings. + + # Each charcter can be only one of the five following: + LETTER = 0x00000100 # Is letter: L, R, AL + NUMBER = 0x00000200 # Is number: EN, AN + NUMSEPTER = 0x00000400 # Is number separator or terminator: ES, ET, CS + SPACE = 0x00000800 # Is space: BN, BS, SS, WS + EXPLICIT = 0x00001000 # Is expilict mark: LRE, RLE, LRO, RLO, PDF + + # Can be set only if Mask.SPACE is also set. + SEPARATOR = 0x00002000 # Is test separator: BS, SS + + OVERRIDE = 0x00004000 # Is explicit override: LRO, RLO + + # The following must be to make types pairwise different, some of them can + # be removed but are here because of efficiency (make queries faster). + ES = 0x00010000 + ET = 0x00020000 + CS = 0x00040000 + + NSM = 0x00080000 + BN = 0x00100000 + + BS = 0x00200000 + SS = 0x00400000 + WS = 0x00800000 + + # We reserve a single bit for user's private use: we will never use it. + PRIVATE = 0x01000000 + + +class _Type: + """ + TODO. + """ + + # Strong types + + LTR = Mask.STRONG + Mask.LETTER # Left-To-Right letter + RTL = Mask.STRONG + Mask.LETTER + Mask.RTL # Right-To-Left letter + AL = Mask.STRONG + Mask.LETTER + Mask.RTL + Mask.ARABIC # Arabic Letter + LRE = Mask.STRONG + Mask.EXPLICIT # Left-to-Right Embedding + RLE = Mask.STRONG + Mask.EXPLICIT + Mask.RTL # Right-to-Left Embedding + LRO = Mask.STRONG + Mask.EXPLICIT + Mask.OVERRIDE # Left-to-Right Override + RLO = Mask.STRONG + Mask.EXPLICIT + Mask.RTL + Mask.OVERRIDE # Right-to-Left Override + + # Weak types + + PDF = Mask.WEAK + Mask.EXPLICIT # Pop Directional Override + EN = Mask.WEAK + Mask.NUMBER # European Numeral + AN = Mask.WEAK + Mask.NUMBER + Mask.ARABIC # Arabic Numeral + ES = Mask.WEAK + Mask.NUMSEPTER + Mask.ES # European number Separator + ET = Mask.WEAK + Mask.NUMSEPTER + Mask.ET # European number Terminator + CS = Mask.WEAK + Mask.NUMSEPTER + Mask.CS # Common Separator + NSM = Mask.WEAK + Mask.NSM # Non Spacing Mark + BN = Mask.WEAK + Mask.SPACE + Mask.BN # Boundary Neutral + + # Neutral types + + BS = Mask.NEUTRAL + Mask.SPACE + Mask.SEPARATOR + Mask.BS # Block Separator + SS = Mask.NEUTRAL + Mask.SPACE + Mask.SEPARATOR + Mask.SS # Segment Separator + WS = Mask.NEUTRAL + Mask.SPACE + Mask.WS # WhiteSpace + ON = Mask.NEUTRAL # Other Neutral + + # Paragraph-only types + + WLTR = Mask.WEAK # Weak Left-To-Right + WRTL = Mask.WEAK | Mask.RTL # Weak Right-To-Left + + SENTINEL = Mask.SENTINEL # start or end of text (run list) SENTINEL + # Only used internally + + PRIVATE = Mask.PRIVATE # Private types for applications + # More private types can be obtained by summing up from this one + + +class CharType: + """ + Class of character (direction) types. + + Strong types: + + LTR Left-To-Right letter + RTL Right-To-Left letter + AL Arabic Letter + LRE Left-to-Right Embedding + RLE Right-to-Left Embedding + LRO Left-to-Right Override + RLO Right-to-Left Override + + Weak types: + + PDF Pop Directional Override + EN European Numeral + AN Arabic Numeral + ES European number Separator + ET European number Terminator + CS Common Separator + NSM Non Spacing Mark + BN Boundary Neutral + + Neutral types: + + BS Block Separator + SS Segment Separator + WS WhiteSpace + ON Other Neutral + """ + + LTR = _Type.LTR + RTL = _Type.RTL + AL = _Type.AL + EN = _Type.EN + AN = _Type.AN + ES = _Type.ES + ET = _Type.ET + CS = _Type.CS + NSM = _Type.NSM + BN = _Type.BN + BS = _Type.BS + SS = _Type.SS + WS = _Type.WS + ON = _Type.ON + LRE = _Type.LRE + RLE = _Type.RLE + LRO = _Type.LRO + RLO = _Type.RLO + PDF = _Type.PDF + + +class ParType: + """ + Class of paragraph (direction) types: + + LTR Left-to-Right paragraph + RTL Right-to-Left paragraph + ON (Other) Neutral paragraph + WLTR Weak Left-to-Right paragraph + WRTL Weak Right-to-Left paragraph + """ + + LTR = _Type.LTR + RTL = _Type.RTL + ON = _Type.ON + WLTR = _Type.WLTR + WRTL = _Type.WRTL + + +# Mask and Type functions + +def level_is_rtl(lev): + """ + Return True if `lev' is a Right-to-Left level, False otherwise. + """ + + return lev & 1 + + +def level_to_dir(lev): + """ + Return the bidi type corresponding to the direction of the level number. + + Return ParType.LTR for evens, and ParType.RTL for odds. + """ + + return ParType.RTL if level_is_rtl(lev) else ParType.LTR + + +def dir_is_rtl(dir): + """ + Return True if `dir' is a Right-to-Left, False otherwise. + """ + + return dir & Mask.RTL + + +def dir_to_level(dir): + """ + Return the minimum level of the direction. + + Return 0 for LTR and 1 for RTL. + """ + + return 1 if dir_is_rtl(dir) else 0 + diff --git a/fribidi.py b/fribidi/fribidi.py index efd80e5..d5c4366 100755 --- a/fribidi.py +++ b/fribidi/fribidi.py @@ -1,113 +1,68 @@ #!/usr/bin/env python # coding=UTF-8 +# TODO: COPYRIGHT + """ -an implementation of Unicode Bidirectional Algorithm, using GNU FriBidi +implementation of Unicode Bidirectional Algorithm, using GNU FriBidi This is a python wrap of GNU FriBidi C library. http://fribidi.org/ GNU FriBidi is an implementation of Unicode Bidirectional Algorithm (bidi). http://unicode.org/reports/tr9/ - """ - -import ctypes +__version__ = '0.11' -# Load FriBidi - -_libfribidi = ctypes.CDLL("libfribidi.so") +# Package imports try: - _libfribidi.fribidi_shape() -except AttributeError: - libfribidi_version = '0.10' - libfribidi_version_major = 0 - libfribidi_version_minor = 10 -else: - libfribidi_version = '0.19' - libfribidi_version_major = 0 - libfribidi_version_minor = 19 - - -# Versions - -VERSION = '0.10' -"Version of the python wrapper." - - -# Memory allocation functions - -def _malloc_int_array(n): - - """ - Return a pointer to allocated C int array of length `n'. - """ - - t = ctypes.c_int * n - return t() - - -def _malloc_int8_array(n): - - """ - Return a pointer to allocated C int array of length `n'. - """ - - t = ctypes.c_int8 * n - return t() - - -def _malloc_int32_array(n): - - """ - Return a pointer to allocated C int32 array of length `n'. - """ - - t = ctypes.c_uint32 * n - return t() - - -def _malloc_int32_array_from_list(a, n=None): - - """ - Return a pointer to allocated C int32 array of length `n', initialized with `a' - - If `n' is not set, the length of `a' will be considered. - """ - - if n is None: - n = len(a) - - # Memory allocations + import _malloc + from _type import Mask, _Type, CharType, ParType +except ImportError: + from . import _malloc + from ._type import Mask, _Type, CharType, ParType - m = _malloc_int32_array(n) - for i in xrange(n): - m[i] = a[i] +# Python version - return m +import types +try: + # Python 2.x + UnicodeType = types.UnicodeType +except AttributeError: + # Python 3.0 + StringTypes = str -def _malloc_char_array(n): - """ - Return a pointer to allocated UTF8 (C char) array of length `n'. - """ +# Load FriBidi - t = ctypes.c_char * n - return t() +import ctypes +class VersionError(Exception): + pass -def _malloc_char_array_from_string(s): +_libfribidi = ctypes.CDLL("libfribidi.so") +_libfribidi._orig_getitem = _libfribidi.__getitem__ +def _libfribidi_new_getitem(name): + try: + return _libfribidi._orig_getitem(name) + except AttributeError: + raise VersionError +_libfribidi.__getitem__ = _libfribidi_new_getitem - """ - Return a pointer to allocated UTF8 (C char) array, initialized with `s'. - """ - return ctypes.c_char_p(s) +# TODO: better version detection +try: + _libfribidi.fribidi_shape() +except VersionError: + libfribidi_version = '0.10' +else: + libfribidi_version = '0.19' +libfribidi_version_info = [int(x) for x in libfribidi_version.split('.')] # Unicode type convertors @@ -120,9 +75,9 @@ def _pyunicode_to_utf32_p(a_pyunicode): utf8_pystr = a_pyunicode.encode('UTF-8') utf8_len = len(utf8_pystr) - utf8_p = _malloc_char_array_from_string(utf8_pystr) + utf8_p = _malloc.char_array_from_string(utf8_pystr) - utf32_p = _malloc_int32_array(a_len+1) + utf32_p = _malloc.int32_array(a_len+1) _libfribidi.fribidi_utf8_to_unicode(utf8_p, utf8_len, utf32_p) return utf32_p @@ -135,227 +90,13 @@ def _utf32_p_to_pyunicode(a_utf32_p): utf32_len = ctypes.sizeof(a_utf32_p) / ctypes.sizeof(ctypes.c_uint32) utf8_len = 6*utf32_len+1 - utf8_p = _malloc_char_array(utf8_len) + utf8_p = _malloc.char_array(utf8_len) _libfribidi.fribidi_unicode_to_utf8(a_utf32_p, utf32_len, utf8_p) return utf8_p.value.decode('UTF-8') -# ######################################################################## -# FriBidi API, Bidi, Types (fribidi-bidi-types.h) - -# Character and Paragraph Masks and Types - -class Mask: - """ - TODO. - """ - - # Mask values - - RTL = 0x00000001 # Is right to left - ARABIC = 0x00000002 # Is arabic - - # Each character can be only one of the three following: - STRONG = 0x00000010 # Is strong - WEAK = 0x00000020 # Is weak - NEUTRAL = 0x00000040 # Is neutral - SENTINEL = 0x00000080 # Is sentinel - # Sentinels are not valid chars, just identify the start/end of strings. - - # Each charcter can be only one of the five following: - LETTER = 0x00000100 # Is letter: L, R, AL - NUMBER = 0x00000200 # Is number: EN, AN - NUMSEPTER = 0x00000400 # Is number separator or terminator: ES, ET, CS - SPACE = 0x00000800 # Is space: BN, BS, SS, WS - EXPLICIT = 0x00001000 # Is expilict mark: LRE, RLE, LRO, RLO, PDF - - # Can be set only if Mask.SPACE is also set. - SEPARATOR = 0x00002000 # Is test separator: BS, SS - - OVERRIDE = 0x00004000 # Is explicit override: LRO, RLO - - # The following must be to make types pairwise different, some of them can - # be removed but are here because of efficiency (make queries faster). - ES = 0x00010000 - ET = 0x00020000 - CS = 0x00040000 - - NSM = 0x00080000 - BN = 0x00100000 - - BS = 0x00200000 - SS = 0x00400000 - WS = 0x00800000 - - # We reserve a single bit for user's private use: we will never use it. - PRIVATE = 0x01000000 - - -class _Type: - """ - TODO. - """ - - # Strong types - - LTR = Mask.STRONG + Mask.LETTER # Left-To-Right letter - RTL = Mask.STRONG + Mask.LETTER + Mask.RTL # Right-To-Left letter - AL = Mask.STRONG + Mask.LETTER + Mask.RTL + Mask.ARABIC # Arabic Letter - LRE = Mask.STRONG + Mask.EXPLICIT # Left-to-Right Embedding - RLE = Mask.STRONG + Mask.EXPLICIT + Mask.RTL # Right-to-Left Embedding - LRO = Mask.STRONG + Mask.EXPLICIT + Mask.OVERRIDE # Left-to-Right Override - RLO = Mask.STRONG + Mask.EXPLICIT + Mask.RTL + Mask.OVERRIDE # Right-to-Left Override - - # Weak types - - PDF = Mask.WEAK + Mask.EXPLICIT # Pop Directional Override - EN = Mask.WEAK + Mask.NUMBER # European Numeral - AN = Mask.WEAK + Mask.NUMBER + Mask.ARABIC # Arabic Numeral - ES = Mask.WEAK + Mask.NUMSEPTER + Mask.ES # European number Separator - ET = Mask.WEAK + Mask.NUMSEPTER + Mask.ET # European number Terminator - CS = Mask.WEAK + Mask.NUMSEPTER + Mask.CS # Common Separator - NSM = Mask.WEAK + Mask.NSM # Non Spacing Mark - BN = Mask.WEAK + Mask.SPACE + Mask.BN # Boundary Neutral - - # Neutral types - - BS = Mask.NEUTRAL + Mask.SPACE + Mask.SEPARATOR + Mask.BS # Block Separator - SS = Mask.NEUTRAL + Mask.SPACE + Mask.SEPARATOR + Mask.SS # Segment Separator - WS = Mask.NEUTRAL + Mask.SPACE + Mask.WS # WhiteSpace - ON = Mask.NEUTRAL # Other Neutral - - # Paragraph-only types - - WLTR = Mask.WEAK # Weak Left-To-Right - WRTL = Mask.WEAK | Mask.RTL # Weak Right-To-Left - - SENTINEL = Mask.SENTINEL # start or end of text (run list) SENTINEL - # Only used internally - - PRIVATE = Mask.PRIVATE # Private types for applications - # More private types can be obtained by summing up from this one - - -class CharType: - """ - Class of character (direction) types. - - Strong types: - - LTR Left-To-Right letter - RTL Right-To-Left letter - AL Arabic Letter - LRE Left-to-Right Embedding - RLE Right-to-Left Embedding - LRO Left-to-Right Override - RLO Right-to-Left Override - - Weak types: - - PDF Pop Directional Override - EN European Numeral - AN Arabic Numeral - ES European number Separator - ET European number Terminator - CS Common Separator - NSM Non Spacing Mark - BN Boundary Neutral - - Neutral types: - - BS Block Separator - SS Segment Separator - WS WhiteSpace - ON Other Neutral - - """ - - LTR = _Type.LTR - RTL = _Type.RTL - AL = _Type.AL - EN = _Type.EN - AN = _Type.AN - ES = _Type.ES - ET = _Type.ET - CS = _Type.CS - NSM = _Type.NSM - BN = _Type.BN - BS = _Type.BS - SS = _Type.SS - WS = _Type.WS - ON = _Type.ON - LRE = _Type.LRE - RLE = _Type.RLE - LRO = _Type.LRO - RLO = _Type.RLO - PDF = _Type.PDF - - -class ParType: - - """ - Class of paragraph (direction) types: - - LTR Left-to-Right paragraph - RTL Right-to-Left paragraph - ON (Other) Neutral paragraph - WLTR Weak Left-to-Right paragraph - WRTL Weak Right-to-Left paragraph - - """ - - LTR = _Type.LTR - RTL = _Type.RTL - ON = _Type.ON - WLTR = _Type.WLTR - WRTL = _Type.WRTL - - -def level_is_rtl(lev): - - """ - Return True if `lev' is a Right-to-Left level, False otherwise. - - """ - - return lev & 1 - - -def level_to_dir(lev): - - """ - Return the bidi type corresponding to the direction of the level number. - - Return ParType.LTR for evens, and ParType.RTL for odds. - - """ - - return ParType.RTL if level_is_rtl(lev) else ParType.LTR - - -def dir_is_rtl(dir): - - """ - Return True if `dir' is a Right-to-Left, False otherwise. - - """ - - return dir & Mask.RTL - - -def dir_to_level(dir): - - """ - Return the minimum level of the direction. - - Return 0 for LTR and 1 for RTL. - - """ - - return 1 if dir_is_rtl(dir) else 0 - # TODO: More dir functions (probabely should put into Type class) # fribidi-bidi-types.h: 283-334 @@ -363,7 +104,6 @@ def dir_to_level(dir): # Functions def get_bidi_types(unicode_text, text_length=None): - """ Return characters bidi types. @@ -373,9 +113,8 @@ def get_bidi_types(unicode_text, text_length=None): http://www.unicode.org/reports/tr9/#Bidirectional_Character_Types, using data provided in file UnicodeData.txt of the Unicode Character Database available at http://www.unicode.org/Public/UNIDATA/UnicodeData.txt . - """ - # TOD: There are a few macros defined in fribidi-bidi-types.h for querying a bidi type. + # TODO: There are a few macros defined in fribidi-bidi-types.h for querying a bidi type. if not isinstance(unicode_text, unicode): @@ -388,10 +127,9 @@ def get_bidi_types(unicode_text, text_length=None): input_utf32_p = _pyunicode_to_utf32_p(unicode_text) - output_chartype_p = _malloc_int32_array(text_length) + output_chartype_p = _malloc.int32_array(text_length) # Calling the API - """ FRIBIDI_ENTRY void fribidi_get_bidi_types ( const FriBidiChar *str, /* input string */ @@ -400,7 +138,7 @@ def get_bidi_types(unicode_text, text_length=None): ); """ - if libfribidi_version_minor <= 10: + if libfribidi_version <= 10: _libfribidi.fribidi_get_types( input_utf32_p, # input string text_length, # input string length @@ -427,7 +165,6 @@ def get_bidi_types(unicode_text, text_length=None): def get_par_direction(bidi_types_list, text_length=None): - """ Return base paragraph direction @@ -448,7 +185,6 @@ def get_par_direction(bidi_types_list, text_length=None): good heuristic to set direction of the neutral paragraphs at the beginning of text. For other neutral paragraphs, you better use the direction of the previous paragraph. - """ if not text_length: @@ -456,7 +192,7 @@ def get_par_direction(bidi_types_list, text_length=None): # Memory allocations - input_bidi_types_p = _malloc_int32_array_from_list(bidi_types_list, text_length) + input_bidi_types_p = _malloc.int32_array_from_list(bidi_types_list, text_length) # Calling the API @@ -479,7 +215,6 @@ def get_par_direction(bidi_types_list, text_length=None): def get_par_embedding_levels(bidi_types_list, text_length=None, base_direction=None): - """ Return the list of embedding levels of characters in the paragraph. @@ -494,7 +229,6 @@ def get_par_embedding_levels(bidi_types_list, text_length=None, I1 inclusive, and parts 1 to 3 of L1, except for rule X9 which is implemented in remove_bidi_marks(). Part 4 of L1 is implemented in reorder_line(). - """ # TODO: There are a few macros defined in fribidi-bidi-types.h to work with this embedding levels. @@ -507,13 +241,12 @@ def get_par_embedding_levels(bidi_types_list, text_length=None, # Memory allocations - input_bidi_types_p = _malloc_int32_array_from_list(bidi_types_list, text_length) + input_bidi_types_p = _malloc.int32_array_from_list(bidi_types_list, text_length) pbase_dir_p = ctypes.pointer(ctypes.c_int32(base_direction)) - emb_p = _malloc_int8_array(text_length) + emb_p = _malloc.int8_array(text_length) # Calling the API - """ FRIBIDI_ENTRY FriBidiLevel fribidi_get_par_embedding_levels ( const FriBidiCharType *bidi_types, /* input list of bidi types as returned by fribidi_get_bidi_types() */ @@ -544,13 +277,11 @@ def get_par_embedding_levels(bidi_types_list, text_length=None, def reorder_line(bidi_types_list, text_length=None, line_offset=0, base_direction=None, with_max_levels=False): - """ Return visual reordered of a line of logical string """ # TODO - """ This function reorders the characters in a line of text from logical to final visual order. This function implements part 4 of rule L1, and rules @@ -579,7 +310,6 @@ def reorder_line(bidi_types_list, text_length=None, line_offset=0, Returns: Maximum level found in this line plus one, or zero if any error occured (memory allocation failure most probably). - """ if not text_length: @@ -590,13 +320,12 @@ def reorder_line(bidi_types_list, text_length=None, line_offset=0, # Memory allocations - input_bidi_types_p = _malloc_int32_array_from_list(bidi_types_list, text_length) + input_bidi_types_p = _malloc.int32_array_from_list(bidi_types_list, text_length) pbase_dir_p = ctypes.pointer(ctypes.c_int32(base_direction)) - emb_p = _malloc_int8_array(text_length) + emb_p = _malloc.int8_array(text_length) # Calling the API - """ FRIBIDI_ENTRY FriBidiLevel fribidi_reorder_line ( FriBidiFlags flags, /* reorder flags */ @@ -652,7 +381,6 @@ def log2vis(unicode_text, text_length=None, base_direction=None, are True, the return value will be a tuple including logical-to-visual position, visual-to-logical positions, or embedding-level lists respectively. - """ if not isinstance(unicode_text, unicode): @@ -670,14 +398,13 @@ def log2vis(unicode_text, text_length=None, base_direction=None, input_utf32_p = _pyunicode_to_utf32_p(unicode_text) pbase_dir_p = ctypes.pointer(ctypes.c_int32(base_direction)) - output_utf32_p = _malloc_int32_array(text_length+1) + output_utf32_p = _malloc.int32_array(text_length+1) - l2v_p = _malloc_int_array(text_length) if with_l2v_position else None - v2l_p = _malloc_int_array(text_length) if with_v2l_position else None - emb_p = _malloc_int8_array(text_length) if with_embedding_level else None + l2v_p = _malloc.int_array(text_length) if with_l2v_position else None + v2l_p = _malloc.int_array(text_length) if with_v2l_position else None + emb_p = _malloc.int8_array(text_length) if with_embedding_level else None # Calling the API - """ FRIBIDI_API fribidi_boolean fribidi_log2vis ( @@ -727,10 +454,8 @@ def log2vis(unicode_text, text_length=None, base_direction=None, def log2vis_get_embedding_levels(unicode_text, base_direction=None): - """ Return an array containing the embedding-level of characters in the text. - """ if not isinstance(unicode_text, unicode): @@ -746,10 +471,9 @@ def log2vis_get_embedding_levels(unicode_text, base_direction=None): input_utf32_p = _pyunicode_to_utf32_p(unicode_text) pbase_dir_p = ctypes.pointer(ctypes.c_int32(base_direction)) - emb_p = _malloc_int8_array(text_len) + emb_p = _malloc.int8_array(text_len) # Calling the API - """ FRIBIDI_API fribidi_boolean fribidi_log2vis_get_embedding_levels ( @@ -786,7 +510,6 @@ def log2vis_get_embedding_levels(unicode_text, base_direction=None): def remove_bidi_marks(unicode_text, text_length=None, with_position_to=False, with_position_from=False, with_embedding_level=False): - """ Return the text with all Bidirectional Marks removed. @@ -797,7 +520,6 @@ def remove_bidi_marks(unicode_text, text_length=None, Note: Seems the optional parameters of fribidi_remove_bidi_marks() doesn't work or crash. Use them at your own risk. - """ if not isinstance(unicode_text, unicode): @@ -810,12 +532,11 @@ def remove_bidi_marks(unicode_text, text_length=None, input_utf32_p = _pyunicode_to_utf32_p(unicode_text) - pto_p = _malloc_int_array(text_length) if with_position_to else None - pfr_p = _malloc_int_array(text_length) if with_position_from else None - emb_p = _malloc_int8_array(text_length) if with_embedding_level else None + pto_p = _malloc.int_array(text_length) if with_position_to else None + pfr_p = _malloc.int_array(text_length) if with_position_from else None + emb_p = _malloc.int8_array(text_length) if with_embedding_level else None # Calling the API - """ FRIBIDI_API FriBidiStrIndex fribidi_remove_bidi_marks ( @@ -863,7 +584,6 @@ def remove_bidi_marks(unicode_text, text_length=None, def get_mirror_chars(unicode_text): - """ Return TODO @@ -872,13 +592,12 @@ def get_mirror_chars(unicode_text): * fribidi_get_mirror_char() returns the mirrored character, if input * character has a mirror, or the input itself. * if mirrored_ch is NULL, just returns if character has a mirror or not. - """ if not isinstance(unicode_text, unicode): unicode_text = unicode(unicode_text) - res = u'' + res = UnicodeType() for unicode_char in unicode_text: text_length = len(unicode_text) @@ -887,7 +606,7 @@ def get_mirror_chars(unicode_text): input_utf32_p = _pyunicode_to_utf32_p(unicode_char) - output_utf32_p = _malloc_int32_array(text_length+1) + output_utf32_p = _malloc.int32_array(text_length+1) # Calling the API @@ -917,7 +636,6 @@ def get_mirror_chars(unicode_text): def get_mirror_prop(unicode_text): - """ Return TODO @@ -926,7 +644,6 @@ def get_mirror_prop(unicode_text): * fribidi_get_mirror_char() returns the mirrored character, if input * character has a mirror, or the input itself. * if mirrored_ch is NULL, just returns if character has a mirror or not. - """ if not isinstance(unicode_text, unicode): @@ -968,12 +685,10 @@ def get_mirror_prop(unicode_text): def get_version_info(): - """ Return TODO TODO. - """ # TODO @@ -984,15 +699,13 @@ def get_version_info(): # Main def _main(): - """ Print visual representation of command-line parameters (as a whole). - """ import sys text = ' '.join(sys.argv[1:]).decode('UTF-8') - print log2vis(text) + print(log2vis(text)) if __name__=='__main__': diff --git a/test/fribidi b/test/fribidi new file mode 120000 index 0000000..0e5cdd8 --- /dev/null +++ b/test/fribidi @@ -0,0 +1 @@ +../fribidi
\ No newline at end of file diff --git a/test/fribidi.py b/test/fribidi.py deleted file mode 120000 index b2f56ab..0000000 --- a/test/fribidi.py +++ /dev/null @@ -1 +0,0 @@ -../fribidi.py
\ No newline at end of file diff --git a/test/test1.py b/test/test1.py index aa5feef..e5106a9 100755 --- a/test/test1.py +++ b/test/test1.py @@ -2,116 +2,113 @@ # coding=UTF-8 -from fribidi import * +from fribidi.fribidi import * -def _main(): +print +print 'libfribidi version:', libfribidi_version +print - print 'libfribidi version:', libfribidi_version, libfribidi_version_major, libfribidi_version_minor - print +# Bidi API - # Bidi API +print +print 'TEST get_bidi_types()' +print - print - print 'TEST get_bidi_types()' - print +print get_bidi_types(123) +print get_bidi_types(u"سلام") +print get_bidi_types(u"سلام").__class__ +print - print get_bidi_types(123) - print get_bidi_types(u"سلام") - print get_bidi_types(u"سلام").__class__ - print +print +print 'TEST get_par_direction()' +print - print - print 'TEST get_par_direction()' - print +print get_par_direction(get_bidi_types(123)) +print get_par_direction(get_bidi_types(u"سلام")) +print get_par_direction(get_bidi_types(u"سلام")).__class__ +print - print get_par_direction(get_bidi_types(123)) - print get_par_direction(get_bidi_types(u"سلام")) - print get_par_direction(get_bidi_types(u"سلام")).__class__ - print +print +print 'TEST get_par_embedding_levels()' +print - print - print 'TEST get_par_embedding_levels()' - print +print get_par_embedding_levels(get_bidi_types(123)) +print get_par_embedding_levels(get_bidi_types(u"سلام")) +print get_par_embedding_levels(get_bidi_types(u"سلام")).__class__ +print - print get_par_embedding_levels(get_bidi_types(123)) - print get_par_embedding_levels(get_bidi_types(u"سلام")) - print get_par_embedding_levels(get_bidi_types(u"سلام")).__class__ - print +print get_par_embedding_levels(get_bidi_types("abc"), None, ParType.LTR) +print get_par_embedding_levels(get_bidi_types(u"aسلام"), None, ParType.LTR) +print get_par_embedding_levels(get_bidi_types(u"aسلام"), None, ParType.RTL) - print get_par_embedding_levels(get_bidi_types("abc"), None, ParType.LTR) - print get_par_embedding_levels(get_bidi_types(u"aسلام"), None, ParType.LTR) - print get_par_embedding_levels(get_bidi_types(u"aسلام"), None, ParType.RTL) +''' +print +print 'TEST remove_bidi_marks()' +print - ''' - print - print 'TEST remove_bidi_marks()' - print +print remove_bidi_marks(123) +print remove_bidi_marks(u"سلام") +print remove_bidi_marks(u"سلام").__class__ +print - print remove_bidi_marks(123) - print remove_bidi_marks(u"سلام") - print remove_bidi_marks(u"سلام").__class__ - print +print remove_bidi_marks(u"سلامa") +#print remove_bidi_marks(u"سلامa", None, False, True) +#print remove_bidi_marks(u"سلامa", None, False, False, True) +#print remove_bidi_marks(u"سلامa", None, True) - print remove_bidi_marks(u"سلامa") - #print remove_bidi_marks(u"سلامa", None, False, True) - #print remove_bidi_marks(u"سلامa", None, False, False, True) - #print remove_bidi_marks(u"سلامa", None, True) +print remove_bidi_marks(u"سلام") +#print remove_bidi_marks(u"سلام", None, True) +#print remove_bidi_marks(u"سلام", None, False, True) +#print remove_bidi_marks(u"سلام", None, False, False, True) - print remove_bidi_marks(u"سلام") - #print remove_bidi_marks(u"سلام", None, True) - #print remove_bidi_marks(u"سلام", None, False, True) - #print remove_bidi_marks(u"سلام", None, False, False, True) +print +print 'TEST get_mirror_chars()' +print - print - print 'TEST get_mirror_chars()' - print +print get_mirror_chars(123) +print get_mirror_chars(u"سلام") +print get_mirror_chars(u"سلام").__class__ +print - print get_mirror_chars(123) - print get_mirror_chars(u"سلام") - print get_mirror_chars(u"سلام").__class__ - print +a="()"; print a, get_mirror_chars(a) +a=u"«»"; print a, get_mirror_chars(a) +a=u"﴾﴿"; print a, get_mirror_chars(a) - a="()"; print a, get_mirror_chars(a) - a=u"«»"; print a, get_mirror_chars(a) - a=u"﴾﴿"; print a, get_mirror_chars(a) +print +print 'TEST get_mirror_prop()' +print - print - print 'TEST get_mirror_prop()' - print +print get_mirror_prop(123) +print get_mirror_prop(u"سلام") +print get_mirror_prop(u"سلام").__class__ +print - print get_mirror_prop(123) - print get_mirror_prop(u"سلام") - print get_mirror_prop(u"سلام").__class__ - print +print u"() «» ﴾﴿", get_mirror_prop(u"() «» ﴾﴿") - print u"() «» ﴾﴿", get_mirror_prop(u"() «» ﴾﴿") +print +print 'TEST get_version_info()' +print - print - print 'TEST get_version_info()' - print +print get_version_info() - print get_version_info() +print 'TEST log2vis()' +print - print 'TEST log2vis()' - print +print log2vis(123) +print log2vis(u"سلام") +print log2vis(u"سلام").__class__ +print - print log2vis(123) - print log2vis(u"سلام") - print log2vis(u"سلام").__class__ - print +print log2vis(u"سلام", None, None, True) +print log2vis(u"سلام", None, None, False, True) +print log2vis(u"سلام", None, None, False, False, True) - print log2vis(u"سلام", None, None, True) - print log2vis(u"سلام", None, None, False, True) - print log2vis(u"سلام", None, None, False, False, True) +print log2vis(u"1سلام", None, ParType.LTR, True, True, True) +print log2vis(u"1سلام", None, ParType.RTL, True, True, True) - print log2vis(u"1سلام", None, ParType.LTR, True, True, True) - print log2vis(u"1سلام", None, ParType.RTL, True, True, True) - - print log2vis(u"aسلام", None, ParType.LTR, True, True, True) - print log2vis(u"aسلام", None, ParType.RTL, True, True, True) - ''' - -if __name__ == '__main__': - _main() +print log2vis(u"aسلام", None, ParType.LTR, True, True, True) +print log2vis(u"aسلام", None, ParType.RTL, True, True, True) +''' +# vim:set encoding=utf-8: diff --git a/test/test2.py b/test/test2.py index a6bb6e1..4ed2b69 100755 --- a/test/test2.py +++ b/test/test2.py @@ -2,29 +2,30 @@ # coding=UTF-8 -from fribidi import * +from fribidi.fribidi import * s = u'سلام ABC' -print 'ORIG\t%s' % s -print 'LTR\t%s' % log2vis(s, None, ParType.LTR) -print 'RTL\t%s' % log2vis(s, None, ParType.RTL) +print u'ORIG\t%s' % s +print u'LTR\t%s' % log2vis(s, None, ParType.LTR) +print u'RTL\t%s' % log2vis(s, None, ParType.RTL) s = u'46/12/2008' -print 'ORIG\t%s' % s -print 'LTR\t%s' % log2vis(s, None, ParType.LTR) -print 'RTL\t%s' % log2vis(s, None, ParType.RTL) +print u'ORIG\t%s' % s +print u'LTR\t%s' % log2vis(s, None, ParType.LTR) +print u'RTL\t%s' % log2vis(s, None, ParType.RTL) s = u'٤٦/١٢/٢٠٠٨' -print 'ORIG\t%s' % s -print 'LTR\t%s' % log2vis(s, None, ParType.LTR) -print 'RTL\t%s' % log2vis(s, None, ParType.RTL) +print u'ORIG\t%s' % s +print u'LTR\t%s' % log2vis(s, None, ParType.LTR) +print u'RTL\t%s' % log2vis(s, None, ParType.RTL) s = u'۴۶/۱۲/۲۰۰۸' -print 'ORIG\t%s' % s -print 'LTR\t%s' % log2vis(s, None, ParType.LTR) -print 'RTL\t%s' % log2vis(s, None, ParType.RTL) +print u'ORIG\t%s' % s +print u'LTR\t%s' % log2vis(s, None, ParType.LTR) +print u'RTL\t%s' % log2vis(s, None, ParType.RTL) +# vim:set encoding=utf-8: |