mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-11-25 09:26:21 -05:00
Fixed composite unicode characters breaking text alignment rendering
This commit is contained in:
parent
3e7e55a9ca
commit
5ceb0c671e
5 changed files with 42 additions and 9 deletions
30
nomadnet/util.py
Normal file
30
nomadnet/util.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import re
|
||||
import unicodedata
|
||||
import RNS
|
||||
|
||||
def strip_modifiers(text):
|
||||
def process_characters(text):
|
||||
result = []
|
||||
i = 0
|
||||
while i < len(text):
|
||||
char = text[i]
|
||||
category = unicodedata.category(char)
|
||||
|
||||
if category.startswith(('L', 'N', 'P', 'S')):
|
||||
result.append(char)
|
||||
i += 1
|
||||
elif category.startswith(('M', 'Sk', 'Cf')) or char in '\u200d\u200c':
|
||||
i += 1
|
||||
else:
|
||||
result.append(char)
|
||||
i += 1
|
||||
|
||||
return ''.join(result)
|
||||
|
||||
stripped = process_characters(text)
|
||||
stripped = re.sub(r'[\uFE00-\uFE0F]', '', stripped)
|
||||
stripped = re.sub(r'[\U000E0100-\U000E01EF]', '', stripped, flags=re.UNICODE)
|
||||
stripped = re.sub(r'[\U0001F3FB-\U0001F3FF]', '', stripped, flags=re.UNICODE)
|
||||
stripped = re.sub(r'[\u200D\u200C]', '', stripped)
|
||||
|
||||
return stripped
|
||||
Loading…
Add table
Add a link
Reference in a new issue