Skip to content

针对汉字字符进行上下、左右居中特殊处理 - #18

Open
217heidai wants to merge 2 commits into
StarCompute:masterfrom
217heidai:dev
Open

针对汉字字符进行上下、左右居中特殊处理#18
217heidai wants to merge 2 commits into
StarCompute:masterfrom
217heidai:dev

Conversation

@217heidai

Copy link
Copy Markdown

针对汉字字符进行上下、左右居中特殊处理,优化显示效果。

@217heidai

Copy link
Copy Markdown
Author

可以缓解 #16

@StarCompute

Copy link
Copy Markdown
Owner

因为懒,一直没有回复你,不过今天看到一种方法,暂时没有测试,供参考:
`try:
# 新版本使用textbbox
bbox = draw.textbbox((0, 0), char, font=font)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]
except AttributeError:
# 旧版本使用textsize
text_width, text_height = draw.textsize(char, font=font)

# 计算位置
x = (font_size - text_width) // 2
y = (font_size - text_height) // 2`

1 similar comment
@StarCompute

Copy link
Copy Markdown
Owner

因为懒,一直没有回复你,不过今天看到一种方法,暂时没有测试,供参考:
`try:
# 新版本使用textbbox
bbox = draw.textbbox((0, 0), char, font=font)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]
except AttributeError:
# 旧版本使用textsize
text_width, text_height = draw.textsize(char, font=font)

# 计算位置
x = (font_size - text_width) // 2
y = (font_size - text_height) // 2`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants