feat: support multiple custom fonts

This commit is contained in:
Erzbir
2026-08-17 22:27:14 +08:00
parent 38639e3199
commit 2a9da1e8f8
2 changed files with 69 additions and 41 deletions
+32 -8
View File
@@ -63,18 +63,42 @@ spec:
value: false value: false
help: '如果启用 "使用系统字体", 此配置项不生效' help: '如果启用 "使用系统字体", 此配置项不生效'
- $formkit: attachment - $formkit: array
if: "$get(custom_font_enable).value === true" if: "$get(custom_font_enable).value === true"
name: custom_font_file name: custom_fonts
label: 自定义字体
value: [ ]
itemLabels:
- type: "text"
label: "$value.name"
- type: "text"
label: "$value.file"
children:
- $formkit: text
name: name
label: 字体名称
placeholder: "JetBrains Mono"
validation: "required"
- $formkit: attachment
name: file
label: 自定义字体文件 label: 自定义字体文件
value: "" value: ""
validation: "required"
- $formkit: text - $formkit: select
if: "$get(custom_font_enable).value === true" name: format
name: custom_font_name label: 字体格式
label: 字体名称 value: woff2
help: 填写字体文件中声明的字体全名或 PostScript 名, 名称不正确时无法加载字体 options:
value: "" - label: WOFF2
value: woff2
- label: WOFF
value: woff
- label: TrueType
value: truetype
- label: OpenType
value: opentype
- $formkit: checkbox - $formkit: checkbox
name: color_scheme_switcher_enable name: color_scheme_switcher_enable
+26 -22
View File
@@ -82,36 +82,40 @@
window.TerminalTheme?.applyCustomCss?.(); window.TerminalTheme?.applyCustomCss?.();
</script> </script>
<th:block <th:block
th:if="${theme.config?.style?.custom_font_enable and not theme.config?.style?.system_font_enable}" th:if="${theme.config?.style?.custom_font_enable
th:with="font=${#objects.nullSafe(theme.config?.style?.custom_font_file, #theme.assets('/dist/JetBrainsMono-Regular.woff2'))}, and not theme.config?.style?.system_font_enable
ext=${font.substring(font.lastIndexOf('.') + 1)}, and theme.config?.style?.custom_fonts != null
format=${ext == 'woff2' ? 'woff2' : and not #lists.isEmpty(theme.config.style.custom_fonts)}">
(ext == 'woff' ? 'woff' :
(ext == 'ttf' ? 'truetype' : <!-- Preload primary font -->
(ext == 'otf' ? 'opentype' : <th:block th:with="font=${theme.config.style.custom_fonts[0]}">
(ext == 'eot' ? 'embedded-opentype' : <link rel="preload"
((ext == 'ttc' or ext == 'otc') ? 'collection' : ext)))))}, th:href="${font.file}"
mime=${ext == 'woff2' ? 'font/woff2' : as="font"
(ext == 'woff' ? 'font/woff' : th:type="${font.format == 'woff2' ? 'font/woff2' :
(ext == 'ttf' ? 'font/ttf' : (font.format == 'woff' ? 'font/woff' :
(ext == 'otf' ? 'font/otf' : (font.format == 'truetype' ? 'font/ttf' :
(ext == 'sfnt' ? 'font/sfnt' : (font.format == 'opentype' ? 'font/otf' : 'application/octet-stream')))}"
(ext == 'eot' ? 'application/vnd.ms-fontobject' : crossorigin/>
((ext == 'ttc' or ext == 'otc') ? 'font/collection' : 'application/octet-stream'))))))}"> </th:block>
<link rel="preload" th:href="${font}" as="font" th:type="${mime}" crossorigin/>
<!--/*/ <!--/*/
<style th:inline="css"> <style th:inline="css">
[# th:each="font : ${theme.config.style.custom_fonts}"]
@font-face { @font-face {
font-display: swap; font-display: swap;
font-family: "custom"; font-family: "[(${font.name})]";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
src: src: url("[(${font.file})]") format("[(${font.format})]");
local("[(${theme.config?.style?.custom_font_name})]"),
url("[(${font})]") format("[(${format})]");
} }
[/]
:root { :root {
--family-theme-font: custom; --family-theme-font:
[# th:each="font, stat : ${theme.config.style.custom_fonts}"]
"[(${font.name})]"[# th:if="${!stat.last}"],[/]
[/];
} }
</style> </style>
/*/--> /*/-->