Chinese glyphs of text cannot be displayed correctly
Description
Chinese glyphs of text cannot be displayed correctly
font: SourceHanSansSC-Normal.otf , 100% suppose Chinese
Code example to reproduce the issue:
full codes: Github Link
import flet as ft
from flet import Theme
import runadb
def main(page: ft.page):
page.title = "APKGET"
page.scroll = "always"
page.fonts = {"SHS": "SourceHanSans-normal.otf", "2": "https://www.unpkg.com/font-online/fonts/SourceHanSans/SourceHanSans-Normal.otf"}
page.theme = Theme(font_family="SHS")
global output_dir
output_dir = runadb.desktop_path()
def picked_dir(e: ft.FilePickerResultEvent):
if e.path:
global output_dir
pick_dir_text.value = (e.path)
output_dir = e.path
pick_dir_text.update()
pick_dir_dialog = ft.FilePicker(on_result=picked_dir)
page.overlay.append(pick_dir_dialog)
def update_list():
#app_list.rows.append(ft.DataRow(cells=[ft.DataCell(ft.Text("1")),ft.DataCell(ft.Text("2")),ft.DataCell(ft.Text("3")),]))
#page.update()
update_button.disabled = True
update_button.text = "加载中,请勿执行其它操作"
page.update()
global output_dir
def create_buttons(i):
global output_dir
return ft.DataCell(ft.ElevatedButton("导出",icon=ft.icons.DOWNLOAD, on_click=lambda _: runadb.push(i[0],output_dir,i[2])))
adb_app_list = runadb.get_list()
for i in adb_app_list:
app_list.rows.append(ft.DataRow(cells=[
create_buttons(i),
ft.DataCell(ft.Text(i[2])),
ft.DataCell(ft.Text(i[1]))
]))
update_button.disabled = False
update_button.text = "刷新列表"
page.update()
page.controls.append(ft.Markdown("# 快速保存手机中的apk",extension_set=ft.MarkdownExtensionSet.GITHUB_WEB))
pick_dir_text = ft.Text("未选择,默认为桌面")
update_button = ft.ElevatedButton("刷新列表",icon=ft.icons.REFRESH, on_click=lambda _: update_list())
page.controls.append(ft.Row([
update_button,
ft.ElevatedButton("更改导出路径",icon=ft.icons.FOLDER_OUTLINED,
on_click=lambda _: pick_dir_dialog.get_directory_path(),),
pick_dir_text,])
)
app_list = ft.DataTable(
columns=[ft.DataColumn(ft.Text("操作")),ft.DataColumn(ft.Text("应用名")),ft.DataColumn(ft.Text("包名"))],
rows=[],
border=ft.border.all(2, "grey"),
border_radius=10,
horizontal_lines=ft.border.BorderSide(1, "grey"),
)
page.controls.append(app_list)
page.update()
ft.app(target=main)
Describe the results you received:
The thickness of the character "导" is different
Some characters are different, it used Japanese glyphs but not Chinese glyphs.(Although they are similar)
(The characters in Notepad are correct, you can find them in my source code)
Describe the results you expected:
Just like that.
Flet version (pip show flet):
Name: flet
Version: 0.14.0
Summary: Flet for Python - easily build interactive multi-platform apps in Python
Home-page:
Author: Appveyor Systems Inc.
Author-email: [email protected]
License: Apache-2.0
Location: e:\python\lib\site-packages
Requires: cookiecutter, flet-runtime, packaging, qrcode, watchdog, websocket-client, websockets
Required-by:
Operating system:
Windows10 1909
I also found the same issue on Windows, but the same code works fine on Mac.
I hope this helps: page.fonts = { "SourceHan": exec_folder+"/assets/fonts/SourceHanSerifCN-Regular.otf", } page.theme.font_family = "SourceHan" text_style= ft.TextStyle( font_family="SourceHan"),
before:
after:
page.fonts = {"SHS": "SourceHanSans-normal.otf", "2": "https://www.unpkg.com/font-online/fonts/SourceHanSans/SourceHanSans-Normal.otf"}
你这 fonts 加载的写法不对吧
Yes, I also found that the support for Simplified Chinese fonts is not good enough. For example, the menu items in the picture are sometimes thick and sometimes thin.
Chinese language can use AlibabaPuHuiTi, https://www.alibabafonts.com/
I found that there is no problem with Chinese fonts on MacOS, but there are the above problems on Windows and Linux.
I'm running into the same issue, I feel it auto-translates Simplified Chinese into Traditional Chinese fonts, you can tell from the way of writing and the ones that didn't find the match properly displayed with a thinner font. I Hope Simplified Chinese can be 100% supported shortly.