mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 14:53:44 +08:00
1 parent
26568927e5
commit
2d46e6f0ba
3 files changed
+23
-9
No files matched your search
+12
-2
@@ -180,7 +180,7 @@ func (r *Reader) parseAnnotations(doc *Document) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// annotationIndex 读取注解文件索引,不解析页面外观
|
// annotationIndex 读取注解索引,将页引用对应到文档声明的标识,不解析页面外观
|
||||||
// 入参: doc 文档结构
|
// 入参: doc 文档结构
|
||||||
// 返回: Annotations 注解索引, error 错误信息
|
// 返回: Annotations 注解索引, error 错误信息
|
||||||
func (r *Reader) annotationIndex(doc *Document) (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 {
|
if err := xml.NewDecoder(f).Decode(&annotations); err != nil {
|
||||||
return Annotations{}, err
|
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)
|
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)
|
annotPath := resolveResourcePath(annPath, "", page.FileLoc)
|
||||||
if file, ok := r.packageFile(annotPath); ok {
|
if file, ok := r.packageFile(annotPath); ok {
|
||||||
annotPath = cleanPackagePath(file.Name)
|
annotPath = cleanPackagePath(file.Name)
|
||||||
|
|||||||
@@ -180,12 +180,13 @@ func (e *Editor) editAnnotations(index int, ids []string, edit func([]byte, *edi
|
|||||||
var patches []editorXMLPatch
|
var patches []editorXMLPatch
|
||||||
found := make(map[string]bool, len(ids))
|
found := make(map[string]bool, len(ids))
|
||||||
remaining := 0
|
remaining := 0
|
||||||
|
pageID := editorResourceID(e.pages[index].ID)
|
||||||
for _, ref := range root.children {
|
for _, ref := range root.children {
|
||||||
if !ref.matchesOFD("Page") {
|
if !ref.matchesOFD("Page") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
remaining++
|
remaining++
|
||||||
if ref.attr("PageID") != e.pages[index].ID {
|
if pageID == "" || editorResourceID(ref.attr("PageID")) != pageID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
loc := ref.child("FileLoc")
|
loc := ref.child("FileLoc")
|
||||||
|
|||||||
@@ -175,8 +175,9 @@ func (e *Editor) annotationXML(index int, id string) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var result []byte
|
var result []byte
|
||||||
|
pageID := editorResourceID(e.pages[index].ID)
|
||||||
for _, ref := range root.children {
|
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
|
continue
|
||||||
}
|
}
|
||||||
file, err := editorPageLocation(reader, nil, name, strings.TrimSpace(editorImportText(data, ref.child("FileLoc"))))
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
pageID := editorResourceID(e.pages[index].ID)
|
||||||
for _, item := range root.children {
|
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
|
ref = item
|
||||||
loc := item.child("FileLoc")
|
loc := item.child("FileLoc")
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
@@ -363,18 +365,19 @@ func (e *Editor) annotationFiles() []string {
|
|||||||
}
|
}
|
||||||
removed := make(map[string]bool)
|
removed := make(map[string]bool)
|
||||||
for id := range e.source.pages {
|
for id := range e.source.pages {
|
||||||
removed[id] = true
|
removed[editorResourceID(id)] = true
|
||||||
}
|
}
|
||||||
for id := range e.source.annotationPages {
|
for id := range e.source.annotationPages {
|
||||||
removed[id] = true
|
removed[editorResourceID(id)] = true
|
||||||
}
|
}
|
||||||
for _, page := range e.pages {
|
for _, page := range e.pages {
|
||||||
delete(removed, page.ID)
|
delete(removed, editorResourceID(page.ID))
|
||||||
}
|
}
|
||||||
|
delete(removed, "")
|
||||||
var files []string
|
var files []string
|
||||||
for name, pages := range e.source.reader.annotationFiles {
|
for name, pages := range e.source.reader.annotationFiles {
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
if !removed[page] {
|
if !removed[editorResourceID(page)] {
|
||||||
files = append(files, name)
|
files = append(files, name)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user