feat: support multiple custom fonts
This commit is contained in:
+36
-12
@@ -62,19 +62,43 @@ spec:
|
||||
label: 启用自定义字体文件
|
||||
value: false
|
||||
help: '如果启用 "使用系统字体", 此配置项不生效'
|
||||
|
||||
- $formkit: attachment
|
||||
|
||||
- $formkit: array
|
||||
if: "$get(custom_font_enable).value === true"
|
||||
name: custom_font_file
|
||||
label: 自定义字体文件
|
||||
value: ""
|
||||
|
||||
- $formkit: text
|
||||
if: "$get(custom_font_enable).value === true"
|
||||
name: custom_font_name
|
||||
label: 字体名称
|
||||
help: 填写字体文件中声明的字体全名或 PostScript 名, 名称不正确时无法加载字体
|
||||
value: ""
|
||||
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: 自定义字体文件
|
||||
value: ""
|
||||
validation: "required"
|
||||
|
||||
- $formkit: select
|
||||
name: format
|
||||
label: 字体格式
|
||||
value: woff2
|
||||
options:
|
||||
- label: WOFF2
|
||||
value: woff2
|
||||
- label: WOFF
|
||||
value: woff
|
||||
- label: TrueType
|
||||
value: truetype
|
||||
- label: OpenType
|
||||
value: opentype
|
||||
|
||||
- $formkit: checkbox
|
||||
name: color_scheme_switcher_enable
|
||||
|
||||
+33
-29
@@ -82,37 +82,41 @@
|
||||
window.TerminalTheme?.applyCustomCss?.();
|
||||
</script>
|
||||
<th:block
|
||||
th:if="${theme.config?.style?.custom_font_enable and not theme.config?.style?.system_font_enable}"
|
||||
th:with="font=${#objects.nullSafe(theme.config?.style?.custom_font_file, #theme.assets('/dist/JetBrainsMono-Regular.woff2'))},
|
||||
ext=${font.substring(font.lastIndexOf('.') + 1)},
|
||||
format=${ext == 'woff2' ? 'woff2' :
|
||||
(ext == 'woff' ? 'woff' :
|
||||
(ext == 'ttf' ? 'truetype' :
|
||||
(ext == 'otf' ? 'opentype' :
|
||||
(ext == 'eot' ? 'embedded-opentype' :
|
||||
((ext == 'ttc' or ext == 'otc') ? 'collection' : ext)))))},
|
||||
mime=${ext == 'woff2' ? 'font/woff2' :
|
||||
(ext == 'woff' ? 'font/woff' :
|
||||
(ext == 'ttf' ? 'font/ttf' :
|
||||
(ext == 'otf' ? 'font/otf' :
|
||||
(ext == 'sfnt' ? 'font/sfnt' :
|
||||
(ext == 'eot' ? 'application/vnd.ms-fontobject' :
|
||||
((ext == 'ttc' or ext == 'otc') ? 'font/collection' : 'application/octet-stream'))))))}">
|
||||
<link rel="preload" th:href="${font}" as="font" th:type="${mime}" crossorigin/>
|
||||
th:if="${theme.config?.style?.custom_font_enable
|
||||
and not theme.config?.style?.system_font_enable
|
||||
and theme.config?.style?.custom_fonts != null
|
||||
and not #lists.isEmpty(theme.config.style.custom_fonts)}">
|
||||
|
||||
<!-- Preload primary font -->
|
||||
<th:block th:with="font=${theme.config.style.custom_fonts[0]}">
|
||||
<link rel="preload"
|
||||
th:href="${font.file}"
|
||||
as="font"
|
||||
th:type="${font.format == 'woff2' ? 'font/woff2' :
|
||||
(font.format == 'woff' ? 'font/woff' :
|
||||
(font.format == 'truetype' ? 'font/ttf' :
|
||||
(font.format == 'opentype' ? 'font/otf' : 'application/octet-stream')))}"
|
||||
crossorigin/>
|
||||
</th:block>
|
||||
|
||||
<!--/*/
|
||||
<style th:inline="css">
|
||||
@font-face {
|
||||
font-display: swap;
|
||||
font-family: "custom";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src:
|
||||
local("[(${theme.config?.style?.custom_font_name})]"),
|
||||
url("[(${font})]") format("[(${format})]");
|
||||
}
|
||||
:root {
|
||||
--family-theme-font: custom;
|
||||
}
|
||||
[# th:each="font : ${theme.config.style.custom_fonts}"]
|
||||
@font-face {
|
||||
font-display: swap;
|
||||
font-family: "[(${font.name})]";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: url("[(${font.file})]") format("[(${font.format})]");
|
||||
}
|
||||
[/]
|
||||
|
||||
:root {
|
||||
--family-theme-font:
|
||||
[# th:each="font, stat : ${theme.config.style.custom_fonts}"]
|
||||
"[(${font.name})]"[# th:if="${!stat.last}"],[/]
|
||||
[/];
|
||||
}
|
||||
</style>
|
||||
/*/-->
|
||||
</th:block>
|
||||
|
||||
Reference in New Issue
Block a user