Skip to content

Instantly share code, notes, and snippets.

@Redlnn
Last active December 30, 2023 10:04
Show Gist options
  • Save Redlnn/ec888b4d3743965db6ba497c44d6b63c to your computer and use it in GitHub Desktop.
Save Redlnn/ec888b4d3743965db6ba497c44d6b63c to your computer and use it in GitHub Desktop.
一个生成用于 Stylus/Stylish 的全局衬线字体替换的 CSS 的脚本
# -*- coding: utf-8 -*-
"""
一个生成用于 Stylus/Stylish 的全局衬线字体替换的 CSS 的脚本
"""
template = '''\
@font-face {
font-family: '{{origin}}';
src: local('{{font}}');
}
'''
origin_fonts = {
'SC': [
'Source Han Serif CN',
'Source Han Serif SC',
'Noto Serif SC',
'Simsun',
'SimSun',
'simsun',
'宋体',
'宋體',
'瀹嬩綋',
'NSimsun',
'新宋体',
'新宋體',
],
'TC': [
'PMingLiu',
'PMingLiU-ExtB',
'新细明体',
'新細明體',
'MingLiu',
'细明体',
'細明體',
'AR PL UMing TW',
'cwTeXMing',
'台灣明體' 'Source Han Serif TC',
'Noto Serif CJK',
'Noto Serif TC',
],
'HC': [
'PMingLiU_HKSCS',
'PMingLiU_HKSCS-ExtB',
'MingLiU_HKSCS',
'MingLiU_HKSCS-ExtB',
'Source Han Serif HC',
'Noto Serif HC',
'Noto Serif HK',
],
'JP': [
'Source Han Serif',
'Noto Serif',
],
'KR': ['Source Han Serif K', 'Noto Serif K'],
}
fonts = {
'SC': 'Source Han Serif SC VF',
'TC': 'Source Han Serif TC VF',
'HC': 'Source Han Serif HC VF',
'JP': 'Source Han Serif VF',
'KR': 'Source Han Serif VF K',
}
footer = '''\
@font-face {
font-family: '標楷體';
src: local('KaiTi');
}
@font-face {
font-family: 'DFKai-SB';
src: local('KaiTi');
}
@font-face {
font-family: 'KaiTi_GB2312';
src: local('KaiTi');
}
@font-face {
font-family: '楷体_GB2312';
src: local('KaiTi');
}
@font-face {
font-family: 'SimFang_GB2312';
src: local('SimFang');
}
@font-face {
font-family: '仿宋_GB2312';
src: local('SimFang');
}
'''
out = '/* 替换衬线字体 */\n'
for lang, _origin_fonts in origin_fonts.items():
for origin_font in _origin_fonts:
out += template.replace('{{origin}}', origin_font).replace(
'{{font}}', fonts[lang]
)
with open('fonts-serif.css', 'w', encoding='utf8') as f:
f.write(out)
f.write(footer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment