-
Notifications
You must be signed in to change notification settings - Fork 10
/
pyfribidi.py
36 lines (30 loc) · 1.29 KB
/
pyfribidi.py
1
2
3
4
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
31
32
33
34
35
36
"""simple Python binding for fribidi.
pyfribidi uses libfribidi to order text visually using the unicode
algorithm. pyfribidi can also convert text from visual order to
logical order, but the conversion may be wrong in certain cases.
"""
__version__ = "0.12.0"
import six
from _pyfribidi import LTR, ON, RTL, log2vis as _log2vis
def log2vis(logical, base_direction=RTL, encoding="utf-8", clean=False, reordernsm=True):
"""
Return string reordered visually according to base direction.
Return the same type of input string, either unicode or string using
encoding.
Note that this function does not handle line breaking. You should
call log2vis with each line.
Arguments:
- logical: unicode or encoded string
- base_direction: optional logical base direction. Accepts one of
the constants LTR, RTL or ON, defined in this module. ON calculate
the base direction according to the BiDi algorithm.
- encoding: optional string encoding (ignored for unicode input)
"""
if not isinstance(logical, six.text_type):
logical = six.text_type(logical, encoding)
else:
encoding = None
res = _log2vis(logical, base_direction=base_direction, clean=clean, reordernsm=reordernsm)
if encoding:
return res.encode(encoding)
return res