mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 16:44:23 +08:00
1 parent
996f8f9518
commit
07eb44c037
5 files changed
+60
-14
No files matched your search
+20
-6
@@ -960,7 +960,7 @@ func linkResults(source []ofdgo.PageLink) ([]any, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if dest := link.Dest; dest != nil {
|
if dest := link.Dest; dest != nil {
|
||||||
item["dest"] = map[string]any{"type": dest.Type, "pageID": dest.PageID, "left": dest.Left, "top": dest.Top,
|
item["dest"] = map[string]any{"type": dest.Type, "pageID": resolvedPageID(dest.PageID), "left": dest.Left, "top": dest.Top,
|
||||||
"right": dest.Right, "bottom": dest.Bottom, "zoom": dest.Zoom,
|
"right": dest.Right, "bottom": dest.Bottom, "zoom": dest.Zoom,
|
||||||
"omitLeft": dest.OmitLeft, "omitTop": dest.OmitTop, "omitZoom": dest.OmitZoom}
|
"omitLeft": dest.OmitLeft, "omitTop": dest.OmitTop, "omitZoom": dest.OmitZoom}
|
||||||
}
|
}
|
||||||
@@ -969,6 +969,18 @@ func linkResults(source []ofdgo.PageLink) ([]any, error) {
|
|||||||
return links, nil
|
return links, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolvedPageID 将跳转目标转换为界面页面列表中的标识,未找到时保留原值
|
||||||
|
// 入参: id 目标页面标识
|
||||||
|
// 返回: string 页面列表标识或原值
|
||||||
|
func resolvedPageID(id string) string {
|
||||||
|
if currentSession != nil {
|
||||||
|
if index := currentSession.doc.PageIndex(id); index >= 0 {
|
||||||
|
return currentSession.doc.Pages.Page[index].ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
// pageTextString 提取OFD页面原文
|
// pageTextString 提取OFD页面原文
|
||||||
// 入参: args 页面索引
|
// 入参: args 页面索引
|
||||||
// 返回: any 页面原文, error 错误信息
|
// 返回: any 页面原文, error 错误信息
|
||||||
@@ -1513,11 +1525,8 @@ func readAnnotation(args []js.Value) (any, error) {
|
|||||||
info["linkKind"], info["linkURI"], info["linkBase"] = "uri", link.URI.URI, link.URI.Base
|
info["linkKind"], info["linkURI"], info["linkBase"] = "uri", link.URI.URI, link.URI.Base
|
||||||
info["linkTarget"] = link.URI.Target
|
info["linkTarget"] = link.URI.Target
|
||||||
} else if err == nil && link.Goto != nil && link.Goto.Dest != nil {
|
} else if err == nil && link.Goto != nil && link.Goto.Dest != nil {
|
||||||
for i, page := range currentSession.doc.Pages.Page {
|
if index := currentSession.doc.PageIndex(link.Goto.Dest.PageID); index >= 0 {
|
||||||
if page.ID == link.Goto.Dest.PageID {
|
info["linkKind"], info["linkPage"] = "page", index+1
|
||||||
info["linkKind"], info["linkPage"] = "page", i+1
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1815,6 +1824,11 @@ func editorAppearance(item map[string]any, object ofdgo.GraphicObject, paint boo
|
|||||||
for _, action := range object.Actions() {
|
for _, action := range object.Actions() {
|
||||||
if action.Event == "CLICK" && (action.URI != nil || action.Goto != nil) {
|
if action.Event == "CLICK" && (action.URI != nil || action.Goto != nil) {
|
||||||
links++
|
links++
|
||||||
|
if action.Goto != nil && action.Goto.Dest != nil {
|
||||||
|
gotoAction, dest := *action.Goto, *action.Goto.Dest
|
||||||
|
dest.PageID = resolvedPageID(dest.PageID)
|
||||||
|
gotoAction.Dest, action.Goto = &dest, &gotoAction
|
||||||
|
}
|
||||||
if data, err := json.Marshal(action); err == nil {
|
if data, err := json.Marshal(action); err == nil {
|
||||||
item["link"] = string(data)
|
item["link"] = string(data)
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-1
@@ -201,6 +201,36 @@ type print struct {
|
|||||||
Copies *int `xml:"Copies,attr"`
|
Copies *int `xml:"Copies,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PageIndex 按标识查找页面,优先匹配原文和标准十进制写法,等价编号有歧义时不匹配
|
||||||
|
// 入参: id 页面标识
|
||||||
|
// 返回: int 从0开始的页面索引,未找到时为-1
|
||||||
|
func (doc *Document) PageIndex(id string) int {
|
||||||
|
if doc == nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
index, key := -1, editorResourceID(id)
|
||||||
|
for i, page := range doc.Pages.Page {
|
||||||
|
if page.ID == id {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
if key != "" && page.ID == key {
|
||||||
|
index = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if index >= 0 || key == "" {
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
for i, page := range doc.Pages.Page {
|
||||||
|
if editorResourceID(page.ID) == key {
|
||||||
|
if index >= 0 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
index = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
|
||||||
// OutlineInfos 获取目录层级和目标页码
|
// OutlineInfos 获取目录层级和目标页码
|
||||||
// 返回: []OutlineInfo 目录节点信息
|
// 返回: []OutlineInfo 目录节点信息
|
||||||
func (doc *Document) OutlineInfos() []OutlineInfo {
|
func (doc *Document) OutlineInfos() []OutlineInfo {
|
||||||
@@ -342,7 +372,7 @@ func outlineInfos(outlines []OutlineElem, bookmarks map[string]Dest, pages map[s
|
|||||||
for _, action := range outline.Actions {
|
for _, action := range outline.Actions {
|
||||||
if action.Goto != nil {
|
if action.Goto != nil {
|
||||||
if dest := gotoDest(action.Goto, bookmarks); dest != nil {
|
if dest := gotoDest(action.Goto, bookmarks); dest != nil {
|
||||||
info.Page = pages[dest.PageID]
|
info.Page, _ = resourceValue(pages, dest.PageID)
|
||||||
if info.Page != 0 {
|
if info.Page != 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -462,9 +462,9 @@ func (e *Editor) withOutlines(data []byte) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
valid := make(map[string]bool, len(e.pages))
|
valid := make(map[string]int, len(e.pages))
|
||||||
for _, page := range e.pages {
|
for i, page := range e.pages {
|
||||||
valid[page.ID] = true
|
valid[page.ID] = i
|
||||||
}
|
}
|
||||||
var removals []editorXMLPatch
|
var removals []editorXMLPatch
|
||||||
var walk func(*editorXML)
|
var walk func(*editorXML)
|
||||||
@@ -475,8 +475,10 @@ func (e *Editor) withOutlines(data []byte) ([]byte, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if target := action.child("Goto"); target != nil {
|
if target := action.child("Goto"); target != nil {
|
||||||
if dest := target.child("Dest"); dest != nil && !valid[dest.attr("PageID")] {
|
if dest := target.child("Dest"); dest != nil {
|
||||||
removals = append(removals, editorXMLPatch{action.start, action.end, nil})
|
if _, ok := resourceValue(valid, dest.attr("PageID")); !ok {
|
||||||
|
removals = append(removals, editorXMLPatch{action.start, action.end, nil})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ func (r *Renderer) imageObjectResource(object ImageObject) (image.Image, error)
|
|||||||
return img, err
|
return img, err
|
||||||
}
|
}
|
||||||
img, err := read(object.ResourceID)
|
img, err := read(object.ResourceID)
|
||||||
if err == nil || object.Substitution == "" || object.Substitution == object.ResourceID {
|
if err == nil || object.Substitution == "" || sameResourceID(object.Substitution, object.ResourceID) {
|
||||||
return img, err
|
return img, err
|
||||||
}
|
}
|
||||||
if r.pageContext != nil && r.pageContext.Err() != nil {
|
if r.pageContext != nil && r.pageContext.Err() != nil {
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ func (n *pdfNavigation) actionTarget(action Action, page int, source actionSourc
|
|||||||
if dest == nil {
|
if dest == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
target, ok := pageIndex[dest.PageID]
|
target, ok := resourceValue(pageIndex, dest.PageID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user