Documentation
¶
Overview ¶
Package content 遍历 OFD 页面、模板、批注和复合图元,并传递统一的坐标与裁剪。
本包不持有解析文档、绘制上下文或资源缓存。Resources 提供图元资源和已测量的 复合单元范围,调用方负责页面租约、字体锁、资源预算及印章子文档的生命周期。 所有访问回调都同步执行,回调结束后不保留页面内容或资源引用。
Frame 的坐标和裁剪采用 OFD 左上原点,单位为毫米。文字与链接消费同一遍历帧, 复合对象的绘制和遍历通过 MapBox 共用矩形映射。输入模型与共享路径均只读。
Index ¶
- Constants
- func AnnotationVisible(annot *spec.Annot) bool
- func ApplicationClip(area *spec.PageArea) *geom.Path
- func ItemID(item spec.PageItem) spec.StID
- func LayerType(layer *spec.Layer) string
- func MapBox(from, to spec.StBox) (geom.Matrix, bool)
- func Present(item spec.PageItem) bool
- func VisibleLayers(layers []*spec.Layer, hidden map[spec.StID]bool) []*spec.Layer
- func WalkAnnotations[S Resources](frame Frame[S], annotations *spec.PageAnnot, watermark bool, visit Visitor[S])
- func WalkItems[S Resources](frame Frame[S], items []spec.PageItem, visit Visitor[S])
- func WalkLayerType[S Resources](frame Frame[S], layers []*spec.Layer, kind string, visit Visitor[S])
- func WalkLayers[S Resources](frame Frame[S], layers []*spec.Layer, visit Visitor[S])
- func WalkPage[S PageResources](frame Frame[S], page *models.PageContent, annotations *spec.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 ApplicationClip ¶ added in v0.1.9
ApplicationClip 按 §7.5 表7返回显示区域与物理页面的交集(左上原点)。 缺省不裁剪;空交集必须保留空路径,不能回退为整页可见。
func VisibleLayers ¶
VisibleLayers 返回未隐藏的非空图层,不修改原切片。
func WalkAnnotations ¶
func WalkAnnotations[S Resources](frame Frame[S], annotations *spec.PageAnnot, watermark bool, visit Visitor[S])
WalkAnnotations 按来源筛选批注,并将 Appearance 局部坐标平移到目标页。
func WalkLayerType ¶ added in v0.1.9
func WalkLayerType[S Resources](frame Frame[S], layers []*spec.Layer, kind string, visit Visitor[S])
WalkLayerType 只遍历指定类别的图层,供模板与页面图层交错使用。
func WalkLayers ¶
WalkLayers 按背景、正文、前景遍历图层,保留同类图层和图元的原始顺序。
func WalkPage ¶
func WalkPage[S PageResources](frame Frame[S], page *models.PageContent, annotations *spec.PageAnnot, visibility Visibility, options Options, seals func(Frame[S], Visitor[S]) error, visit Visitor[S]) error
WalkPage 按 GB/T 33190—2016 §7.7 图16遍历模板与页面图层,再访问印章和批注。 page 和 annotations 必须在调用期间保持有效,seals 同步访问已固定的印章子文档。
Types ¶
type Composite ¶
type Composite struct {
Items []spec.PageItem
Box spec.StBox
Source spec.StBox
DrawParam *spec.DrawParam
}
Composite 描述待展开的单元。Box 是单元的逻辑画布,Source 是其中实际映射到 CompositeObject.Boundary 的区域;测量裁边与预算扣除由资源提供方负责。
type Frame ¶
type Frame[S Resources] struct { Scope S Box spec.StBox Matrix geom.Matrix Clip *geom.Path Source Source TemplateID uint64 DrawParam *spec.DrawParam Depth int InComposite bool // TemplateScope 在模板遍历期间绑定资源作用域;返回的释放函数必须同步调用。 TemplateScope func(spec.StID) (S, func(), error) }
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 spec.StID) (*models.PageContent, error)
TemplateForeground(template spec.Template) bool
}
PageResources 追加模板加载及叠放位置查询,返回的内容在遍历期间必须保持只读。
type Resources ¶
type Resources interface {
GetDrawParam(id spec.StID) *spec.DrawParam
ResolveComposite(object spec.CompositeObject, inherited *spec.DrawParam, depth int) (Composite, bool)
TextClip(unit spec.CTGraphicUnit, pageHeight float64) *geom.Path
CompositeClip(object spec.CompositeObject, pageHeight float64) *geom.Path
}
Resources 提供图层参数、复合单元范围及已经构建的裁剪路径。 裁剪路径采用当前画布左下原点坐标,由 Frame.OFDClip 转为目标页坐标。
type Visibility ¶
Visibility 是本次输出的正文层及模板引用过滤,不修改原模型。