feat(前端界面): OFDGo WebUI支持设置DPI
build.yaml / build (push) Successful in 32s

This commit is contained in:
2026-07-09 14:10:25 +08:00
parent 3fab819246
commit 89577ea72f
5 changed files with 44 additions and 4 deletions
+3 -2
View File
@@ -79,7 +79,7 @@ func safeCall(fn func([]js.Value) (any, error), args []js.Value) (data any, err
// 入参: args 浏览器参数
// 返回: any 文档信息, error 错误信息
func openDocument(args []js.Value) (any, error) {
if len(args) < 3 {
if len(args) < 4 {
return nil, fmt.Errorf("missing open arguments")
}
data, err := bytesFromJS(args[0])
@@ -91,11 +91,12 @@ func openDocument(args []js.Value) (any, error) {
return nil, err
}
renderAnnotations := args[2].Bool()
dpi := args[3].Float()
if currentSession != nil {
_ = currentSession.Close()
currentSession = nil
}
session, err := Open(data, OpenOptions{Fonts: fonts, RenderAnnotations: renderAnnotations})
session, err := Open(data, OpenOptions{Fonts: fonts, DPI: dpi, RenderAnnotations: renderAnnotations})
if err != nil {
return nil, err
}
+4
View File
@@ -30,6 +30,7 @@ import (
// OpenOptions 打开OFD文档选项
type OpenOptions struct {
Fonts []FontFile
DPI float64
RenderAnnotations bool
}
@@ -186,6 +187,9 @@ func Open(data []byte, opts OpenOptions) (*Session, error) {
return nil, err
}
var rendererOptions []ofdgo.RendererOption
if opts.DPI > 0 {
rendererOptions = append(rendererOptions, ofdgo.WithDPI(opts.DPI))
}
if len(opts.Fonts) > 0 {
fontFS := ofdgo.NewFontFS(opts.Fonts)
if fontFS.Len() == 0 {