This commit is contained in:
Daniel 2025-04-24 20:48:16 +08:00
parent 89d9d16a06
commit 99d4ad4bd4
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
3 changed files with 44 additions and 10 deletions

View File

@ -197,7 +197,7 @@ require (
replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950
replace github.com/pdfcpu/pdfcpu => github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01
replace github.com/pdfcpu/pdfcpu => github.com/88250/pdfcpu v0.3.14-0.20250424122812-f10e8d9d8d46
//replace github.com/88250/lute => F:\golang\gopath\src\github.com\88250\lute
//replace github.com/siyuan-note/dejavu => D:\88250\dejavu

View File

@ -16,8 +16,8 @@ github.com/88250/gulu v1.2.3-0.20250227144607-7f4570b0d689 h1:39y5g7vnFAIcXhTN3I
github.com/88250/gulu v1.2.3-0.20250227144607-7f4570b0d689/go.mod h1:c8uVw25vW2W4dhJ/j4iYsX5H1hc19spim266jO5x2hU=
github.com/88250/lute v1.7.7-0.20250423133018-cff81864be77 h1:Ky/O9dd9CJ6UZ4Ye8aWpycdlSuYtUKis5UuZLvsRa4w=
github.com/88250/lute v1.7.7-0.20250423133018-cff81864be77/go.mod h1:WYyUw//5yVw9BJnoVjx7rI/3szsISxNZCYGOqTIrV0o=
github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01 h1:AcFe63RXjIh1XtX/dc4Es3U8bYKjlEkvavHd1nFBOHM=
github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01/go.mod h1:fVfOloBzs2+W2VJCCbq60XIxc3yJHAZ0Gahv1oO0gyI=
github.com/88250/pdfcpu v0.3.14-0.20250424122812-f10e8d9d8d46 h1:Bq1JsDfVbHKUxNL/B2JXd8cC/1h6aFjrlXpGycnh0Hk=
github.com/88250/pdfcpu v0.3.14-0.20250424122812-f10e8d9d8d46/go.mod h1:fVfOloBzs2+W2VJCCbq60XIxc3yJHAZ0Gahv1oO0gyI=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1/go.mod h1:U3pckKQIgxxkmZjV5yXQjHdGxQK0o/vEZeZ6cQsxfHw=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=

View File

@ -1041,6 +1041,10 @@ func ProcessPDF(id, p string, merge, removeAssets, watermark bool) (err error) {
logging.LogErrorf("mkdir [%s] failed: %s", font.UserFontDir, mkdirErr)
return
}
if loadErr := api.LoadUserFonts(); nil != loadErr {
logging.LogErrorf("load user fonts failed: %s", loadErr)
}
pdfCtx, ctxErr := api.ReadContextFile(p)
if nil != ctxErr {
logging.LogErrorf("read pdf context failed: %s", ctxErr)
@ -1098,7 +1102,43 @@ func processPDFWatermark(pdfCtx *model.Context, watermark bool) {
}
m[kv[0]] = kv[1]
}
m["fontname"] = "LXGWWenKaiLite-Regular"
useDefaultFont := true
if "" != m["fontname"] {
listFonts, e := api.ListFonts()
var builtInFontNames []string
if nil != e {
logging.LogInfof("listFont failed: %s", e)
} else {
for _, f := range listFonts {
if strings.Contains(f, "(") {
f = f[:strings.Index(f, "(")]
}
f = strings.TrimSpace(f)
if strings.Contains(f, ":") || "" == f || strings.Contains(f, "Corefonts") || strings.Contains(f, "Userfonts") {
continue
}
builtInFontNames = append(builtInFontNames, f)
}
for _, font := range builtInFontNames {
if font == m["fontname"] {
useDefaultFont = false
break
}
}
}
}
if useDefaultFont {
m["fontname"] = "LXGWWenKaiLite-Regular"
fontPath := filepath.Join(util.AppearancePath, "fonts", "LxgwWenKai-Lite-1.501", "LXGWWenKaiLite-Regular.ttf")
err := api.InstallFonts([]string{fontPath})
if err != nil {
logging.LogErrorf("install font [%s] failed: %s", fontPath, err)
}
}
descBuilder := bytes.Buffer{}
for k, v := range m {
descBuilder.WriteString(k)
@ -1108,12 +1148,6 @@ func processPDFWatermark(pdfCtx *model.Context, watermark bool) {
}
desc = descBuilder.String()
desc = desc[:len(desc)-1]
fontPath := filepath.Join(util.AppearancePath, "fonts", "LxgwWenKai-Lite-1.501", "LXGWWenKaiLite-Regular.ttf")
err := api.InstallFonts([]string{fontPath})
if err != nil {
logging.LogErrorf("install font [%s] failed: %s", fontPath, err)
}
}
logging.LogInfof("add PDF watermark [mode=%s, str=%s, desc=%s]", mode, str, desc)