diff --git a/ofdgo_annot.go b/ofdgo_annot.go index ef72cae..426bc61 100644 --- a/ofdgo_annot.go +++ b/ofdgo_annot.go @@ -180,7 +180,7 @@ func (r *Reader) parseAnnotations(doc *Document) error { return nil } -// annotationIndex 读取注解文件索引,不解析页面外观 +// annotationIndex 读取注解索引,将页引用对应到文档声明的标识,不解析页面外观 // 入参: doc 文档结构 // 返回: Annotations 注解索引, error 错误信息 func (r *Reader) annotationIndex(doc *Document) (Annotations, error) { @@ -197,8 +197,18 @@ func (r *Reader) annotationIndex(doc *Document) (Annotations, error) { if err := xml.NewDecoder(f).Decode(&annotations); err != nil { return Annotations{}, err } + pageIDs := make(map[string]string, len(doc.Pages.Page)) + for _, page := range doc.Pages.Page { + if id := editorResourceID(page.ID); id != "" { + pageIDs[id] = page.ID + } + } r.annotationFiles = make(map[string][]string) - for _, page := range annotations.Page { + for i := range annotations.Page { + page := &annotations.Page[i] + if id := pageIDs[editorResourceID(page.PageID)]; id != "" { + page.PageID = id + } annotPath := resolveResourcePath(annPath, "", page.FileLoc) if file, ok := r.packageFile(annotPath); ok { annotPath = cleanPackagePath(file.Name) diff --git a/ofdgo_editor_annot.go b/ofdgo_editor_annot.go index 5093fc4..47789ba 100644 --- a/ofdgo_editor_annot.go +++ b/ofdgo_editor_annot.go @@ -180,12 +180,13 @@ func (e *Editor) editAnnotations(index int, ids []string, edit func([]byte, *edi var patches []editorXMLPatch found := make(map[string]bool, len(ids)) remaining := 0 + pageID := editorResourceID(e.pages[index].ID) for _, ref := range root.children { if !ref.matchesOFD("Page") { continue } remaining++ - if ref.attr("PageID") != e.pages[index].ID { + if pageID == "" || editorResourceID(ref.attr("PageID")) != pageID { continue } loc := ref.child("FileLoc") diff --git a/ofdgo_editor_annot_content.go b/ofdgo_editor_annot_content.go index c7d6052..daeeaa7 100644 --- a/ofdgo_editor_annot_content.go +++ b/ofdgo_editor_annot_content.go @@ -175,8 +175,9 @@ func (e *Editor) annotationXML(index int, id string) ([]byte, error) { return nil, err } var result []byte + pageID := editorResourceID(e.pages[index].ID) for _, ref := range root.children { - if !ref.matchesOFD("Page") || ref.attr("PageID") != e.pages[index].ID || ref.child("FileLoc") == nil { + if !ref.matchesOFD("Page") || pageID == "" || editorResourceID(ref.attr("PageID")) != pageID || ref.child("FileLoc") == nil { continue } file, err := editorPageLocation(reader, nil, name, strings.TrimSpace(editorImportText(data, ref.child("FileLoc")))) @@ -247,8 +248,9 @@ func (e *Editor) appendAnnotations(index int, annotations []byte, generated bool if err != nil { return err } + pageID := editorResourceID(e.pages[index].ID) for _, item := range root.children { - if item.matchesOFD("Page") && item.attr("PageID") == e.pages[index].ID { + if item.matchesOFD("Page") && pageID != "" && editorResourceID(item.attr("PageID")) == pageID { ref = item loc := item.child("FileLoc") if loc == nil { @@ -363,18 +365,19 @@ func (e *Editor) annotationFiles() []string { } removed := make(map[string]bool) for id := range e.source.pages { - removed[id] = true + removed[editorResourceID(id)] = true } for id := range e.source.annotationPages { - removed[id] = true + removed[editorResourceID(id)] = true } for _, page := range e.pages { - delete(removed, page.ID) + delete(removed, editorResourceID(page.ID)) } + delete(removed, "") var files []string for name, pages := range e.source.reader.annotationFiles { for _, page := range pages { - if !removed[page] { + if !removed[editorResourceID(page)] { files = append(files, name) break }