mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
perf: markdown perf
This commit is contained in:
@@ -191,11 +191,16 @@ def render_markdown(markdown_text, image_width=800, image_height=600, font_size=
|
||||
if font.getsize(line)[0] > image_width:
|
||||
cp = line
|
||||
single_size = font.getsize("步")[0]
|
||||
max_words_per_line = image_width // single_size - 1
|
||||
max_words_per_line = (image_width // single_size)*2
|
||||
# 步长为单个字符的宽度
|
||||
_t = 0
|
||||
for ii in range(len(line)):
|
||||
_t += 1
|
||||
# 检测是否是中文
|
||||
if line[ii] >= u'\u4e00' and line[ii] <= u'\u9fa5':
|
||||
_t += 2
|
||||
else:
|
||||
_t += 1
|
||||
|
||||
if _t > max_words_per_line:
|
||||
# splited.append(cp[:ii] + '\n')
|
||||
_pre_lines.append(cp[:ii])
|
||||
|
||||
Reference in New Issue
Block a user