Documentation
¶
Overview ¶
Package content 遍历 OFD 页面、模板、批注和复合图元,并传递统一的坐标与裁剪。
本包不持有解析文档、绘制上下文或资源缓存。Resources 提供图元资源和已测量的 复合单元范围,调用方负责页面租约、字体锁、资源预算及印章子文档的生命周期。 所有访问回调都同步执行,回调结束后不保留页面内容或资源引用。
Frame 的坐标和裁剪采用 OFD 左上原点,单位为毫米。文字与链接消费同一遍历帧, 复合对象的绘制和遍历通过 MapBox 共用矩形映射。输入模型与共享路径均只读。
Index ¶
- Constants
- func AnnotationVisible(annot *models.Annot) bool
- func ItemID(item models.PageItem) models.StID
- func MapBox(from, to models.StBox) (geom.Matrix, bool)
- func Present(item models.PageItem) bool
- func VisibleLayers(layers []*models.Layer, hidden map[models.StID]bool) []*models.Layer
- func WalkAnnotations[S Resources](frame Frame[S], annotations *models.PageAnnot, watermark bool, ...)
- func WalkItems[S Resources](frame Frame[S], items []models.PageItem, visit Visitor[S])
- func WalkLayers[S Resources](frame Frame[S], layers []*models.Layer, visit Visitor[S])
- func WalkPage[S PageResources](frame Frame[S], page *models.PageContent, annotations *models.PageAnnot, ...) error
- type Composite
- type Frame
- type Options
- type PageResources
- type Resources
- type Source
- type Visibility
- type Visitor
Constants ¶
const MaxDepth = 32
MaxDepth 限制块与复合图元的递归嵌套深度,防止循环引用无限展开。
Variables ¶
This section is empty.
Functions ¶
func AnnotationVisible ¶
AnnotationVisible 判断批注是否可见,未指定 Visible 时默认为可见。
func VisibleLayers ¶
VisibleLayers 返回未隐藏的非空图层,不修改原切片。
func WalkAnnotations ¶
func WalkAnnotations[S Resources](frame Frame[S], annotations *models.PageAnnot, watermark bool, visit Visitor[S])
WalkAnnotations 按来源筛选批注,并将 Appearance 局部坐标平移到目标页。
func WalkLayers ¶
WalkLayers 先遍历背景图层,再遍历其他图层,保留图层内的图元顺序。
func WalkPage ¶
func WalkPage[S PageResources](frame Frame[S], page *models.PageContent, annotations *models.PageAnnot, visibility Visibility, options Options, seals func(Frame[S], Visitor[S]) error, visit Visitor[S]) error
WalkPage 按背景模板、水印、正文、前景模板、印章和其他批注的顺序遍历。 page 和 annotations 必须在调用期间保持有效,seals 同步访问已固定的印章子文档。
Types ¶
type Composite ¶
type Composite struct {
Items []models.PageItem
Box models.StBox
Source models.StBox
DrawParam *models.DrawParam
}
Composite 描述待展开的单元。Box 是单元的逻辑画布,Source 是其中实际映射到 CompositeObject.Boundary 的区域;测量裁边与预算扣除由资源提供方负责。
type Frame ¶
type Frame[S Resources] struct { Scope S Box models.StBox Matrix geom.Matrix Clip *geom.Path Source Source DrawParam *models.DrawParam Depth int InComposite bool }
Frame 记录当前资源作用域到目标页的映射。Scope 可携带调用方的文档与预算, 由泛型保留具体类型,遍历层不需要访问其中的绘制或字体状态。
func (Frame[S]) MapLayout ¶
func (f Frame[S]) MapLayout(layout textlayout.Layout) textlayout.Layout
MapLayout 将独占的布局结果映射到目标页;字符切片原位更新,不修改文档模型。
type PageResources ¶
type PageResources interface {
Resources
LoadTemplate(id models.StID) (*models.PageContent, error)
TemplateForeground(template models.Template) bool
}
PageResources 追加模板加载及叠放位置查询,返回的内容在遍历期间必须保持只读。
type Resources ¶
type Resources interface {
GetDrawParam(id models.StID) *models.DrawParam
ResolveComposite(object models.CompositeObject, inherited *models.DrawParam, depth int) (Composite, bool)
TextClip(unit models.CTGraphicUnit, pageHeight float64) *geom.Path
CompositeClip(object models.CompositeObject, pageHeight float64) *geom.Path
}
Resources 提供图层参数、复合单元范围及已经构建的裁剪路径。 裁剪路径采用当前画布左下原点坐标,由 Frame.OFDClip 转为目标页坐标。
type Visibility ¶
Visibility 是本次输出的正文层及模板引用过滤,不修改原模型。