mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🔥 PDF export supports setting footer template https://github.com/siyuan-note/siyuan/issues/7478
Use frontend instead of backend impl
This commit is contained in:
parent
cd0fb32d38
commit
d544fec54e
2 changed files with 0 additions and 100 deletions
|
|
@ -22,12 +22,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/pdfcpu/pkg/api"
|
||||
"github.com/88250/pdfcpu/pkg/font"
|
||||
"github.com/ConradIrwin/font/sfnt"
|
||||
"github.com/adrg/strutil"
|
||||
"github.com/adrg/strutil/metrics"
|
||||
"github.com/adrg/sysfont"
|
||||
"github.com/flopp/go-findfont"
|
||||
"github.com/siyuan-note/logging"
|
||||
ttc "golang.org/x/image/font/sfnt"
|
||||
|
|
@ -35,54 +30,6 @@ import (
|
|||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
var (
|
||||
preferredPDFWatermarkFonts = []string{"MicrosoftYaHei", "SimSun", "ArialUnicode", "Xihei", "Heiti", "AquaHiraKaku", "AppleGothic", "Helvetica"}
|
||||
)
|
||||
|
||||
func InstallPDFFonts() string {
|
||||
names := font.UserFontNames()
|
||||
if 0 < len(names) {
|
||||
return getPreferredPDFWatermarkFont(names)
|
||||
}
|
||||
|
||||
finder := sysfont.NewFinder(&sysfont.FinderOpts{Extensions: []string{".ttf", ".ttc"}})
|
||||
var fontPaths []string
|
||||
for _, preferredFont := range preferredPDFWatermarkFonts {
|
||||
f := finder.Match(preferredFont)
|
||||
if nil != f {
|
||||
fontPaths = append(fontPaths, f.Filename)
|
||||
}
|
||||
}
|
||||
|
||||
logging.LogInfof("installing fonts [%s]", strings.Join(fontPaths, ", "))
|
||||
if err := api.InstallFonts(fontPaths); nil != err {
|
||||
logging.LogErrorf("install font [%s] failed: %s", strings.Join(fontPaths, ", "), err)
|
||||
return getPreferredPDFWatermarkFont(names)
|
||||
}
|
||||
|
||||
names = font.UserFontNames()
|
||||
return getPreferredPDFWatermarkFont(names)
|
||||
}
|
||||
|
||||
func getPreferredPDFWatermarkFont(userFontNames []string) (ret string) {
|
||||
ret = "Helvetica"
|
||||
if 1 > len(userFontNames) {
|
||||
return
|
||||
}
|
||||
|
||||
var score float64
|
||||
for _, preferredFont := range preferredPDFWatermarkFonts {
|
||||
for _, userFont := range userFontNames {
|
||||
if tmp := strutil.Similarity(preferredFont, userFont, &metrics.JaroWinkler{CaseSensitive: false}); score < tmp {
|
||||
ret = preferredFont
|
||||
score = tmp
|
||||
}
|
||||
}
|
||||
}
|
||||
logging.LogInfof("preferred PDF font [%s]", ret)
|
||||
return
|
||||
}
|
||||
|
||||
func GetSysFonts(currentLanguage string) (ret []string) {
|
||||
fonts := loadFonts(currentLanguage)
|
||||
ret = []string{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue