|
125 | 125 | [u'\u066E', u'\uFBE4', u'\uFBE8', u'\uFBE9', u'\uFBE5', 4], |
126 | 126 | [u'\u06AA', u'\uFB8E', u'\uFB90', u'\uFB91', u'\uFB8F', 4], |
127 | 127 | [u'\u06C1', u'\uFBA6', u'\uFBA8', u'\uFBA9', u'\uFBA7', 4], |
128 | | - [u'\u06E4', u'\u06E4', u'\u06E4', u'\u06E4', u'\uFEEE', 2] |
129 | 128 | ] |
130 | 129 |
|
131 | 130 | def get_reshaped_glyph(target, location): |
@@ -223,18 +222,29 @@ def get_reshaped_word(unshaped_word): |
223 | 222 | return decomposed_word.reconstruct_word(result) |
224 | 223 |
|
225 | 224 | def reshape_it(unshaped_word): |
226 | | - reshaped_word = [get_reshaped_glyph(unshaped_word[0], 2)] |
227 | | - for i in range(1, len(unshaped_word) - 1): |
228 | | - if get_glyph_type(unshaped_word[i - 1]) == 2: |
229 | | - reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 2)) |
| 225 | + if not unshaped_word: |
| 226 | + return u'' |
| 227 | + if len(unshaped_word) == 1: |
| 228 | + return get_reshaped_glyph(unshaped_word[0], 1) |
| 229 | + reshaped_word = [] |
| 230 | + for i in range(len(unshaped_word)): |
| 231 | + before = False |
| 232 | + after = False |
| 233 | + if i == 0: |
| 234 | + after = get_glyph_type(unshaped_word[i]) == 4 |
| 235 | + elif i == len(unshaped_word) - 1: |
| 236 | + before = get_glyph_type(unshaped_word[i - 1]) == 4 |
230 | 237 | else: |
| 238 | + after = get_glyph_type(unshaped_word[i]) == 4 |
| 239 | + before = get_glyph_type(unshaped_word[i - 1]) == 4 |
| 240 | + if after and before: |
231 | 241 | reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 3)) |
232 | | - |
233 | | - if len(unshaped_word) >= 2: |
234 | | - if get_glyph_type(unshaped_word[-2]) == 2: |
235 | | - reshaped_word.append(get_reshaped_glyph(unshaped_word[-1], 1)) |
236 | | - else: |
237 | | - reshaped_word.append(get_reshaped_glyph(unshaped_word[-1], 4)) |
| 242 | + elif after and not before: |
| 243 | + reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 2)) |
| 244 | + elif not after and before: |
| 245 | + reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 4)) |
| 246 | + elif not after and not before: |
| 247 | + reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 1)) |
238 | 248 |
|
239 | 249 | return u''.join(reshaped_word) |
240 | 250 |
|
|
0 commit comments