Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle: Clean up obsolete bundled fonts with URL compatibility https://github.com/siyuan-note/siyuan/issues/15891

Danielbc6705d6cf04
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index 9f453d5e73..47e5a772dd 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -88,9 +88,7 @@ Minified files that contain their own bundled-license blocks retain those blocks
|---|---|---|---|---|
| JetBrains Mono | 2.304 | OFL-1.1 | [upstream](https://github.com/JetBrains/JetBrainsMono) | app/appearance/fonts/JetBrainsMono-2.304/LICENSE |
| LXGW WenKai GB Lite | 1.521 | OFL-1.1 | [upstream](https://github.com/lxgw/LxgwWenkaiGB-Lite) | app/appearance/fonts/LxgwWenKaiGB-Lite-1.521/LICENSE |
-| LXGW WenKai Lite (retained version) | 1.501 | OFL-1.1 | [upstream](https://github.com/lxgw/LxgwWenKai-Lite) | app/appearance/fonts/LxgwWenKai-Lite-1.501/LICENSE |
| Noto COLRv1 Emoji | 2.051 | OFL-1.1 | [upstream](https://github.com/googlefonts/noto-emoji) | app/appearance/fonts/Noto-COLRv1-2.051/LICENSE |
-| Noto COLRv1 Emoji (retained version) | 2.047 | OFL-1.1 | [upstream](https://github.com/googlefonts/noto-emoji) | app/appearance/fonts/Noto-COLRv1-2.047/LICENSE |
## Go standard library and runtime
@@ -1610,105 +1608,6 @@ This license is copied below, and is also available with a FAQ at:
https://scripts.sil.org/OFL
------------------------------------------------------------
-SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
------------------------------------------------------------
-
-PREAMBLE
-The goals of the Open Font License (OFL) are to stimulate worldwide
-development of collaborative font projects, to support the font creation
-efforts of academic and linguistic communities, and to provide a free and
-open framework in which fonts may be shared and improved in partnership
-with others.
-
-The OFL allows the licensed fonts to be used, studied, modified and
-redistributed freely as long as they are not sold by themselves. The
-fonts, including any derivative works, can be bundled, embedded,
-redistributed and/or sold with any software provided that any reserved
-names are not used by derivative works. The fonts and derivatives,
-however, cannot be released under any other type of license. The
-requirement for fonts to remain under this license does not apply
-to any document created using the fonts or their derivatives.
-
-DEFINITIONS
-"Font Software" refers to the set of files released by the Copyright
-Holder(s) under this license and clearly marked as such. This may
-include source files, build scripts and documentation.
-
-"Reserved Font Name" refers to any names specified as such after the
-copyright statement(s).
-
-"Original Version" refers to the collection of Font Software components as
-distributed by the Copyright Holder(s).
-
-"Modified Version" refers to any derivative made by adding to, deleting,
-or substituting -- in part or in whole -- any of the components of the
-Original Version, by changing formats or by porting the Font Software to a
-new environment.
-
-"Author" refers to any designer, engineer, programmer, technical
-writer or other person who contributed to the Font Software.
-
-PERMISSION & CONDITIONS
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of the Font Software, to use, study, copy, merge, embed, modify,
-redistribute, and sell modified and unmodified copies of the Font
-Software, subject to the following conditions:
-
-1) Neither the Font Software nor any of its individual components,
-in Original or Modified Versions, may be sold by itself.
-
-2) Original or Modified Versions of the Font Software may be bundled,
-redistributed and/or sold with any software, provided that each copy
-contains the above copyright notice and this license. These can be
-included either as stand-alone text files, human-readable headers or
-in the appropriate machine-readable metadata fields within text or
-binary files as long as those fields can be easily viewed by the user.
-
-3) No Modified Version of the Font Software may use the Reserved Font
-Name(s) unless explicit written permission is granted by the corresponding
-Copyright Holder. This restriction only applies to the primary font name as
-presented to the users.
-
-4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
-Software shall not be used to promote, endorse or advertise any
-Modified Version, except to acknowledge the contribution(s) of the
-Copyright Holder(s) and the Author(s) or with their explicit written
-permission.
-
-5) The Font Software, modified or unmodified, in part or in whole,
-must be distributed entirely under this license, and must not be
-distributed under any other license. The requirement for fonts to
-remain under this license does not apply to any document created
-using the Font Software.
-
-TERMINATION
-This license becomes null and void if any of the above conditions are
-not met.
-
-DISCLAIMER
-THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
-OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
-COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
-DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
-OTHER DEALINGS IN THE FONT SOFTWARE.
-```
-
-### app/appearance/fonts/LxgwWenKai-Lite-1.501/LICENSE
-
-```text
-Copyright 2021-2024 LXGW (https://github.com/lxgw/LxgwWenKai)
-Copyright 2020 The Klee Project Authors (https://github.com/fontworks-fonts/Klee)
-
-This Font Software is licensed under the SIL Open Font License, Version 1.1.
-This license is copied below, and is also available with a FAQ at:
-https://openfontlicense.org
-
-
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
@@ -1896,103 +1795,6 @@ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
```
-### app/appearance/fonts/Noto-COLRv1-2.047/LICENSE
-
-```text
-This Font Software is licensed under the SIL Open Font License,
-Version 1.1.
-
-This license is copied below, and is also available with a FAQ at:
-http://scripts.sil.org/OFL
-
------------------------------------------------------------
-SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
------------------------------------------------------------
-
-PREAMBLE
-The goals of the Open Font License (OFL) are to stimulate worldwide
-development of collaborative font projects, to support the font
-creation efforts of academic and linguistic communities, and to
-provide a free and open framework in which fonts may be shared and
-improved in partnership with others.
-
-The OFL allows the licensed fonts to be used, studied, modified and
-redistributed freely as long as they are not sold by themselves. The
-fonts, including any derivative works, can be bundled, embedded,
-redistributed and/or sold with any software provided that any reserved
-names are not used by derivative works. The fonts and derivatives,
-however, cannot be released under any other type of license. The
-requirement for fonts to remain under this license does not apply to
-any document created using the fonts or their derivatives.
-
-DEFINITIONS
-"Font Software" refers to the set of files released by the Copyright
-Holder(s) under this license and clearly marked as such. This may
-include source files, build scripts and documentation.
-
-"Reserved Font Name" refers to any names specified as such after the
-copyright statement(s).
-
-"Original Version" refers to the collection of Font Software
-components as distributed by the Copyright Holder(s).
-
-"Modified Version" refers to any derivative made by adding to,
-deleting, or substituting -- in part or in whole -- any of the
-components of the Original Version, by changing formats or by porting
-the Font Software to a new environment.
-
-"Author" refers to any designer, engineer, programmer, technical
-writer or other person who contributed to the Font Software.
-
-PERMISSION & CONDITIONS
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of the Font Software, to use, study, copy, merge, embed,
-modify, redistribute, and sell modified and unmodified copies of the
-Font Software, subject to the following conditions:
-
-1) Neither the Font Software nor any of its individual components, in
-Original or Modified Versions, may be sold by itself.
-
-2) Original or Modified Versions of the Font Software may be bundled,
-redistributed and/or sold with any software, provided that each copy
-contains the above copyright notice and this license. These can be
-included either as stand-alone text files, human-readable headers or
-in the appropriate machine-readable metadata fields within text or
-binary files as long as those fields can be easily viewed by the user.
-
-3) No Modified Version of the Font Software may use the Reserved Font
-Name(s) unless explicit written permission is granted by the
-corresponding Copyright Holder. This restriction only applies to the
-primary font name as presented to the users.
-
-4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
-Software shall not be used to promote, endorse or advertise any
-Modified Version, except to acknowledge the contribution(s) of the
-Copyright Holder(s) and the Author(s) or with their explicit written
-permission.
-
-5) The Font Software, modified or unmodified, in part or in whole,
-must be distributed entirely under this license, and must not be
-distributed under any other license. The requirement for fonts to
-remain under this license does not apply to any document created using
-the Font Software.
-
-TERMINATION
-This license becomes null and void if any of the above conditions are
-not met.
-
-DISCLAIMER
-THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
-OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
-COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
-DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
-OTHER DEALINGS IN THE FONT SOFTWARE.
-```
-
### app/appearance/fonts/Noto-COLRv1-2.051/LICENSE
```text
diff --git a/app/appearance/fonts/LxgwWenKai-Lite-1.501/LICENSE b/app/appearance/fonts/LxgwWenKai-Lite-1.501/LICENSE
deleted file mode 100644
index bf48308d5b..0000000000
--- a/app/appearance/fonts/LxgwWenKai-Lite-1.501/LICENSE
+++ /dev/null
@@ -1,94 +0,0 @@
-Copyright 2021-2024 LXGW (https://github.com/lxgw/LxgwWenKai)
-Copyright 2020 The Klee Project Authors (https://github.com/fontworks-fonts/Klee)
-
-This Font Software is licensed under the SIL Open Font License, Version 1.1.
-This license is copied below, and is also available with a FAQ at:
-https://openfontlicense.org
-
-
------------------------------------------------------------
-SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
------------------------------------------------------------
-
-PREAMBLE
-The goals of the Open Font License (OFL) are to stimulate worldwide
-development of collaborative font projects, to support the font creation
-efforts of academic and linguistic communities, and to provide a free and
-open framework in which fonts may be shared and improved in partnership
-with others.
-
-The OFL allows the licensed fonts to be used, studied, modified and
-redistributed freely as long as they are not sold by themselves. The
-fonts, including any derivative works, can be bundled, embedded,
-redistributed and/or sold with any software provided that any reserved
-names are not used by derivative works. The fonts and derivatives,
-however, cannot be released under any other type of license. The
-requirement for fonts to remain under this license does not apply
-to any document created using the fonts or their derivatives.
-
-DEFINITIONS
-"Font Software" refers to the set of files released by the Copyright
-Holder(s) under this license and clearly marked as such. This may
-include source files, build scripts and documentation.
-
-"Reserved Font Name" refers to any names specified as such after the
-copyright statement(s).
-
-"Original Version" refers to the collection of Font Software components as
-distributed by the Copyright Holder(s).
-
-"Modified Version" refers to any derivative made by adding to, deleting,
-or substituting -- in part or in whole -- any of the components of the
-Original Version, by changing formats or by porting the Font Software to a
-new environment.
-
-"Author" refers to any designer, engineer, programmer, technical
-writer or other person who contributed to the Font Software.
-
-PERMISSION & CONDITIONS
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of the Font Software, to use, study, copy, merge, embed, modify,
-redistribute, and sell modified and unmodified copies of the Font
-Software, subject to the following conditions:
-
-1) Neither the Font Software nor any of its individual components,
-in Original or Modified Versions, may be sold by itself.
-
-2) Original or Modified Versions of the Font Software may be bundled,
-redistributed and/or sold with any software, provided that each copy
-contains the above copyright notice and this license. These can be
-included either as stand-alone text files, human-readable headers or
-in the appropriate machine-readable metadata fields within text or
-binary files as long as those fields can be easily viewed by the user.
-
-3) No Modified Version of the Font Software may use the Reserved Font
-Name(s) unless explicit written permission is granted by the corresponding
-Copyright Holder. This restriction only applies to the primary font name as
-presented to the users.
-
-4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
-Software shall not be used to promote, endorse or advertise any
-Modified Version, except to acknowledge the contribution(s) of the
-Copyright Holder(s) and the Author(s) or with their explicit written
-permission.
-
-5) The Font Software, modified or unmodified, in part or in whole,
-must be distributed entirely under this license, and must not be
-distributed under any other license. The requirement for fonts to
-remain under this license does not apply to any document created
-using the Font Software.
-
-TERMINATION
-This license becomes null and void if any of the above conditions are
-not met.
-
-DISCLAIMER
-THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
-OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
-COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
-DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
-OTHER DEALINGS IN THE FONT SOFTWARE.
\ No newline at end of file
diff --git a/app/appearance/fonts/LxgwWenKai-Lite-1.501/LXGWWenKaiLite-Regular.ttf b/app/appearance/fonts/LxgwWenKai-Lite-1.501/LXGWWenKaiLite-Regular.ttf
deleted file mode 100644
index 52e9959610..0000000000
Binary files a/app/appearance/fonts/LxgwWenKai-Lite-1.501/LXGWWenKaiLite-Regular.ttf and /dev/null differ
diff --git a/app/appearance/fonts/Noto-COLRv1-2.047/LICENSE b/app/appearance/fonts/Noto-COLRv1-2.047/LICENSE
deleted file mode 100644
index d952d62c06..0000000000
--- a/app/appearance/fonts/Noto-COLRv1-2.047/LICENSE
+++ /dev/null
@@ -1,92 +0,0 @@
-This Font Software is licensed under the SIL Open Font License,
-Version 1.1.
-
-This license is copied below, and is also available with a FAQ at:
-http://scripts.sil.org/OFL
-
------------------------------------------------------------
-SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
------------------------------------------------------------
-
-PREAMBLE
-The goals of the Open Font License (OFL) are to stimulate worldwide
-development of collaborative font projects, to support the font
-creation efforts of academic and linguistic communities, and to
-provide a free and open framework in which fonts may be shared and
-improved in partnership with others.
-
-The OFL allows the licensed fonts to be used, studied, modified and
-redistributed freely as long as they are not sold by themselves. The
-fonts, including any derivative works, can be bundled, embedded,
-redistributed and/or sold with any software provided that any reserved
-names are not used by derivative works. The fonts and derivatives,
-however, cannot be released under any other type of license. The
-requirement for fonts to remain under this license does not apply to
-any document created using the fonts or their derivatives.
-
-DEFINITIONS
-"Font Software" refers to the set of files released by the Copyright
-Holder(s) under this license and clearly marked as such. This may
-include source files, build scripts and documentation.
-
-"Reserved Font Name" refers to any names specified as such after the
-copyright statement(s).
-
-"Original Version" refers to the collection of Font Software
-components as distributed by the Copyright Holder(s).
-
-"Modified Version" refers to any derivative made by adding to,
-deleting, or substituting -- in part or in whole -- any of the
-components of the Original Version, by changing formats or by porting
-the Font Software to a new environment.
-
-"Author" refers to any designer, engineer, programmer, technical
-writer or other person who contributed to the Font Software.
-
-PERMISSION & CONDITIONS
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of the Font Software, to use, study, copy, merge, embed,
-modify, redistribute, and sell modified and unmodified copies of the
-Font Software, subject to the following conditions:
-
-1) Neither the Font Software nor any of its individual components, in
-Original or Modified Versions, may be sold by itself.
-
-2) Original or Modified Versions of the Font Software may be bundled,
-redistributed and/or sold with any software, provided that each copy
-contains the above copyright notice and this license. These can be
-included either as stand-alone text files, human-readable headers or
-in the appropriate machine-readable metadata fields within text or
-binary files as long as those fields can be easily viewed by the user.
-
-3) No Modified Version of the Font Software may use the Reserved Font
-Name(s) unless explicit written permission is granted by the
-corresponding Copyright Holder. This restriction only applies to the
-primary font name as presented to the users.
-
-4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
-Software shall not be used to promote, endorse or advertise any
-Modified Version, except to acknowledge the contribution(s) of the
-Copyright Holder(s) and the Author(s) or with their explicit written
-permission.
-
-5) The Font Software, modified or unmodified, in part or in whole,
-must be distributed entirely under this license, and must not be
-distributed under any other license. The requirement for fonts to
-remain under this license does not apply to any document created using
-the Font Software.
-
-TERMINATION
-This license becomes null and void if any of the above conditions are
-not met.
-
-DISCLAIMER
-THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
-OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
-COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
-DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
-OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/app/appearance/fonts/Noto-COLRv1-2.047/Noto-COLRv1.woff2 b/app/appearance/fonts/Noto-COLRv1-2.047/Noto-COLRv1.woff2
deleted file mode 100644
index b77ea8505a..0000000000
Binary files a/app/appearance/fonts/Noto-COLRv1-2.047/Noto-COLRv1.woff2 and /dev/null differ
diff --git a/app/appearance/fonts/Noto-COLRv1-2.051/README.md b/app/appearance/fonts/Noto-COLRv1-2.051/README.md
index 2edc2ef9c5..0c9d8ab27c 100644
--- a/app/appearance/fonts/Noto-COLRv1-2.051/README.md
+++ b/app/appearance/fonts/Noto-COLRv1-2.051/README.md
@@ -19,4 +19,4 @@ python -m fontTools.ttLib.woff2 compress Noto-COLRv1.ttf -o Noto-COLRv1.woff2
在 `app/` 目录运行 `node --import tsx --test src/util/emojiFont.test.ts tests/emojiFont.test.js`,检查新增列表、补充范围、实际字形组合和离线字体加载。浏览器测试使用 Electron,分别检查三种平台样式分支;这不替代实际 Apple WebKit 和移动端的兼容性验证。
-保留 `Noto-COLRv1-2.047` 目录以兼容历史引用;当前前端和离线 HTML 导出使用本目录。
+当前前端和离线 HTML 导出使用本目录。内核仅清理内容与原版一致的 `Noto-COLRv1-2.047` 历史副本;旧字体 URL 在文件缺失时映射到本目录,用户修改过的旧文件优先保留和使用。
diff --git a/kernel/model/appearance.go b/kernel/model/appearance.go
index 5ef68c0047..4c97f3108e 100644
--- a/kernel/model/appearance.go
+++ b/kernel/model/appearance.go
@@ -51,6 +51,10 @@ func InitAppearance() {
return
}
+ if err := util.CleanupLegacyFonts(util.AppearancePath); err != nil {
+ logging.LogWarnf("clean up legacy fonts failed: %s", err)
+ }
+
refreshAppearanceConfig()
util.InitEmojiChars()
}
diff --git a/kernel/server/appearance_path.go b/kernel/server/appearance_path.go
index 57a8c33f6c..2879d1b8e1 100644
--- a/kernel/server/appearance_path.go
+++ b/kernel/server/appearance_path.go
@@ -38,6 +38,17 @@ func isThirdPartyAppearanceRequest(requestPath string) bool {
// resolveAppearanceFile 在读取前限定真实路径,仅允许主题和图标包目录链接到外部目录。
func resolveAppearanceFile(root, requestPath string) (string, int) {
+ filePath, status := resolveAppearanceFilePath(root, requestPath)
+ if replacement := util.LegacyFontReplacement(requestPath); status == 0 && replacement != "" {
+ if _, err := os.Lstat(filePath); os.IsNotExist(err) {
+ // 已存在的用户文件优先,仅为缺失的历史字体提供替代资源,并复用路径边界校验。
+ return resolveAppearanceFilePath(root, replacement)
+ }
+ }
+ return filePath, status
+}
+
+func resolveAppearanceFilePath(root, requestPath string) (string, int) {
relativePath, ok := cleanStaticRelativePath(requestPath)
if !ok {
return "", http.StatusForbidden
diff --git a/kernel/server/legacy_font_test.go b/kernel/server/legacy_font_test.go
new file mode 100644
index 0000000000..55e0b334ee
--- /dev/null
+++ b/kernel/server/legacy_font_test.go
@@ -0,0 +1,89 @@
+// SiYuan - From thought to insight, with agents
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package server
+
+import (
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/model"
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
+
+func TestLegacyFontURLs(t *testing.T) {
+ oldRoot, oldMode, oldConf := util.AppearancePath, util.Mode, model.Conf
+ util.AppearancePath, util.Mode = t.TempDir(), "prod"
+ model.Conf = model.NewAppConf()
+ model.Conf.AccessAuthCode = "test-password"
+ t.Cleanup(func() { util.AppearancePath, util.Mode, model.Conf = oldRoot, oldMode, oldConf })
+ engine := gin.New()
+ serveAppearance(engine)
+ for _, oldPath := range []string{
+ "fonts/JetBrainsMono-1.0.3/JetBrainsMono-Regular.woff",
+ "fonts/LxgwWenKai-Lite-1.311/LXGWWenKaiLite-Regular.ttf",
+ "fonts/LxgwWenKai-Lite-1.501/LXGWWenKaiLite-Regular.ttf",
+ "fonts/Noto-COLRv1-2.047/Noto-COLRv1.woff2",
+ } {
+ t.Run(oldPath, func(t *testing.T) {
+ currentPath := util.LegacyFontReplacement(oldPath)
+ if currentPath == "" {
+ t.Fatal("missing compatibility mapping")
+ }
+ write := func(name, data string) {
+ t.Helper()
+ file := filepath.Join(util.AppearancePath, filepath.FromSlash(name))
+ if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(file, []byte(data), 0644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ check := func(want int, body string) {
+ t.Helper()
+ r := httptest.NewRecorder()
+ engine.ServeHTTP(r, httptest.NewRequest("GET", "/appearance/"+oldPath+"?v=old", nil))
+ if r.Code != want || body != "" && r.Body.String() != body {
+ t.Fatalf("status=%d body=%q", r.Code, r.Body.String())
+ }
+ }
+ write(currentPath, "current")
+ check(200, "current")
+ write(oldPath, "user modified")
+ check(200, "user modified")
+ if err := os.Remove(filepath.Join(util.AppearancePath, filepath.FromSlash(oldPath))); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Remove(filepath.Join(util.AppearancePath, filepath.FromSlash(currentPath))); err != nil {
+ t.Fatal(err)
+ }
+ check(404, "")
+ outside := filepath.Join(t.TempDir(), "private")
+ if err := os.WriteFile(outside, []byte("secret"), 0644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(outside, filepath.Join(util.AppearancePath, filepath.FromSlash(currentPath))); err != nil {
+ t.Skipf("symlink unavailable: %v", err)
+ }
+ check(403, "")
+ os.Remove(filepath.Join(util.AppearancePath, filepath.FromSlash(currentPath)))
+ })
+ }
+}
diff --git a/kernel/util/legacy_font.go b/kernel/util/legacy_font.go
new file mode 100644
index 0000000000..9670a5396c
--- /dev/null
+++ b/kernel/util/legacy_font.go
@@ -0,0 +1,163 @@
+// SiYuan - From thought to insight, with agents
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package util
+
+import (
+ "bytes"
+ "crypto/sha256"
+ "fmt"
+ "io"
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+type legacyFont struct {
+ directory string
+ file string
+ replacement string
+ hashes map[string]string
+}
+
+// 历史文件校验值来自仓库中的发行资源;1.0.3 和 1.311 取自提交 1ca0fbce9b 的父提交。
+// LICENSE 按 LF 换行校验,以兼容不同平台的源码检出方式。
+var legacyFonts = []legacyFont{
+ {"JetBrainsMono-1.0.3", "JetBrainsMono-Regular.woff", "JetBrainsMono-2.304/JetBrainsMono-Regular.woff2", map[string]string{
+ "JetBrainsMono-Regular.woff": "018579ddf1ed49dc710b4012e460bf53b50cb1c57937ad0190e049231158d4f9",
+ "LICENSE": "dfbd64f8a465680b035eb2dc7326e4fa039ebab1d6b435ef05b39114abfb2699",
+ }},
+ {"LxgwWenKai-Lite-1.311", "LXGWWenKaiLite-Regular.ttf", "LxgwWenKaiGB-Lite-1.521/LXGWWenKaiGBLite-Regular.ttf", map[string]string{
+ "LXGWWenKaiLite-Regular.ttf": "5426d47684418aa3876b4b14535c2572e1deeaae84d7d42ee9b817114edcfd55",
+ "LICENSE": "6c9731e86205ff7b0b18dfa14d45442b61315576e660c3c7c32298a9a94fe52f",
+ }},
+ {"LxgwWenKai-Lite-1.501", "LXGWWenKaiLite-Regular.ttf", "LxgwWenKaiGB-Lite-1.521/LXGWWenKaiGBLite-Regular.ttf", map[string]string{
+ "LXGWWenKaiLite-Regular.ttf": "ea08d142772c60fb2e7c396213302e55762680ded7fb20f9a9f5a6b352d2bcfe",
+ "LICENSE": "ba5b13c50f860d8eae2342c334c062775f352f637b25870151a6cac35006383c",
+ }},
+ {"Noto-COLRv1-2.047", "Noto-COLRv1.woff2", "Noto-COLRv1-2.051/Noto-COLRv1.woff2", map[string]string{
+ "Noto-COLRv1.woff2": "adb7c3f25f5c6bbf511fcf5e2d03e657e935f468e4b38eff5f010a7d3ba01449",
+ "LICENSE": "6a73f9541c2de74158c0e7cf6b0a58ef774f5a780bf191f2d7ec9cc53efe2bf2",
+ }},
+}
+
+// LegacyFontReplacement 返回已知旧字体 URL 对应的新资源路径,仅用于旧文件缺失时的兼容读取。
+func LegacyFontReplacement(relativePath string) string {
+ for _, font := range legacyFonts {
+ if relativePath == "fonts/"+font.directory+"/"+font.file {
+ return "fonts/" + font.replacement
+ }
+ }
+ return ""
+}
+
+// CleanupLegacyFonts 在新版资源复制成功后清理原版历史字体,不递归删除目录或跟随符号链接。
+func CleanupLegacyFonts(appearanceRoot string) error {
+ for _, directory := range []string{appearanceRoot, filepath.Join(appearanceRoot, "fonts")} {
+ info, err := os.Lstat(directory)
+ if os.IsNotExist(err) {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ if !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
+ return nil
+ }
+ }
+ for _, font := range legacyFonts {
+ if err := cleanupLegacyFont(filepath.Join(appearanceRoot, "fonts"), font); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func cleanupLegacyFont(root string, font legacyFont) error {
+ // 新字体及所在目录必须已经可用,避免清理后没有可用的替代资源。
+ parts := strings.Split(font.replacement, "/")
+ for i := range parts {
+ info, err := os.Lstat(filepath.Join(append([]string{root}, parts[:i+1]...)...))
+ if os.IsNotExist(err) {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ if info.Mode()&os.ModeSymlink != 0 || (i < len(parts)-1 && !info.IsDir()) ||
+ (i == len(parts)-1 && (!info.Mode().IsRegular() || info.Size() == 0)) {
+ return nil
+ }
+ }
+ directory := filepath.Join(root, font.directory)
+ info, err := os.Lstat(directory)
+ if os.IsNotExist(err) {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ if !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
+ return nil
+ }
+ entries, err := os.ReadDir(directory)
+ if err != nil {
+ return err
+ }
+ for _, entry := range entries {
+ expected, known := font.hashes[entry.Name()]
+ if !known || !entry.Type().IsRegular() {
+ return nil
+ }
+ matches, matchErr := matchesLegacyFontFile(filepath.Join(directory, entry.Name()), entry.Name(), expected)
+ if matchErr != nil {
+ return matchErr
+ }
+ if !matches {
+ return nil
+ }
+ }
+ // 全部校验通过才删除已知文件;中断后可继续处理剩余文件,新加入的文件阻止目录删除。
+ for _, entry := range entries {
+ if err = os.Remove(filepath.Join(directory, entry.Name())); err != nil {
+ return err
+ }
+ }
+ return os.Remove(directory)
+}
+
+func matchesLegacyFontFile(path, name, expected string) (bool, error) {
+ file, err := os.Open(path)
+ if err != nil {
+ return false, err
+ }
+ defer file.Close()
+ hash := sha256.New()
+ if name == "LICENSE" {
+ // 原版许可证不足 8 KiB,限制读取大小以保留异常文件并避免启动时占用过多内存。
+ data, readErr := io.ReadAll(io.LimitReader(file, 8193))
+ if readErr != nil {
+ return false, readErr
+ }
+ if len(data) > 8192 {
+ return false, nil
+ }
+ hash.Write(bytes.ReplaceAll(data, []byte("\r\n"), []byte("\n")))
+ } else if _, err = io.Copy(hash, file); err != nil {
+ return false, err
+ }
+ return fmt.Sprintf("%x", hash.Sum(nil)) == expected, nil
+}
diff --git a/kernel/util/legacy_font_test.go b/kernel/util/legacy_font_test.go
new file mode 100644
index 0000000000..1e0d1cc5dd
--- /dev/null
+++ b/kernel/util/legacy_font_test.go
@@ -0,0 +1,166 @@
+// SiYuan - From thought to insight, with agents
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package util
+
+import (
+ "crypto/sha256"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+func TestLegacyFontReplacementsExist(t *testing.T) {
+ for _, font := range legacyFonts {
+ replacement := LegacyFontReplacement("fonts/" + font.directory + "/" + font.file)
+ info, err := os.Stat(filepath.Join("..", "..", "app", "appearance", filepath.FromSlash(replacement)))
+ if replacement == "" || err != nil || !info.Mode().IsRegular() || info.Size() == 0 {
+ t.Fatalf("replacement for %s is unavailable: %s, %v", font.directory, replacement, err)
+ }
+ }
+ for _, path := range []string{"fonts/custom/font.ttf", "fonts/Noto-COLRv1-2.051/Noto-COLRv1.woff2", "fonts/JetBrainsMono-2.304/JetBrainsMono-Regular.woff2", "fonts/JetBrainsMono-1.0.3/unknown.woff", "../fonts/JetBrainsMono-1.0.3/JetBrainsMono-Regular.woff"} {
+ if LegacyFontReplacement(path) != "" {
+ t.Fatalf("unexpected mapping for %q", path)
+ }
+ }
+}
+
+func TestCleanupLegacyFont(t *testing.T) {
+ for _, scenario := range []string{"original", "crlf", "modified", "large license", "extra", "subdirectory", "missing replacement", "empty replacement", "partial", "empty", "retry"} {
+ t.Run(scenario, func(t *testing.T) {
+ root := t.TempDir()
+ font := legacyFont{"old", "font.ttf", "new/font.ttf", map[string]string{
+ "font.ttf": fmt.Sprintf("%x", sha256.Sum256([]byte("original"))),
+ "LICENSE": fmt.Sprintf("%x", sha256.Sum256([]byte("license\n"))),
+ }}
+ write := func(name, content string) {
+ t.Helper()
+ file := filepath.Join(root, name)
+ if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(file, []byte(content), 0644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ write("old/font.ttf", "original")
+ write("old/LICENSE", "license\n")
+ write("new/font.ttf", "replacement")
+ write("custom/font.ttf", "private")
+ preserve := false
+ switch scenario {
+ case "crlf":
+ write("old/LICENSE", "license\r\n")
+ case "modified":
+ write("old/font.ttf", "modified")
+ preserve = true
+ case "large license":
+ write("old/LICENSE", strings.Repeat("x", 8193))
+ preserve = true
+ case "extra":
+ write("old/notes.txt", "notes")
+ preserve = true
+ case "subdirectory":
+ write("old/nested/font.ttf", "private")
+ preserve = true
+ case "missing replacement":
+ os.Remove(filepath.Join(root, "new/font.ttf"))
+ preserve = true
+ case "empty replacement":
+ write("new/font.ttf", "")
+ preserve = true
+ case "partial":
+ os.Remove(filepath.Join(root, "old/font.ttf"))
+ case "empty":
+ os.Remove(filepath.Join(root, "old/font.ttf"))
+ os.Remove(filepath.Join(root, "old/LICENSE"))
+ }
+ if err := cleanupLegacyFont(root, font); err != nil {
+ t.Fatal(err)
+ }
+ _, err := os.Stat(filepath.Join(root, "old"))
+ if preserve && err != nil || !preserve && !os.IsNotExist(err) {
+ t.Fatalf("preserve=%v: %v", preserve, err)
+ }
+ if preserve {
+ if _, err := os.Stat(filepath.Join(root, "old/LICENSE")); err != nil {
+ t.Fatal("partially removed protected directory", err)
+ }
+ }
+ if data, err := os.ReadFile(filepath.Join(root, "custom/font.ttf")); err != nil || string(data) != "private" {
+ t.Fatal("changed custom font", err)
+ }
+ if err := cleanupLegacyFont(root, font); err != nil {
+ t.Fatal("retry", err)
+ }
+ })
+ }
+}
+
+func TestCleanupLegacyFontsPreservesLinks(t *testing.T) {
+ for _, location := range []string{"root", "fonts", "directory", "file", "replacement"} {
+ t.Run(location, func(t *testing.T) {
+ root, outside := t.TempDir(), t.TempDir()
+ font := legacyFonts[0]
+ directory := filepath.Join(root, "fonts", font.directory)
+ if err := os.MkdirAll(directory, 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(outside, "private"), []byte("private"), 0644); err != nil {
+ t.Fatal(err)
+ }
+ replacement := filepath.Join(root, "fonts", filepath.FromSlash(font.replacement))
+ if err := os.MkdirAll(filepath.Dir(replacement), 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(replacement, []byte("replacement"), 0644); err != nil {
+ t.Fatal(err)
+ }
+ switch location {
+ case "root":
+ root = filepath.Join(root, "linked")
+ case "fonts":
+ os.Remove(directory)
+ os.Remove(replacement)
+ os.Remove(filepath.Dir(replacement))
+ os.Remove(filepath.Join(root, "fonts"))
+ case "directory":
+ os.Remove(directory)
+ case "replacement":
+ os.Remove(replacement)
+ }
+ link := map[string]string{"root": root, "fonts": filepath.Join(root, "fonts"), "directory": directory, "file": filepath.Join(directory, font.file), "replacement": replacement}[location]
+ target := outside
+ if location == "file" || location == "replacement" {
+ target = filepath.Join(outside, "private")
+ }
+ if err := os.Symlink(target, link); err != nil {
+ t.Skipf("symlink unavailable: %v", err)
+ }
+ if err := CleanupLegacyFonts(root); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := os.Lstat(link); err != nil {
+ t.Fatal("removed link", err)
+ }
+ if data, err := os.ReadFile(filepath.Join(outside, "private")); err != nil || string(data) != "private" {
+ t.Fatal("changed linked file", err)
+ }
+ })
+ }
+}
diff --git a/scripts/generate-third-party-notices.py b/scripts/generate-third-party-notices.py
index 685e934e45..9c7487b239 100644
--- a/scripts/generate-third-party-notices.py
+++ b/scripts/generate-third-party-notices.py
@@ -458,13 +458,6 @@ FONT_COMPONENTS = [
"https://github.com/lxgw/LxgwWenkaiGB-Lite",
"app/appearance/fonts/LxgwWenKaiGB-Lite-1.521/LICENSE",
),
- (
- "LXGW WenKai Lite (retained version)",
- "1.501",
- "OFL-1.1",
- "https://github.com/lxgw/LxgwWenKai-Lite",
- "app/appearance/fonts/LxgwWenKai-Lite-1.501/LICENSE",
- ),
(
"Noto COLRv1 Emoji",
"2.051",
@@ -472,13 +465,6 @@ FONT_COMPONENTS = [
"https://github.com/googlefonts/noto-emoji",
"app/appearance/fonts/Noto-COLRv1-2.051/LICENSE",
),
- (
- "Noto COLRv1 Emoji (retained version)",
- "2.047",
- "OFL-1.1",
- "https://github.com/googlefonts/noto-emoji",
- "app/appearance/fonts/Noto-COLRv1-2.047/LICENSE",
- ),
]
LOCAL_NOTICE_ROOTS = [