Skip to content

Commit 58f48e4

Browse files
committed
new displaylength method using unicodedata
1 parent 98d0bf5 commit 58f48e4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ASFMKV_dev.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from fontTools import ttLib, subset
1212
from chardet.universaldetector import UniversalDetector
1313
from chardet import detect
14-
import os, sys, re, winreg, zlib, json, copy, traceback, shutil, configparser, time, locale, codecs, argparse
14+
import os, sys, re, winreg, zlib, json, copy, traceback, shutil, configparser, time, locale, codecs, argparse, unicodedata
1515
from os import path
1616
from colorama import init
1717
from datetime import datetime
@@ -1135,13 +1135,12 @@ def fnReadCorrect(ttfont: ttLib.ttFont, index: int, fontpath: str):
11351135
return namestr, c
11361136

11371137

1138-
11391138
def outputSameLength(s: str) -> str:
11401139
length = 0
11411140
output = ''
11421141
for i in range(len(s) - 1, -1, -1):
11431142
si = s[i]
1144-
if 65281 <= ord(si) <= 65374 or ord(si) == 12288 or ord(si) not in range(33, 127):
1143+
if unicodedata.east_asian_width(si) in ['F', 'W', 'A']:
11451144
length += 2
11461145
else:
11471146
length += 1
@@ -1150,7 +1149,8 @@ def outputSameLength(s: str) -> str:
11501149
break
11511150
else:
11521151
output = si + output
1153-
return output + ''.join([' ' for _ in range(0, 60 - length)])
1152+
return output.ljust(60 - (length - len(output)), ' ')
1153+
# + ''.join([' ' for _ in range(0, 60 - length)])
11541154

11551155

11561156
# 当前字体缓存版本,小于该版本的字体缓存会被删除重建

0 commit comments

Comments
 (0)