Skip to content

Commit a7736c6

Browse files
committed
New option use_unshaped_instead_of_isolated
1 parent 2b4465e commit a7736c6

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

arabic_reshaper/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.12'
1+
__version__ = '2.0.13'

arabic_reshaper/arabic_reshaper.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,16 @@ def reshape(self, text):
170170
shift_harakat_position = self.configuration.getboolean(
171171
'shift_harakat_position'
172172
)
173+
use_unshaped_instead_of_isolated = self.configuration.getboolean(
174+
'use_unshaped_instead_of_isolated'
175+
)
173176

174177
positions_harakat = {}
175178

179+
isolated_form = (
180+
use_unshaped_instead_of_isolated and UNSHAPED or ISOLATED
181+
)
182+
176183
for letter in text:
177184
if HARAKAT_RE.match(letter):
178185
if not delete_harakat:
@@ -192,23 +199,23 @@ def reshape(self, text):
192199
elif letter not in LETTERS:
193200
output.append((letter, NOT_SUPPORTED))
194201
elif not output: # first letter
195-
output.append((letter, ISOLATED))
202+
output.append((letter, isolated_form))
196203
else:
197204
previous_letter = output[-1]
198205
if previous_letter[FORM] == NOT_SUPPORTED:
199-
output.append((letter, ISOLATED))
206+
output.append((letter, isolated_form))
200207
elif not connects_with_letter_before(letter):
201-
output.append((letter, ISOLATED))
208+
output.append((letter, isolated_form))
202209
elif not connects_with_letter_after(
203210
previous_letter[LETTER]
204211
):
205-
output.append((letter, ISOLATED))
212+
output.append((letter, isolated_form))
206213
elif (previous_letter[FORM] == FINAL and not
207214
connects_with_letters_before_and_after(
208215
previous_letter[LETTER]
209216
)):
210-
output.append((letter, ISOLATED))
211-
elif previous_letter[FORM] == ISOLATED:
217+
output.append((letter, isolated_form))
218+
elif previous_letter[FORM] == isolated_form:
212219
output[-1] = (
213220
previous_letter[LETTER],
214221
INITIAL
@@ -259,13 +266,13 @@ def reshape(self, text):
259266
# | FINAL | FINAL | MEDIAL | MEDIAL | FINAL |
260267
# +-----------+----------+---------+---------+----------+
261268

262-
if a_form in (ISOLATED, INITIAL):
263-
if b_form in (ISOLATED, FINAL):
269+
if a_form in (isolated_form, INITIAL):
270+
if b_form in (isolated_form, FINAL):
264271
ligature_form = ISOLATED
265272
else:
266273
ligature_form = INITIAL
267274
else:
268-
if b_form in (ISOLATED, FINAL):
275+
if b_form in (isolated_form, FINAL):
269276
ligature_form = FINAL
270277
else:
271278
ligature_form = MEDIAL
@@ -279,7 +286,7 @@ def reshape(self, text):
279286
result.extend(positions_harakat[-1])
280287
for i, o in enumerate(output):
281288
if o[LETTER]:
282-
if o[FORM] == NOT_SUPPORTED:
289+
if o[FORM] == NOT_SUPPORTED or o[FORM] == UNSHAPED:
283290
result.append(o[LETTER])
284291
else:
285292
result.append(LETTERS[o[LETTER]][o[FORM]])

arabic_reshaper/default-config.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ delete_tatweel = no
1515
# Whether to support ZWJ (U+200D) or not.
1616
support_zwj = yes
1717

18+
# Use unshaped form instead of isolated form.
19+
use_unshaped_instead_of_isolated = yes
20+
1821
# Whether to use ligatures or not.
1922
# Serves as a shortcut to disable all ligatures.
2023
support_ligatures = yes

arabic_reshaper/letters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from __future__ import unicode_literals
1717

18+
UNSHAPED = 255
1819
ISOLATED = 0
1920
INITIAL = 1
2021
MEDIAL = 2

0 commit comments

Comments
 (0)