feat(渲染转换): 完善字体转换与链接动作
build.yaml / build (push) Successful in 53s

This commit is contained in:
xiaoqidun committed 2026-10-02 23:38:43 +08:00
1 parent 1104f0fdd1
commit 012569dbc0
15 files changed
+390 -50

No files matched your search

+28 -23
View File
@@ -120,27 +120,15 @@ func (p *pdfImporter) annotations(ctx context.Context, page *pdfgo.Page, strict
if err != nil {
return err
}
var data []byte
format := "WAV"
if sound.File != nil {
var available bool
data, available, err = p.mediaData(ctx, *sound.File)
if err == nil && !available {
if err := p.appearanceAnnotation(ctx, page, annotation); err != nil {
return err
}
continue
id, err := p.soundResource(ctx, sound)
if err != nil {
return err
}
if id == "" {
if err := p.appearanceAnnotation(ctx, page, annotation); err != nil {
return err
}
format = pdfMediaFormat(*sound.File)
} else {
data, err = pdfSoundWAV(sound)
}
if err != nil {
return err
}
id, err := p.editor.AddMedia("Audio", format, data)
if err != nil {
return err
continue
}
if err := p.appearanceAnnotation(ctx, page, annotation, Action{Event: "CLICK", Sound: &Sound{ResourceID: id}}); err != nil {
return err
@@ -180,7 +168,7 @@ func (p *pdfImporter) annotations(ctx context.Context, page *pdfgo.Page, strict
}
continue
}
id, err := p.editor.AddAttachment(file.Name, data)
id, err := p.attachmentFile(file.Name, data)
if err != nil {
return err
}
@@ -340,14 +328,31 @@ func (p *pdfImporter) linkAction(annotation pdfgo.Annotation, strict bool, curre
if !ok {
return nil, fmt.Errorf("invalid PDF link action")
}
switch a["S"] {
kind, err := p.reader.Resolve(a["S"])
if err != nil {
return nil, err
}
switch kind {
case pdfgo.Name("GoTo"):
target = a["D"]
case pdfgo.Name("GoToR"):
return p.remoteLinkAction(a, strict)
case pdfgo.Name("Sound"):
return p.soundLinkAction(a, strict)
case pdfgo.Name("GoToE"):
converted, local, err := p.embeddedLinkAction(a, strict)
if err != nil || local == nil {
return converted, err
}
target = local
case pdfgo.Name("Named"):
value, err := p.reader.Resolve(a["N"])
if err != nil {
return nil, err
}
if _, ok := value.(pdfgo.Name); !ok {
return nil, fmt.Errorf("invalid PDF named action")
}
index := *currentPage
switch value {
case pdfgo.Name("FirstPage"):
@@ -359,7 +364,7 @@ func (p *pdfImporter) linkAction(annotation pdfgo.Annotation, strict bool, curre
case pdfgo.Name("PrevPage"):
index = max(index-1, 0)
default:
return nil, &pdfgo.UnsupportedError{Feature: "named link action"}
return nil, nil
}
action.Goto = &Goto{Dest: &Dest{Type: "XYZ", PageID: p.editor.pages[index].ID, OmitLeft: true, OmitTop: true, OmitZoom: true}}
*currentPage = index