Help us shape the future of Go! Take the 2026 Go Developer Survey

content

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package content 遍历 OFD 页面、模板、批注和复合图元,并传递统一的坐标与裁剪。

本包不持有解析文档、绘制上下文或资源缓存。Resources 提供图元资源和已测量的 复合单元范围,调用方负责页面租约、字体锁、资源预算及印章子文档的生命周期。 所有访问回调都同步执行,回调结束后不保留页面内容或资源引用。

Frame 的坐标和裁剪采用 OFD 左上原点,单位为毫米。文字与链接消费同一遍历帧, 复合对象的绘制和遍历通过 MapBox 共用矩形映射。输入模型与共享路径均只读。

Index

Constants

View Source
const MaxDepth = 32

MaxDepth 限制块与复合图元的递归嵌套深度,防止循环引用无限展开。

Variables

This section is empty.

Functions

func AnnotationVisible

func AnnotationVisible(annot *models.Annot) bool

AnnotationVisible 判断批注是否可见,未指定 Visible 时默认为可见。

func ItemID

func ItemID(item models.PageItem) models.StID

ItemID 返回有效图元的对象 ID,块和缺失载荷返回 0。

func MapBox

func MapBox(from, to models.StBox) (geom.Matrix, bool)

MapBox 构造将 from 矩形映射到 to 矩形的矩阵。两个矩形使用相同的轴方向; 退化的源区域或溢出坐标无法生成有限矩阵时返回 false。

func Present

func Present(item models.PageItem) bool

Present 检查图元种类与载荷一致,缺失对象不参与绘制或内容收集。

func VisibleLayers

func VisibleLayers(layers []*models.Layer, hidden map[models.StID]bool) []*models.Layer

VisibleLayers 返回未隐藏的非空图层,不修改原切片。

func WalkAnnotations

func WalkAnnotations[S Resources](frame Frame[S], annotations *models.PageAnnot, watermark bool, visit Visitor[S])

WalkAnnotations 按来源筛选批注,并将 Appearance 局部坐标平移到目标页。

func WalkItems

func WalkItems[S Resources](frame Frame[S], items []models.PageItem, visit Visitor[S])

WalkItems 展开块和可见复合图元,传递单元坐标映射及父级裁剪。 不可见图元自身仍可携带链接热区,访问后由消费方决定是否收集文字。

func WalkLayers

func WalkLayers[S Resources](frame Frame[S], layers []*models.Layer, visit Visitor[S])

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 将独占的布局结果映射到目标页;字符切片原位更新,不修改文档模型。

func (Frame[S]) OFDClip

func (f Frame[S]) OFDClip(path *geom.Path) *geom.Path

OFDClip 将当前画布坐标的路径映射到目标页的 OFD 坐标,不修改原路径。

func (Frame[S]) Place

func (f Frame[S]) Place(mapping geom.Matrix, source Source, clip *geom.Path) Frame[S]

Place 将子文档帧放置到目标页,并合并目标页裁剪;资源作用域仍属于子文档。

type Options

type Options struct {
	IncludeAnnotations bool
	IncludeWatermarks  bool
	IncludeSeals       bool
}

Options 控制附加文字来源,正文、模板及其复合对象始终收集。

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 Source

type Source = textlayout.Source

Source 是文字来源,与文字布局元数据共用同一类型。

const (
	SourcePage       Source = "page"
	SourceTemplate   Source = "template"
	SourceAnnotation Source = "annotation"
	SourceWatermark  Source = "watermark"
	SourceSeal       Source = "seal"
)

type Visibility

type Visibility struct {
	HiddenLayers    map[models.StID]bool
	HiddenTemplates map[models.StID]bool
}

Visibility 是本次输出的正文层及模板引用过滤,不修改原模型。

type Visitor

type Visitor[S Resources] func(Frame[S], models.PageItem)

Visitor 同步访问一个图元及其资源作用域、坐标和裁剪。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL