mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
feat(编辑渲染): 完善三维转换,优化编辑渲染压缩
This commit is contained in:
1 parent
e8344e6387
commit
839f65e3d7
47 files changed
+4887
-112
No files matched your search
+23
-19
@@ -18,6 +18,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/url"
|
||||
@@ -134,33 +135,19 @@ func (p *pdfImporter) movieAnnotation(ctx context.Context, page *pdfgo.Page, ann
|
||||
// 入参: ctx 取消上下文, page PDF页面, annotation 交互注解, strict 严格检查开关
|
||||
// 返回: error 外观、资源或不可等价转换错误
|
||||
func (p *pdfImporter) interactiveAnnotation(ctx context.Context, page *pdfgo.Page, annotation pdfgo.Annotation, strict bool) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if strict {
|
||||
return &pdfgo.UnsupportedError{Feature: "interactive " + string(annotation.Subtype) + " conversion"}
|
||||
}
|
||||
var actions []Action
|
||||
if annotation.Subtype == "3D" {
|
||||
model, err := p.reader.ReadThreeD(annotation)
|
||||
if err != nil {
|
||||
p.warning(pdfgo.Diagnostic{Page: p.page + 1, Message: "PDF 3D metadata unavailable; static appearance retained: " + err.Error()})
|
||||
return p.appearanceAnnotation(ctx, page, annotation)
|
||||
}
|
||||
data, err := model.Stream.Decode()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id, err := p.editor.AddAttachment(fmt.Sprintf("Model_%d.%s", p.page+1, strings.ToLower(string(model.Format))), data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
actions = append(actions, Action{Event: "CLICK", GotoA: &GotoA{AttachID: id}})
|
||||
return p.threeDAnnotation(ctx, page, annotation)
|
||||
} else {
|
||||
media, err := p.reader.ReadRichMedia(ctx, annotation)
|
||||
if err != nil {
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
p.warning(pdfgo.Diagnostic{Page: p.page + 1, Message: "PDF rich media metadata unavailable; static appearance retained: " + err.Error()})
|
||||
return p.appearanceAnnotation(ctx, page, annotation)
|
||||
return p.interactiveAppearanceFallback(ctx, page, annotation, "metadata", err)
|
||||
}
|
||||
config := media.Configurations[media.ActiveConfiguration]
|
||||
var playing *pdfgo.FileSpecification
|
||||
@@ -245,6 +232,23 @@ func (p *pdfImporter) interactiveAnnotation(ctx context.Context, page *pdfgo.Pag
|
||||
return nil
|
||||
}
|
||||
|
||||
// interactiveAppearanceFallback 保留交互注解的有效正常外观,取消时不继续转换
|
||||
// 入参: ctx 取消上下文, page PDF页面, annotation 交互注解, kind 失败资源类型, cause 原始错误
|
||||
// 返回: error 取消或外观转换错误
|
||||
func (p *pdfImporter) interactiveAppearanceFallback(ctx context.Context, page *pdfgo.Page, annotation pdfgo.Annotation, kind string, cause error) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if errors.Is(cause, context.Canceled) || errors.Is(cause, context.DeadlineExceeded) {
|
||||
return cause
|
||||
}
|
||||
if err := p.appearanceAnnotation(ctx, page, annotation); err != nil {
|
||||
return err
|
||||
}
|
||||
p.warning(pdfgo.Diagnostic{Page: p.page + 1, Message: fmt.Sprintf("PDF %s %s unavailable; normal appearance retained: %v", annotation.Subtype, kind, cause)})
|
||||
return nil
|
||||
}
|
||||
|
||||
// mediaData 读取媒体或附件,宽松模式缺少外部读取器时报告资源不可用
|
||||
// 入参: ctx 取消上下文, file PDF文件说明
|
||||
// 返回: []byte 原始文件, bool 是否可用, error 解码、外部读取或严格模式错误
|
||||
|
||||
Reference in new issue
Block a user