| 1 |
#!/usr/bin/python |
| 2 |
from __future__ import print_function |
| 3 |
__license__ = """ |
| 4 |
This file is part of GNU FreeFont. |
| 5 |
|
| 6 |
GNU FreeFont is free software: you can redistribute it and/or modify it under |
| 7 |
the terms of the GNU General Public License as published by the Free Software |
| 8 |
Foundation, either version 3 of the License, or (at your option) any later |
| 9 |
version. |
| 10 |
|
| 11 |
GNU FreeFont is distributed in the hope that it will be useful, but WITHOUT |
| 12 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License along with |
| 16 |
GNU FreeFont. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
""" |
| 18 |
__author__ = "Emmanuel Vallois" |
| 19 |
__email__ = "[email protected]" |
| 20 |
__copyright__ = "Copyright 2011 Emmanuel Vallois" |
| 21 |
__date__ = "$Date: 2018-06-03 22:35:12 +0200 (So, 03. Jun 2018) $" |
| 22 |
__version__ = "$Revision: 3926 $" |
| 23 |
__doc__ = """ |
| 24 |
Generates test script |
| 25 |
arab_shaping.py |
| 26 |
from a file |
| 27 |
ArabicShaping.txt |
| 28 |
which may be obtained from |
| 29 |
http://www.unicode.org/Public/UNIDATA/ArabicShaping.txt |
| 30 |
""" |
| 31 |
|
| 32 |
'''Convert Unicode ArabicShaping.txt to a Python module containing its data.''' |
| 33 |
|
| 34 |
import sys |
| 35 |
|
| 36 |
sys.stdout = open('arabic_shaping.py', 'w') |
| 37 |
|
| 38 |
print('''#!/usr/bin/python |
| 39 |
__license__ = """''' + __license__ + ''' |
| 40 |
""" |
| 41 |
__doc__ = """ |
| 42 |
Module containing UCD ArabicShaping.txt data.""" |
| 43 |
|
| 44 |
from unicodedata import name |
| 45 |
from collections import OrderedDict |
| 46 |
|
| 47 |
class ArabicShaping: |
| 48 |
def __init__(self, code_point, short_name, joining_type, joining_group): |
| 49 |
self.code_point = code_point |
| 50 |
self.short_name = short_name |
| 51 |
self.joining_type = joining_type |
| 52 |
self.joining_group = joining_group |
| 53 |
def __repr__(self): |
| 54 |
return 'ArabicShaping({:X}, {}, {}, {})'.format(self.code_point, self.short_name, self.joining_type, self.joining_group) |
| 55 |
|
| 56 |
arabic_shapings = OrderedDict()''') |
| 57 |
with open('ArabicShaping.txt') as f: |
| 58 |
for line in f: |
| 59 |
if not line.strip() or line[0] == '#': continue |
| 60 |
line = line[:-1] #removes the \n at the end of the line |
| 61 |
fields = line.split('; ') |
| 62 |
print("arabic_shapings[0x{0[0]}] = ArabicShaping(0x{0[0]}, '{0[1]}', '{0[2]}', '{0[3]}')".format(fields)) |
| 63 |
if fields[0] == '08A0': |
| 64 |
print('''arabic_shapings[0x08A1] = ArabicShaping(0x8A1, 'BEH WITH HAMZA ABOVE','D','BEH')''') |
| 65 |
print('''arabic_shapings[0x08AE] = ArabicShaping(0x8AE, 'DAL WITH THREE DOTS BELOW', 'R', 'DAL') |
| 66 |
arabic_shapings[0x08AF] = ArabicShaping(0x8AF, 'SAD WITH THREE DOTS BELOW', 'D', 'SAD') |
| 67 |
arabic_shapings[0x08B0] = ArabicShaping(0x8B0, 'GAF WITH INVERTED STROKE', 'D', 'GAF') |
| 68 |
arabic_shapings[0x08B1] = ArabicShaping(0x8B1, 'STRAIGHT WAW', 'R', 'WAW')''') |
| 69 |
|
| 70 |
print(''' |
| 71 |
def short_name(cp): |
| 72 |
shaping = arabic_shapings.get(cp) |
| 73 |
return shaping and shaping.short_name or name(unichr(cp)) |
| 74 |
|
| 75 |
def joining_type(cp): |
| 76 |
shaping = arabic_shapings.get(cp) |
| 77 |
return shaping and shaping.joining_type or 'U' |
| 78 |
|
| 79 |
def joining_group(cp): |
| 80 |
shaping = arabic_shapings.get(cp) |
| 81 |
return shaping and shaping.joining_group or 'No_Joining_Group\'''') |