Skip to content

Commit c3c27eb

Browse files
ravarageRavyarSarbastmpcabd
authored
Kurdish support and second way of arabic to support extra fonts (#39)
* Update arabic_reshaper.py * Update letters.py * Update default-config.ini * Update default-config.ini * Update arabic_reshaper/arabic_reshaper.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/arabic_reshaper.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/arabic_reshaper.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/arabic_reshaper.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/arabic_reshaper.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/default-config.ini Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/letters.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/letters.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/letters.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/letters.py Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/default-config.ini Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/default-config.ini Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper/default-config.ini Co-Authored-By: Abdullah Diab <[email protected]> * Update arabic_reshaper.py fix letters and used self.letters and send self.letters to letters to open proper letter format * Update letters.py add letters to accept self.letters * Update test_002_reshaping.py Fixed unit tests * Add files via upload * Update test_002_reshaping.py Co-authored-by: Ravyar Tahir <[email protected]> Co-authored-by: Abdullah Diab <[email protected]>
1 parent 19e9945 commit c3c27eb

File tree

5 files changed

+433
-59
lines changed

5 files changed

+433
-59
lines changed

arabic_reshaper/arabic_reshaper.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# Now you can pass `bidi_text` to any function that handles
2222
# displaying/printing of the text, like writing it to PIL Image or passing it
2323
# to a PDF generating method.
24-
2524
from __future__ import unicode_literals
2625

2726
import re
@@ -32,11 +31,11 @@
3231
from pkg_resources import resource_filename
3332

3433
from .ligatures import LIGATURES
35-
from .letters import (UNSHAPED, ISOLATED, TATWEEL, ZWJ, LETTERS, FINAL,
34+
from .letters import (UNSHAPED, ISOLATED, TATWEEL, ZWJ, LETTERS_ARABIC,
35+
LETTERS_ARABIC_V2, LETTERS_KURDISH, FINAL,
3636
INITIAL, MEDIAL, connects_with_letters_before_and_after,
3737
connects_with_letter_before, connects_with_letter_after)
3838

39-
4039
HARAKAT_RE = re.compile(
4140
'['
4241
'\u0610-\u061a'
@@ -129,6 +128,17 @@ def __init__(self, configuration=None, configuration_file=None):
129128

130129
configuration = configuration_parser['ArabicReshaper']
131130
self.configuration = configuration
131+
self.language = self.configuration.get('language')
132+
133+
134+
if self.language == 'ArabicV2':
135+
self.letters = LETTERS_ARABIC_V2
136+
elif self.language == 'Kurdish':
137+
self.letters = LETTERS_KURDISH
138+
else:
139+
self.letters = LETTERS_ARABIC
140+
141+
132142

133143
@property
134144
def _ligatures_re(self):
@@ -197,23 +207,22 @@ def reshape(self, text):
197207
pass
198208
elif letter == ZWJ and not support_zwj:
199209
pass
200-
elif letter not in LETTERS:
210+
elif letter not in self.letters:
201211
output.append((letter, NOT_SUPPORTED))
202212
elif not output: # first letter
203213
output.append((letter, isolated_form))
204214
else:
205215
previous_letter = output[-1]
206216
if previous_letter[FORM] == NOT_SUPPORTED:
207217
output.append((letter, isolated_form))
208-
elif not connects_with_letter_before(letter):
218+
elif not connects_with_letter_before(letter,self.letters):
209219
output.append((letter, isolated_form))
210220
elif not connects_with_letter_after(
211-
previous_letter[LETTER]
212-
):
221+
previous_letter[LETTER],self.letters):
213222
output.append((letter, isolated_form))
214223
elif (previous_letter[FORM] == FINAL and not
215224
connects_with_letters_before_and_after(
216-
previous_letter[LETTER]
225+
previous_letter[LETTER],self.letters
217226
)):
218227
output.append((letter, isolated_form))
219228
elif previous_letter[FORM] == isolated_form:
@@ -290,7 +299,7 @@ def reshape(self, text):
290299
if o[FORM] == NOT_SUPPORTED or o[FORM] == UNSHAPED:
291300
result.append(o[LETTER])
292301
else:
293-
result.append(LETTERS[o[LETTER]][o[FORM]])
302+
result.append(self.letters[o[LETTER]][o[FORM]])
294303

295304
if not delete_harakat:
296305
if i in positions_harakat:

arabic_reshaper/default-config.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[ArabicReshaper]
2-
# Supported languages are: [Arabic]
2+
# Supported languages are: [Arabic, ArabicV2, Kurdish]
33
# More languages might be supported soon.
4+
# `Arabic` is default and recommended to work in most of the cases and supports (Arabic, Urdu and Farsi)
5+
# `ArabicV2` is only to be used with certain font that you run into missing chars
6+
# `Kurdish` if you are using Kurdish Sarchia font is recommended, work with both unicode and classic Arabic-Kurdish keybouard
47
language = Arabic
58

69
# Whether to delete the Harakat (Tashkeel) before reshaping or not.

0 commit comments

Comments
 (0)