mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 17:27:08 +08:00
1 parent
8de701dbd4
commit
d37f41cd90
21 files changed
+280
-57
No files matched your search
+24
-1
@@ -184,6 +184,7 @@ func (r *browserReaderAt) ReadAt(data []byte, offset int64) (int, error) {
|
||||
// RunWASM 注册浏览器WASM接口并阻塞运行
|
||||
func RunWASM() {
|
||||
registerCallback("ofdgoOpen", openDocument)
|
||||
registerCallback("ofdgoSelectDocument", selectDocument)
|
||||
registerAsyncCallback("ofdgoConvertPDF", convertPDFDocument)
|
||||
registerAsyncCallback("ofdgoConvertFile", convertFile)
|
||||
registerAsyncCallback("ofdgoPackFiles", packFiles)
|
||||
@@ -3359,6 +3360,27 @@ func changeAttachment(args []js.Value) (any, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// selectDocument 切换包内文档,保留编辑快照并清除跨文档剪贴板
|
||||
// 入参: args 文档索引
|
||||
// 返回: any 文档信息, error 错误信息
|
||||
func selectDocument(args []js.Value) (any, error) {
|
||||
if currentSession == nil || len(args) == 0 {
|
||||
return nil, fmt.Errorf("ofd document is not opened")
|
||||
}
|
||||
session, err := currentSession.Document(args[0].Int())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = currentSession.Close()
|
||||
currentSession, currentEditor = session, session.editor
|
||||
if pendingImport != nil {
|
||||
_ = pendingImport.Close()
|
||||
pendingImport = nil
|
||||
}
|
||||
copiedObjects, copiedStyle = nil, nil
|
||||
return editorSummary(), nil
|
||||
}
|
||||
|
||||
// editDocument 将已打开文档接入编辑器,沿用页面、资源及字体配置
|
||||
// 入参: args 当前页索引,省略时使用首页
|
||||
// 返回: any 编辑状态, error 错误信息
|
||||
@@ -3367,6 +3389,7 @@ func editDocument(args []js.Value) (any, error) {
|
||||
return nil, fmt.Errorf("ofd document is not opened")
|
||||
}
|
||||
if currentEditor != nil {
|
||||
currentSession.editing = true
|
||||
return editorSummary(), nil
|
||||
}
|
||||
editor, err := currentSession.Reader.Editor()
|
||||
@@ -3952,7 +3975,7 @@ func verifySignatures(args []js.Value) (any, error) {
|
||||
Certificates: append(files["certificates"], files["roots"]...), Required: policy.RequireRevocation, VerifyTime: &now,
|
||||
}))
|
||||
}
|
||||
reports, err := currentSession.Reader.VerifySignatures(options...)
|
||||
reports, err := currentSession.Reader.VerifyDocumentSignatures(currentSession.Reader.DocumentIndex(), options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+52
-1
@@ -72,6 +72,8 @@ type pageBoxInfo struct {
|
||||
|
||||
// DocumentInfo 文档信息
|
||||
type DocumentInfo struct {
|
||||
DocumentIndex int `json:"documentIndex"`
|
||||
Documents []DocumentEntry `json:"documents,omitempty"`
|
||||
Encryption EncryptionInfo `json:"encryption"`
|
||||
Version string `json:"version"`
|
||||
DocType string `json:"docType"`
|
||||
@@ -96,6 +98,12 @@ type DocumentInfo struct {
|
||||
DetailsPending bool `json:"detailsPending,omitempty"`
|
||||
}
|
||||
|
||||
// DocumentEntry 包内文档入口,不预先解析其他文档的页面和资源
|
||||
type DocumentEntry struct {
|
||||
Index int `json:"index"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// DocumentDetails 不含页面数组的文档补充信息
|
||||
type DocumentDetails struct {
|
||||
FontCount int `json:"fontCount"`
|
||||
@@ -287,6 +295,45 @@ func (s *Session) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Document 创建指定文档的会话,保留编辑内容和字体配置,不复用页面缓存
|
||||
// 不关闭原会话,输入文件的生命周期由原会话管理
|
||||
// 入参: index 文档索引,从0开始
|
||||
// 返回: *Session 文档会话, error 错误信息
|
||||
func (s *Session) Document(index int) (*Session, error) {
|
||||
reader := s.Reader
|
||||
if s.editor != nil {
|
||||
var err error
|
||||
reader, err = s.editor.Reader()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
reader, err := reader.Document(index)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
next, err := newSession(reader, OpenOptions{RenderAnnotations: s.Renderer.RenderAnnotations})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ofdgo.WithRenderBackends(s.Renderer.Backends())(next.Renderer)
|
||||
next.fontFS = s.fontFS
|
||||
if next.fontFS != nil {
|
||||
next.Renderer.SetFontFS(next.fontFS)
|
||||
}
|
||||
next.editor, err = reader.Editor()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
next.editor.SetHistoryLimit(100)
|
||||
if next.fontFS != nil {
|
||||
next.editor.SetFontFS(next.fontFS)
|
||||
}
|
||||
next.editor.SetRenderBackends(next.Renderer.Backends())
|
||||
next.editing = true
|
||||
return next, nil
|
||||
}
|
||||
|
||||
// SetFonts 更新字体配置并保留文档、页面和验签结果
|
||||
// 入参: fonts 字体文件列表
|
||||
// 返回: error 错误信息
|
||||
@@ -376,6 +423,7 @@ func (s *Session) SearchPage(index int, query string) ([]ofdgo.TextMatch, error)
|
||||
// 返回: DocumentInfo 文档信息
|
||||
func (s *Session) Summary() DocumentInfo {
|
||||
info := DocumentInfo{
|
||||
DocumentIndex: s.Reader.DocumentIndex(),
|
||||
Encryption: s.encryptionInfo(),
|
||||
Version: s.Reader.Version(),
|
||||
DocType: s.Reader.DocType(),
|
||||
@@ -384,6 +432,9 @@ func (s *Session) Summary() DocumentInfo {
|
||||
Outlines: s.doc.OutlineInfos(),
|
||||
DetailsPending: true,
|
||||
}
|
||||
for index, body := range s.Reader.OFD.DocBody {
|
||||
info.Documents = append(info.Documents, DocumentEntry{Index: index, Title: body.DocInfo.Title})
|
||||
}
|
||||
if docInfo, err := s.Reader.DocInfo(); err == nil && docInfo != nil {
|
||||
info.Title = docInfo.Title
|
||||
info.Author = docInfo.Author
|
||||
@@ -788,7 +839,7 @@ func (s *Session) signatureInfos() ([]SignatureInfo, error) {
|
||||
return s.signatures, s.signatureError
|
||||
}
|
||||
s.signaturesRead = true
|
||||
reports, err := s.Reader.VerifySignatures()
|
||||
reports, err := s.Reader.VerifyDocumentSignatures(s.Reader.DocumentIndex())
|
||||
if err != nil {
|
||||
s.signatureError = err
|
||||
return nil, err
|
||||
|
||||
Reference in new issue
Block a user