Improve Font Setting of First Execution (#897)

* init default font change

* rename

* improve default font list

* fix
This commit is contained in:
CHLBC 2024-07-16 17:05:26 +08:00 committed by GitHub
parent b1a0cf2666
commit 666b3ca482
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 3 deletions

View File

@ -12,6 +12,8 @@ from myutils.config import (
setlanguage,
static_data,
tryreadconfig,
getlanguse,
set_font_default,
)
import sqlite3
from myutils.utils import (
@ -1186,9 +1188,11 @@ class MAINUI:
def parsedefaultfont(self):
for k in ["fonttype", "fonttype2", "settingfonttype"]:
if globalconfig[k] == "":
globalconfig[k] = QFontDatabase.systemFont(
QFontDatabase.SystemFont.GeneralFont
).family()
l = "ja" if k=="fonttype" else getlanguse()
set_font_default(l, k)
# globalconfig[k] = QFontDatabase.systemFont(
# QFontDatabase.SystemFont.GeneralFont
# ).family()
def loadui(self):
self.installeventfillter()

View File

@ -1,6 +1,7 @@
import json
import os, time, uuid
from traceback import print_exc
from qtsymbols import *
def tryreadconfig(path, default=None):
@ -488,3 +489,37 @@ def saveallconfig():
"./files/lang/{}.json".format(getlanguse()),
languageshow,
)
def is_font_installed(font: str) -> bool:
return QFont(font).exactMatch()
# font_default_used = {}
def get_font_default(lang: str, issetting: bool) -> str:
# global font_default_used
# if lang in font_default_used.keys():
# return font_default_used[lang]
t = "setting_font_type_default" if issetting else "font_type_default"
l = lang if lang in static_data[t].keys() else "default"
font_default = ""
for font in static_data[t][l]:
if is_font_installed(font):
font_default = font
break
if font_default == "":
font_default = QFontDatabase.systemFont(
QFontDatabase.SystemFont.GeneralFont
).family()
# font_default_used["lang"] = font_default
return font_default
def set_font_default(lang: str, fonttype: str) -> None:
globalconfig[fonttype] = get_font_default(lang, True if fonttype=="settingfonttype" else False)

View File

@ -99,6 +99,24 @@
"th",
"bo"
],
"font_type_default": {
"default": ["Segoe UI", "Arial", "Tahoma", "Microsoft Sans Serif"],
"zh": ["微软雅黑", "Microsoft YaHei", "黑体", "SimHei", "新宋体", "NSimSun", "宋体", "SimSun"],
"ja": ["游ゴシック", "Yu Gothic", "メイリオ", "Meiryo", " Pゴシック", "MS PGothic", " ゴシック", "MS Gothic"],
"ko": ["맑은 고딕", "Malgun Gothic", "돋움체", "Dotum", "굴림체", "Gulim", "바탕체", "Batang"],
"cht": ["微軟正黑體", "Microsoft JhengHei", "標楷體", "DFKai-SB", "新細明體", "PMingLiU", "細明體", "MingLiU"],
"th": ["Leelawadee", "Tahoma", "Microsoft Sans Serif"],
"bo": ["Microsoft Himalaya", "Noto Serif Tibetan", "Tibetan Machine Uni"]
},
"setting_font_type_default": {
"default": ["Segoe UI", "Tahoma", "Microsoft Sans Serif", "Arial"],
"zh": ["Microsoft YaHei UI", "微软雅黑", "Microsoft YaHei", "黑体", "SimHei", "新宋体", "NSimSun", "宋体", "SimSun"],
"ja": ["Yu Gothic UI", "游ゴシック", "Yu Gothic", "Meiryo UI", "メイリオ", "Meiryo", "MS UI Gothic", " Pゴシック", "MS PGothic", " ゴシック", "MS Gothic"],
"ko": ["맑은 고딕", "Malgun Gothic", "굴림체", "Gulim", "돋움체", "Dotum", "바탕체", "Batang"],
"cht": ["Microsoft JhengHei UI", "微軟正黑體", "Microsoft JhengHei", "新細明體", "PMingLiU", "細明體", "MingLiU"],
"th": ["Leelawadee UI", "Tahoma", "Microsoft Sans Serif"],
"bo": ["Microsoft YaHei UI", "微软雅黑", "Microsoft YaHei", "黑体", "SimHei", "新宋体", "NSimSun", "宋体", "SimSun"]
},
"codepage_display": [
"日语(CP932,SHIFT-JIS)",
"UTF8(CP65001)",