mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 12:57:45 +08:00
1 parent
eb20f66ffb
commit
075797402d
41 files changed
+633
-125
No files matched your search
+10
-3
@@ -419,6 +419,7 @@ type outputContext struct {
|
||||
|
||||
// businessEngine 独立文档、编辑、剪贴板及操作上下文
|
||||
type businessEngine struct {
|
||||
resources *ofdgo.Resources
|
||||
currentSession *Session
|
||||
currentEditor *ofdgo.Editor
|
||||
saveSnapshot *ofdgo.Editor
|
||||
@@ -1396,7 +1397,7 @@ func (e *businessEngine) convertPDFDocument(args []platformValue) (any, error) {
|
||||
return nil, err
|
||||
}
|
||||
var output bytes.Buffer
|
||||
options := ofdgo.PDFImportOptions{OnProgress: e.editorOperationProgress(args[4]), PasswordUTF8: true}
|
||||
options := ofdgo.PDFImportOptions{Resources: e.resources, OnProgress: e.editorOperationProgress(args[4]), PasswordUTF8: true}
|
||||
if !args[2].IsNull() && !args[2].IsUndefined() {
|
||||
options.Password, err = e.bytesFromJS(args[2])
|
||||
if err != nil {
|
||||
@@ -1450,7 +1451,8 @@ func (e *businessEngine) convertFile(args []platformValue) (any, error) {
|
||||
return nil, err
|
||||
}
|
||||
options := ofdgo.ConvertOptions{
|
||||
Format: settings.Get("format").String(), PageRange: settings.Get("pages").String(),
|
||||
Resources: e.resources,
|
||||
Format: settings.Get("format").String(), PageRange: settings.Get("pages").String(),
|
||||
Pool: e.conversionPool,
|
||||
SkipUnchanged: true,
|
||||
Backends: &backends,
|
||||
@@ -1608,7 +1610,7 @@ func (e *businessEngine) openDocument(args []platformValue) (any, error) {
|
||||
return nil, err
|
||||
}
|
||||
renderAnnotations := args[2].Bool()
|
||||
options := OpenOptions{Fonts: fonts, RenderAnnotations: renderAnnotations}
|
||||
options := OpenOptions{Fonts: fonts, RenderAnnotations: renderAnnotations, ReaderOptions: []ofdgo.ReaderOption{ofdgo.WithResources(e.resources)}}
|
||||
if len(args) > 3 && !args[3].IsNull() && !args[3].IsUndefined() {
|
||||
credentials, err := e.credentialsFromJS(args[3])
|
||||
if err != nil {
|
||||
@@ -4047,6 +4049,7 @@ func (e *businessEngine) previewText(args []platformValue) (any, error) {
|
||||
return nil, err
|
||||
}
|
||||
editor = ofdgo.NewEditor()
|
||||
editor.SetResources(e.resources)
|
||||
fontID, err = editor.AddFont(FontFile{Data: data}, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -5568,6 +5571,7 @@ func (e *businessEngine) loadImport(args []platformValue) (any, error) {
|
||||
}
|
||||
}()
|
||||
var options []ofdgo.ReaderOption
|
||||
options = append(options, ofdgo.WithResources(e.resources))
|
||||
if len(args) > 1 && !args[1].IsNull() && !args[1].IsUndefined() {
|
||||
credentials, err := e.credentialsFromJS(args[1])
|
||||
if err != nil {
|
||||
@@ -5685,6 +5689,7 @@ func (e *businessEngine) importImages(args []platformValue) (any, error) {
|
||||
editor := e.currentEditor
|
||||
if at < 0 {
|
||||
editor = ofdgo.NewEditor()
|
||||
editor.SetResources(e.resources)
|
||||
editor.Info.Title = args[3].String()
|
||||
} else if editor == nil {
|
||||
return nil, fmt.Errorf("document is not editable")
|
||||
@@ -5721,6 +5726,7 @@ func (e *businessEngine) importImages(args []platformValue) (any, error) {
|
||||
func (e *businessEngine) createDocument(args []platformValue) (any, error) {
|
||||
e.clearImport()
|
||||
editor := ofdgo.NewEditor()
|
||||
editor.SetResources(e.resources)
|
||||
editor.Info.Title = args[0].String()
|
||||
if _, err := editor.AddPage(args[1].Float(), args[2].Float()); err != nil {
|
||||
return nil, err
|
||||
@@ -7124,6 +7130,7 @@ func (e *businessEngine) previewSignatureSeal(args []platformValue) (any, error)
|
||||
pages = append(pages, map[string]any{"index": index, "x": box.X, "y": box.Y, "width": box.W, "height": box.H})
|
||||
}
|
||||
editor := ofdgo.NewEditor()
|
||||
editor.SetResources(e.resources)
|
||||
if _, err := editor.AddPage(seal.Width, seal.Height); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ type NativeOutputTarget struct {
|
||||
// hooks应在首次Call前配置,Resolve返回的资源需保持有效直到相应会话关闭
|
||||
type NativeEngine struct {
|
||||
businessEngine
|
||||
// Resources 协调会话的计算与缓存,需在首次Call前配置
|
||||
Resources *ofdgo.Resources
|
||||
// ConversionPool 协调不同会话的批量转换资源
|
||||
ConversionPool *ofdgo.ConversionPool
|
||||
// RenderParallelism 限制同时渲染的页面数,零值使用可用处理器数
|
||||
@@ -152,6 +154,7 @@ func (e *NativeEngine) Call(ctx context.Context, name string, args []any, emit f
|
||||
e.renderSlots = make(chan struct{}, e.renderParallelism())
|
||||
e.resolveInput = e.input
|
||||
e.conversionPool = e.ConversionPool
|
||||
e.resources = e.Resources
|
||||
})
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
@@ -163,6 +166,13 @@ func (e *NativeEngine) Call(ctx context.Context, name string, args []any, emit f
|
||||
case <-ctx.Done():
|
||||
return nativeFailure(ctx.Err())
|
||||
}
|
||||
if e.resources != nil {
|
||||
release, err := e.resources.Acquire(ctx, 64<<20)
|
||||
if err != nil {
|
||||
return nativeFailure(err)
|
||||
}
|
||||
defer release()
|
||||
}
|
||||
}
|
||||
select {
|
||||
case e.gate <- struct{}{}:
|
||||
|
||||
@@ -39,7 +39,8 @@ type platformValue = js.Value
|
||||
|
||||
// RunWASM 注册浏览器WASM接口并阻塞运行
|
||||
func RunWASM() {
|
||||
e := &businessEngine{}
|
||||
resources, _ := ofdgo.NewResources(ofdgo.ResourceOptions{Parallelism: 1, MemoryLimit: 64 << 20, CacheBytes: 48 << 20, SnapshotBytes: 32 << 20})
|
||||
e := &businessEngine{resources: resources}
|
||||
asynchronous := map[string]bool{
|
||||
"ofdgoDetectFormat": true,
|
||||
"ofdgoExportVersion": true,
|
||||
|
||||
Reference in new issue
Block a user