mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 13:56:32 +08:00
1 parent
b3c4bbc844
commit
961bc52038
43 files changed
+2283
-2594
No files matched your search
@@ -19,6 +19,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"maps"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
@@ -43,6 +44,12 @@ type PDFThreeDRenderOptions struct {
|
||||
Time float64
|
||||
}
|
||||
|
||||
// pdfThreeDMarkupState 复用同页批注的宿主解析及模型校验,不保留模型解码缓冲
|
||||
type pdfThreeDMarkupState struct {
|
||||
sources map[pdfgo.Reference]pdfgo.ThreeD
|
||||
sums map[*pdfgo.Stream][16]byte
|
||||
}
|
||||
|
||||
// threeDAnnotation 按非交互呈现规则处理激活状态,保留原始模型与附件动作
|
||||
// 入参: ctx 取消上下文, page PDF页面, annotation 三维注解
|
||||
// 返回: error 外观、资源或取消错误
|
||||
@@ -191,3 +198,57 @@ func RenderPDFThreeD(ctx context.Context, model *U3DModel, source pdfgo.ThreeD,
|
||||
ResolveTexture: options.ResolveTexture, Nodes: options.Nodes, Time: options.Time,
|
||||
})
|
||||
}
|
||||
|
||||
// threeDMarkupAnnotation 应用默认三维视图的批注可见性,其他视图批注保留为隐藏注解
|
||||
// 入参: ctx 取消上下文, annotation 批注, markup 关联, state 同页缓存, strict 严格检查开关
|
||||
// 返回: pdfgo.Annotation 静态批注, error 关联、校验或取消错误
|
||||
func (p *pdfImporter) threeDMarkupAnnotation(ctx context.Context, annotation pdfgo.Annotation, markup *pdfgo.ThreeDMarkup, state *pdfThreeDMarkupState, strict bool) (pdfgo.Annotation, error) {
|
||||
if markup == nil {
|
||||
return annotation, nil
|
||||
}
|
||||
if strict {
|
||||
return annotation, &pdfgo.UnsupportedError{Feature: "3D markup view switching conversion"}
|
||||
}
|
||||
source, ok := state.sources[markup.Annotation.Reference]
|
||||
if !ok || markup.Annotation.Reference == (pdfgo.Reference{}) {
|
||||
var err error
|
||||
source, err = p.reader.ReadThreeDContext(ctx, markup.Annotation)
|
||||
if err != nil {
|
||||
return annotation, err
|
||||
}
|
||||
if markup.Annotation.Reference != (pdfgo.Reference{}) {
|
||||
if state.sources == nil {
|
||||
state.sources = make(map[pdfgo.Reference]pdfgo.ThreeD)
|
||||
}
|
||||
state.sources[markup.Annotation.Reference] = source
|
||||
}
|
||||
}
|
||||
if markup.Checksum != nil {
|
||||
sum, ok := state.sums[source.Stream]
|
||||
if !ok {
|
||||
var err error
|
||||
sum, err = pdfgo.ThreeDArtworkChecksum(ctx, source.Stream)
|
||||
if err != nil {
|
||||
return annotation, err
|
||||
}
|
||||
if state.sums == nil {
|
||||
state.sums = make(map[*pdfgo.Stream][16]byte)
|
||||
}
|
||||
state.sums[source.Stream] = sum
|
||||
}
|
||||
if sum != *markup.Checksum {
|
||||
p.warning(pdfgo.Diagnostic{Page: p.page + 1, Message: "PDF 3D markup artwork checksum differs; view association may be stale"})
|
||||
}
|
||||
}
|
||||
visible := source.ActivationPolicy.Activation != "XA" && markup.MatchesView(source.SelectedView)
|
||||
if !visible {
|
||||
flags, err := p.reader.ReadAnnotationFlags(annotation)
|
||||
if err != nil {
|
||||
return annotation, err
|
||||
}
|
||||
annotation.Dictionary = maps.Clone(annotation.Dictionary)
|
||||
annotation.Dictionary["F"] = pdfgo.Integer(flags | 2)
|
||||
}
|
||||
p.warning(pdfgo.Diagnostic{Page: p.page + 1, Message: "PDF 3D markup default view visibility applied; view switching not transferred"})
|
||||
return annotation, ctx.Err()
|
||||
}
|
||||
Reference in new issue
Block a user