feat(渲染注释): 渲染注释,可配置不渲染

This commit is contained in:
2026-06-26 11:26:09 +08:00
parent 1446705bb6
commit 94fa027446
8 changed files with 283 additions and 19 deletions
+58 -4
View File
@@ -38,15 +38,69 @@ type Annotations struct {
// AnnPage 页面注释引用
type AnnPage struct {
PageID string `xml:"PageID,attr"`
Annotation []Annotation `xml:"Annotation"`
PageID string `xml:"PageID,attr"`
FileLoc string `xml:"FileLoc"`
}
// Annotation 注释定义
// PageAnnot 页面注释集合
type PageAnnot struct {
XMLName xml.Name `xml:"PageAnnot"`
Annot []Annotation `xml:"Annot"`
}
// Annotation 页面注释
type Annotation struct {
ID string `xml:"ID,attr"`
Type string `xml:"Type,attr"`
Subtype string `xml:"Subtype,attr"`
Creator string `xml:"Creator,attr"`
LastModDate string `xml:"LastModDate,attr"`
Loc string `xml:"Loc,attr"`
Appearance Appearance
}
// Appearance 注释外观
type Appearance struct {
Boundary string `xml:"Boundary,attr"`
Objects []GraphicObject `xml:"-"`
TextObject []TextObject `xml:"TextObject"`
PathObject []PathObject `xml:"PathObject"`
ImageObject []ImageObject `xml:"ImageObject"`
CompositeGraphicUnit []CompositeGraphicUnit `xml:"CompositeGraphicUnit"`
}
// parseAnnotations 解析注释文件
// 入参: doc 文档结构
// 返回: error 错误信息
func (r *Reader) parseAnnotations(doc *Document) error {
if doc.Annotations == "" {
return nil
}
annPath := r.ResPath(doc.Annotations)
f, err := r.openFile(annPath)
if err != nil {
return err
}
defer f.Close()
var annotations Annotations
if err := xml.NewDecoder(f).Decode(&annotations); err != nil {
return err
}
if r.Annots == nil {
r.Annots = make(map[string][]Annotation)
}
for _, page := range annotations.Page {
annotPath := resolveResourcePath(annPath, "", page.FileLoc)
af, err := r.openFile(annotPath)
if err != nil {
continue
}
var pageAnnot PageAnnot
err = xml.NewDecoder(af).Decode(&pageAnnot)
_ = af.Close()
if err != nil {
continue
}
r.Annots[page.PageID] = append(r.Annots[page.PageID], pageAnnot.Annot...)
}
return nil
}