spec

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spec 定义 OFD 标准数据模型、基础类型和固定常量,供解析、创建、校验 及外部使用者共享。本包不负责文档加载、渲染或业务权限执行。 结构模型以声明和 XML 解码为主,完整文档创建使用 pkg/creator;基础值已有的 XML 编解码能力不代表 xml.Marshal 可以生成完整标准文档。

Index

Examples

Constants

View Source
const (
	// FillRuleNonZero 使用非零绕数规则。
	FillRuleNonZero = "NonZero"
	// FillRuleEvenOdd 使用奇偶规则。
	FillRuleEvenOdd = "Even-Odd"
)

路径填充规则(PathObject/@Rule、Clip/Area/Path/@Rule)。

View Source
const (
	// LineCapButt 使用平头端点。
	LineCapButt = "Butt"
	// LineCapRound 使用圆头端点。
	LineCapRound = "Round"
	// LineCapSquare 使用方头端点。
	LineCapSquare = "Square"
)

路径端点样式(CT_GraphicUnit/@Cap)。

View Source
const (
	// LineJoinMiter 使用斜接连接。
	LineJoinMiter = "Miter"
	// LineJoinRound 使用圆角连接。
	LineJoinRound = "Round"
	// LineJoinBevel 使用斜角连接。
	LineJoinBevel = "Bevel"
)

路径连接样式(CT_GraphicUnit/@Join)。

View Source
const (
	// LayerBody 普通正文图层。
	LayerBody = "Body"
	// LayerBackground 背景图层。
	LayerBackground = "Background"
	// LayerForeground 前景图层。
	LayerForeground = "Foreground"
	// LayerCustom 自定义图层。
	LayerCustom = "Custom"
)

图层类型(Layer/@Type)。创建、文字提取和渲染都要判断图层是否为背景层, 取值集中在这里避免各包各写一份字面量。

View Source
const (
	// ZOrderBackground 模板页绘制在页面内容之后(背景层)。
	ZOrderBackground = "Background"
	// ZOrderForeground 模板页绘制在页面内容之前(前景层)。
	ZOrderForeground = "Foreground"
)

模板页叠放顺序(TemplatePage/@ZOrder、Template/@ZOrder)。

View Source
const (
	// SigTypeSeal 签章。
	SigTypeSeal = "Seal"
	// SigTypeSign 签名。
	SigTypeSign = "Sign"
)

签名类型(Signature/@Type)。

View Source
const (
	// PageModeNone 使用默认页面显示模式。
	PageModeNone = "None"
	// PageModeFullScreen 以全屏模式显示文档。
	PageModeFullScreen = "FullScreen"
	// PageModeUseOutlines 显示文档大纲面板。
	PageModeUseOutlines = "UseOutlines"
	// PageModeUseThumbs 显示页面缩略图面板。
	PageModeUseThumbs = "UseThumbs"
	// PageModeUseCustomTags 显示自定义标签面板。
	PageModeUseCustomTags = "UseCustomTags"
	// PageModeUseLayers 显示图层面板。
	PageModeUseLayers = "UseLayers"
	// PageModeUseAttatchs 显示附件面板。拼写沿用 OFD 规范原文(Attatchs)。
	PageModeUseAttatchs = "UseAttatchs"
	// PageModeUseBookmarks 显示书签面板。
	PageModeUseBookmarks = "UseBookmarks"

	// PageLayoutOnePage 单页显示。
	PageLayoutOnePage = "OnePage"
	// PageLayoutOneColumn 单列连续显示。
	PageLayoutOneColumn = "OneColumn"
	// PageLayoutTwoPageL 双页显示,页面从左向右排列。
	PageLayoutTwoPageL = "TwoPageL"
	// PageLayoutTwoColumnL 双列连续显示,页面从左向右排列。
	PageLayoutTwoColumnL = "TwoColumnL"
	// PageLayoutTwoPageR 双页显示,页面从右向左排列。
	PageLayoutTwoPageR = "TwoPageR"
	// PageLayoutTwoColumnR 双列连续显示,页面从右向左排列。
	PageLayoutTwoColumnR = "TwoColumnR"

	// TabDisplayDocTitle 标签页显示文档标题。
	TabDisplayDocTitle = "DocTitle"
	// TabDisplayFileName 标签页显示文件名。
	TabDisplayFileName = "FileName"

	// ZoomModeDefault 使用默认缩放。
	ZoomModeDefault = "Default"
	// ZoomModeFitHeight 适应高度。
	ZoomModeFitHeight = "FitHeight"
	// ZoomModeFitWidth 适应宽度。
	ZoomModeFitWidth = "FitWidth"
	// ZoomModeFitRect 适应页面。
	ZoomModeFitRect = "FitRect"
)

文档视图首选项 CT_VPreferences 的取值。

View Source
const (
	AnnotationTypeLink      = "Link"
	AnnotationTypePath      = "Path"
	AnnotationTypeHighlight = "Highlight"
	AnnotationTypeStamp     = "Stamp"
	AnnotationTypeWatermark = "Watermark"
)

注解类型(Annotation/@Type)。

View Source
const (
	MediaTypeImage = "Image"
	MediaTypeAudio = "Audio"
	MediaTypeVideo = "Video"
)

多媒体资源类型(MultiMedia/@Type)。

View Source
const (
	ColorSpaceTypeGray = "GRAY"
	ColorSpaceTypeRGB  = "RGB"
	ColorSpaceTypeCMYK = "CMYK"
)

颜色空间类型(ColorSpace/@Type)。

View Source
const (
	DestTypeXYZ  = "XYZ"
	DestTypeFit  = "Fit"
	DestTypeFitH = "FitH"
	DestTypeFitV = "FitV"
	DestTypeFitR = "FitR"
)

页面跳转目标类型(Dest/@Type)。

View Source
const (
	ActionEventDO    = "DO"
	ActionEventPO    = "PO"
	ActionEventClick = "CLICK"
)

动作触发事件(Action/@Event)。

View Source
const (
	MovieOperatorPlay   = "Play"
	MovieOperatorStop   = "Stop"
	MovieOperatorPause  = "Pause"
	MovieOperatorResume = "Resume"
)

影片动作操作符(Movie/@Operator)。

View Source
const (
	PatternReflectNormal       = "Normal"
	PatternReflectRow          = "Row"
	PatternReflectColumn       = "Column"
	PatternReflectRowAndColumn = "RowAndColumn"
)

图案单元反射方式(Pattern/@ReflectMethod)。

View Source
const (
	PatternRelativePage   = "Page"
	PatternRelativeObject = "Object"
)

图案坐标参考系(Pattern/@RelativeTo)。

View Source
const (
	ShadingMapDirect  = "Direct"
	ShadingMapRepeat  = "Repeat"
	ShadingMapReflect = "Reflect"
)

渐变映射方式(AxialShd/@MapType、RadialShd/@MapType)。

View Source
const (
	// EncryptionEntryPoint 是附录 C.3 的解密入口文件名。
	EncryptionEntryPoint = "Encryptions.xml"
	// IntegrityEntryPoint 是附录 D.2 的完整性保护描述文件名。
	IntegrityEntryPoint = "OFDEntries.xml"
)

GM/T 0099—2020 定义的密码应用入口,均位于 OFD 包根目录。

View Source
const (
	// DocTypeOFD 是基础 OFD,取 GB/T 33190 的一般版式文档。
	DocTypeOFD = "OFD"
	// DocTypeOFDA 是档案长期保存 profile,取 GB/T 42133—2022《信息技术
	// OFD档案应用指南》6.2.1 a):该标准按「禁用清单」限制 OFD 特性以满足
	// DA/T 47 的长期保存要求,并规定阅读软件见到该取值时应禁用插入页面、
	// 调整页面等文档编辑功能。
	DocTypeOFDA = "OFD-A"
	// DocTypeOFDH 是电子病历版式文档 profile。该取值出自
	// GB/T 48666-2026《电子病历版式文档技术要求》7.1 a),该标准在
	// GB/T 33190 与 GB/T 42133 的基础上叠加医疗领域要求,并把阅读软件的
	// 限制扩大到全部文档编辑功能。
	DocTypeOFDH = "OFD-H"
)

DocType 是 OFD.xml 根节点 DocType 属性的取值,用于声明文档遵循的 profile。标准正文本身不校验该属性的具体取值,而是由各领域应用规范 收紧,因此取值随 profile 变化。

View Source
const MaxPageBlockDepth = 256

MaxPageBlockDepth 是 XML 解码的嵌套资源上限,不是 OFD 标准对文档层数的要求。

View Source
const Namespace = "http://www.ofdspec.org/2016"

Namespace 是标准 OFD 命名空间。

View Source
const RootDocument = "OFD.xml"

RootDocument 是 OFD 包根文档的文件名。

Variables

DocTypes 是全部已知 DocType 取值,按 profile 从通用到专用排列。

View Source
var ErrPageBlockDepth = errors.New("页面对象块嵌套层级过深")

ErrPageBlockDepth 表示页面对象块嵌套超过实现资源上限,可用 errors.Is 判断。

Functions

func DecodeTextCodeValue added in v0.1.9

func DecodeTextCodeValue(text string) string

DecodeTextCodeValue 解码表45的 OFD 文字转义,并兼容 z.ofd 等生产方在首尾插入 XML 排版换行。 这些换行不参与表 46 的定位与表 48 的 CodePosition。表 45 要求空格转义, 这里仍保留历史文档的直接空格和内部换行;显式转义也保持原值。

func IsDocType

func IsDocType(value string) bool

IsDocType 判断 value 是否为已知 DocType 取值。

Types

type Action added in v0.1.9

type Action struct {
	Event  ActionEvent  `xml:"Event,attr"`
	Region *Region      `xml:"Region,omitempty"`
	Goto   *ActionGoto  `xml:"Goto,omitempty"`
	URI    *ActionURI   `xml:"URI,omitempty"` //nolint:tagliatelle // 标准元素名为 URI。
	GotoA  *ActionGotoA `xml:"GotoA,omitempty"`
	Sound  *ActionSound `xml:"Sound,omitempty"`
	Movie  *ActionMovie `xml:"Movie,omitempty"`
}

Action 是 §14.1 表51的动作声明,不负责触发或执行动作。 Goto、URI、GotoA、Sound、Movie 按标准应恰有一项,模型解码本身不代替校验。

type ActionEvent added in v0.1.9

type ActionEvent string

ActionEvent 是 §14.1 表52的动作触发事件。

type ActionGoto added in v0.1.9

type ActionGoto struct {
	Dest     *Dest        `xml:"Dest,omitempty"`
	Bookmark *BookmarkRef `xml:"Bookmark,omitempty"`
}

ActionGoto 是 §14.2 表53的文档内跳转,目标区域和书签引用应恰有一项。

type ActionGotoA added in v0.1.9

type ActionGotoA struct {
	AttachID string `xml:"AttachID,attr"` //nolint:tagliatelle // 标准属性名为 AttachID。
	// NewWindow 保留属性省略状态;附录A的缺省值为 true,由动作执行方解释。
	NewWindow *bool `xml:"NewWindow,attr,omitempty"`
}

ActionGotoA 是 §14.3 表55的附件跳转声明。

type ActionList added in v0.1.9

type ActionList struct {
	// Actions 动作列表。
	Actions []Action `xml:"Action"`
}

ActionList 动作列表。

type ActionMovie added in v0.1.9

type ActionMovie struct {
	ResourceID StRefID       `xml:"ResourceID,attr"` //nolint:tagliatelle // 标准属性名为 ResourceID。
	Operator   MovieOperator `xml:"Operator,attr,omitempty"`
}

ActionMovie 是 §14.6 表58的视频动作声明,Operator 为空表示省略,不提前补 Play。

type ActionSound added in v0.1.9

type ActionSound struct {
	ResourceID  StRefID `xml:"ResourceID,attr"` //nolint:tagliatelle // 标准属性名为 ResourceID。
	Volume      *int    `xml:"Volume,attr,omitempty"`
	Repeat      *bool   `xml:"Repeat,attr,omitempty"`
	Synchronous *bool   `xml:"Synchronous,attr,omitempty"`
}

ActionSound 是 §14.5 表57的音频动作声明,省略状态由指针保留。

type ActionURI added in v0.1.9

type ActionURI struct {
	URI    string  `xml:"URI,attr"` //nolint:tagliatelle // 标准属性名为 URI。
	Base   *string `xml:"Base,attr,omitempty"`
	Target *string `xml:"Target,attr,omitempty"`
}

ActionURI 是 §14.4 表56及附录A的 URI 动作声明,不打开外部链接。

type Actions added in v0.1.9

type Actions struct {
	// Action 动作列表。
	Action []Action `xml:"Action"`
}

Actions 动作集合。

type Annot added in v0.1.9

type Annot struct {
	// ID 注解标识,在页面注解文件内唯一。
	ID string `xml:"ID,attr"` //nolint:tagliatelle // OFD 标准属性名为 ID。
	// Type 注解类型。
	Type AnnotType `xml:"Type,attr"`
	// Creator 创建该注解的软件或用户名称。
	Creator string `xml:"Creator,attr"`
	// LastModDate 注解最后修改时间。
	LastModDate DateTime `xml:"LastModDate,attr"`
	// Visible 表示该注释对象是否显示,未指定时默认为 true。
	Visible OptionalBool `xml:"Visible,attr,omitempty"`
	// Subtype 注解子类型。
	Subtype string `xml:"Subtype,attr,omitempty"`
	// Print 是否随页面打印 Remark 信息,缺省为 true;不控制 Appearance(§15 表61)。
	Print OptionalBool `xml:"Print,attr,omitempty"`
	// NoZoom 是否在缩放页面时保持 Remark 显示大小不变。
	NoZoom bool `xml:"NoZoom,attr,omitempty"`
	// NoRotate 是否在旋转页面时保持 Remark 显示方向不变。
	NoRotate bool `xml:"NoRotate,attr,omitempty"`
	// ReadOnly 是否禁止用户更改 Remark,未指定时按规范默认为 true。
	ReadOnly OptionalBool `xml:"ReadOnly,attr,omitempty"`
	// Remark 注解备注。
	Remark *string `xml:"Remark,omitempty"`
	// Parameters 注解参数集合。
	Parameters *Params `xml:"Parameters,omitempty"`
	// Appearance 注解外观内容。
	Appearance *Appearance `xml:"Appearance"`
}

Annot 单个页面注解定义。

type AnnotPage added in v0.1.9

type AnnotPage struct {
	PageID  StRefID `xml:"PageID,attr"` //nolint:tagliatelle // OFD标准属性名为PageID。
	FileLoc StLoc   `xml:"FileLoc"`
}

AnnotPage 保存单个页面的分页注释文件引用。

type AnnotType added in v0.1.9

type AnnotType string

AnnotType 注解类型枚举。

const (
	// AnnotTypeLink 表示链接注解。
	AnnotTypeLink AnnotType = "Link"
	// AnnotTypePath 表示路径注解。
	AnnotTypePath AnnotType = "Path"
	// AnnotTypeHighlight 表示高亮注解。
	AnnotTypeHighlight AnnotType = "Highlight"
	// AnnotTypeStamp 表示图章注解。
	AnnotTypeStamp AnnotType = "Stamp"
	// AnnotTypeWatermark 表示水印注解。
	AnnotTypeWatermark AnnotType = "Watermark"
)

func (*AnnotType) UnmarshalXMLAttr added in v0.1.9

func (a *AnnotType) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 从 XML 属性中解析并校验注解类型。

type Annotations added in v0.1.9

type Annotations struct {
	XMLName xml.Name    `xml:"Annotations"`
	Xmlns   string      `xml:"xmlns,attr,omitempty"` //nolint:tagliatelle // XML 命名空间属性固定为小写 xmlns。
	Pages   []AnnotPage `xml:"Page,omitempty"`
}

Annotations 是 GB/T 33190—2016 §15.1 表60的注释索引,不包含注释外观。

type Appearance added in v0.1.9

type Appearance struct {
	// CTPageBlock 注解外观中的页面对象。
	CTPageBlock

	// Boundary 注解外观的边界框。
	Boundary *StBox `xml:"Boundary,attr,omitempty"`
}

Appearance 注解外观定义。

func (*Appearance) UnmarshalXML added in v0.1.9

func (a *Appearance) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 先解析外观边界,再将其内容交由共享的页面块解析器处理。

type ArcData added in v0.1.9

type ArcData struct {
	// RX 椭圆在 X 轴方向的半径。
	RX float64
	// RY 椭圆在 Y 轴方向的半径。
	RY float64
	// XAxisRotation 椭圆相对于 X 轴的旋转角度,单位为度。
	XAxisRotation float64
	// LargeArcFlag 是否选择大于或等于 180 度的弧段。
	LargeArcFlag bool
	// SweepFlag 是否沿正向角度方向绘制弧段。
	SweepFlag bool
	// EndPoint 椭圆弧的终点坐标。
	EndPoint StPos
}

ArcData 定义椭圆弧参数。

type Attachment added in v0.1.9

type Attachment struct {
	ID           string       `xml:"ID,attr"` //nolint:tagliatelle // OFD标准属性名为大写ID。
	Name         string       `xml:"Name,attr"`
	Format       *string      `xml:"Format,attr,omitempty"`
	CreationDate DateTime     `xml:"CreationDate,attr,omitempty"`
	ModDate      DateTime     `xml:"ModDate,attr,omitempty"`
	Size         *float64     `xml:"Size,attr,omitempty"`
	Visible      OptionalBool `xml:"Visible,attr,omitempty"`
	Usage        string       `xml:"Usage,attr,omitempty"`
	FileLoc      StLoc        `xml:"FileLoc"`
}

Attachment 是 §20.2 表73的附件声明,不包含附件内容及加载状态。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var attachment spec.Attachment
	data := `<Attachment ID="attachment_1" Name="说明.txt" Visible="false"><FileLoc>Files/readme.txt</FileLoc></Attachment>`
	if err := xml.Unmarshal([]byte(data), &attachment); err != nil {
		panic(err)
	}
	fmt.Println(attachment.ID, attachment.Name, attachment.FileLoc)
	fmt.Println(attachment.Visible.IsSet(), attachment.Visible.Value(true))
}
Output:
attachment_1 说明.txt Files/readme.txt
true false

type Attachments added in v0.1.9

type Attachments struct {
	XMLName     xml.Name     `xml:"Attachments"`
	Xmlns       string       `xml:"xmlns,attr,omitempty"` //nolint:tagliatelle // XML 命名空间属性固定为小写 xmlns。
	Attachments []Attachment `xml:"Attachment,omitempty"`
}

Attachments 是 GB/T 33190—2016 §20.1 表72的附件列表。

type Bookmark added in v0.1.9

type Bookmark struct {
	// Name 书签名称。
	Name string `xml:"Name,attr"`
	// Dest 书签指向的目标位置。
	Dest Dest `xml:"Dest"`
}

Bookmark 是 §7.5 表10的书签,目标位置不提前解析为运行时页码。

type BookmarkList added in v0.1.9

type BookmarkList struct {
	// Bookmarks 书签列表。
	Bookmarks []Bookmark `xml:"Bookmark"`
}

BookmarkList 是 §7.5 表10的文档书签列表。

type BookmarkRef added in v0.1.9

type BookmarkRef struct {
	Name string `xml:"Name,attr"`
}

BookmarkRef 按名称引用文档书签,而不是再次声明书签目标。

type Border added in v0.1.9

type Border struct {
	// BorderColor 边框颜色。
	BorderColor *CTColor `xml:"BorderColor"`
	// LineWidth 边框线宽,单位为毫米;缺省为 0.353,显式 0 表示不绘制边框。
	LineWidth *float64 `xml:"LineWidth,attr,omitempty"`
	// HorizonalCornerRadius 水平方向圆角半径,单位为毫米。
	HorizonalCornerRadius float64 `xml:"HorizonalCornerRadius,attr,omitempty"`
	// VerticalCornerRadius 垂直方向圆角半径,单位为毫米。
	VerticalCornerRadius float64 `xml:"VerticalCornerRadius,attr,omitempty"`
	// DashOffset 虚线模式的起始偏移量。
	DashOffset float64 `xml:"DashOffset,attr,omitempty"`
	// DashPattern 虚线模式中实线段和空白段的长度数组。
	DashPattern StArray[float64] `xml:"DashPattern,attr,omitempty"`
}

Border 图像边框定义。

type CTAxialShd added in v0.1.9

type CTAxialShd struct {
	// Segment 渐变颜色分段列表。
	Segment []Segment `xml:"Segment"`
	// MapType 渐变映射方式,可为 Direct、Repeat 或 Reflect。
	MapType string `xml:"MapType,attr,omitempty"` // Direct, Repeat, Reflect
	// MapUnit 渐变映射单元长度。
	MapUnit float64 `xml:"MapUnit,attr,omitempty"`
	// Extend 渐变起止范围外的延伸方式,可为 0、1、2 或 3。
	Extend int `xml:"Extend,attr,omitempty"` // 0,1,2,3
	// StartPoint 渐变起点。
	StartPoint StPos `xml:"StartPoint,attr"`
	// EndPoint 渐变终点。
	EndPoint StPos `xml:"EndPoint,attr"`
}

CTAxialShd 轴向渐变填充定义。

type CTCGTransform added in v0.1.9

type CTCGTransform struct {
	// Glyphs 变换关系中字型索引列表
	Glyphs StArray[int] `xml:"Glyphs"`
	// CodePosition 变换起始字符在 TextCode 中的位置。
	CodePosition int `xml:"CodePosition,attr"`
	// CodeCount 参与变换的字符数量。
	CodeCount int `xml:"CodeCount,attr,omitempty"`
	// GlyphCount 参与变换的字形数量。
	GlyphCount int `xml:"GlyphCount,attr,omitempty"`
}

CTCGTransform 字符图形变换定义。

type CTColor added in v0.1.9

type CTColor struct {
	// Pattern 图案填充定义。
	Pattern *CtPattern `xml:"Pattern"`
	// AxialShd 轴向渐变填充定义。
	AxialShd *CTAxialShd `xml:"AxialShd"`
	// RadialShd 径向渐变填充定义。
	RadialShd *CTRadialShd `xml:"RadialShd"`
	// GouraudShd Gouraud 三角网格渐变填充定义。
	GouraudShd *CTGouraudShd `xml:"GouraudShd"`
	// LaGourandShd 规范 XML Schema 中的字段拼写,对应 LaGouraudShd。
	LaGourandShd *CTLaGouraudShd `xml:"LaGourandShd"`
	// LaGouraudShd 是标准正文中的拼写,LaGourandShd 是规范 XML Schema 中的拼写。
	LaGouraudShd *CTLaGouraudShd `xml:"LaGouraudShd"`
	// Value 颜色值,指定了当前颜色空间下各通道的取值。
	// Value 的取值应符合"通道 1 通道 2 通道 3 …"格式。
	// 此属性不出现时,应参考 Index 属性从颜色空间的调色板中取值。当二者都不出现时,各通道为0。
	//
	// 可选
	Value *ColorValue `xml:"Value,attr,omitempty"`
	// Index 调色板中颜色的编号,非负整数,将从当前颜色空间的调色板中取出相应索引的预定义颜色用来绘制。
	// 索引从0开始,可选。
	Index int `xml:"Index,attr,omitempty"`
	// ColorSpace 颜色空间资源引用。
	ColorSpace StRefID `xml:"ColorSpace,attr,omitempty"`
	// Alpha 颜色不透明度,在 0~255 之间取值。默认为 255,表示完全不透明
	//
	// 可选
	Alpha *uint8 `xml:"Alpha,attr,omitempty"`
}

CTColor 颜色及颜色填充定义。

type CTGouraudShd added in v0.1.9

type CTGouraudShd struct {
	// Point Gouraud 网格控制点列表。
	Point []GouraudPoint `xml:"Point"`
	// BackColor 网格背景颜色。
	BackColor *CTColor `xml:"BackColor,omitempty"`
	// Extend 渐变起止范围外的延伸方式。
	Extend int `xml:"Extend,attr,omitempty"`
}

CTGouraudShd Gouraud 三角网格渐变填充定义。

type CTGraphicUnit added in v0.1.9

type CTGraphicUnit struct {
	// Actions 图元触发的动作集合。
	Actions *Actions `xml:"Actions"`
	// Clips 图元使用的裁剪区域集合。
	Clips *Clips `xml:"Clips"`
	// Boundary 图元的边界框,单位为毫米。
	Boundary StBox `xml:"Boundary,attr"`
	// Name 图元名称。
	Name string `xml:"Name,attr,omitempty"`
	// Visible 像素是否可见,未指定时默认为 true。
	Visible OptionalBool `xml:"Visible,attr,omitempty"`
	// CTM 图元使用的坐标变换矩阵。
	CTM *CTM `xml:"CTM,attr,omitempty"`
	// DrawParam 图元使用的绘制参数引用。
	DrawParam StRefID `xml:"DrawParam,attr,omitempty"`
	// LineWidth 线宽,单位为毫米。
	LineWidth float64 `xml:"LineWidth,attr,omitempty"`
	// 线端点样式,枚举值,指定了一条线的端点样式。默认值为 Butt
	Cap  string `xml:"Cap,attr,omitempty"`  // Butt, Round, Square
	Join string `xml:"Join,attr,omitempty"` // Miter, Round, Bevel
	// Join 为 Miter 时的斜接截断值,附录 A 缺省为4.234;其他 Join 类型时无效。
	MiterLimit float64 `xml:"MiterLimit,attr,omitempty"`
	// DashOffset 虚线模式的起始偏移量。
	DashOffset float64 `xml:"DashOffset,attr,omitempty"`
	// DashPattern 虚线模式中实线段和空白段的长度数组。
	DashPattern *StArray[float64] `xml:"DashPattern,attr,omitempty"`
	// Alpha 图元整体不透明度,取值范围为 0 到 255,255 表示完全不透明(缺省 255)。
	Alpha *uint8 `xml:"Alpha,attr,omitempty"`

	// 兼容将这些属性编码为子元素的文档。
	DrawParamElement   *StID             `xml:"DrawParam,omitempty"`
	LineWidthElement   *float64          `xml:"LineWidth,omitempty"`
	CapElement         *string           `xml:"Cap,omitempty"`
	JoinElement        *string           `xml:"Join,omitempty"`
	MiterLimitElement  *float64          `xml:"MiterLimit,omitempty"`
	DashOffsetElement  *float64          `xml:"DashOffset,omitempty"`
	DashPatternElement *StArray[float64] `xml:"DashPattern,omitempty"`
}

CTGraphicUnit 图元通用属性定义。

func (*CTGraphicUnit) NormalizeDrawParams added in v0.1.9

func (g *CTGraphicUnit) NormalizeDrawParams()

NormalizeDrawParams 将既有非规范文档的子元素形式绘制参数复制到属性字段。 只合并已解码的声明,不加载 DrawParam 引用;XML 解码入口会自动调用。

func (CTGraphicUnit) VisibleValue added in v0.1.9

func (g CTGraphicUnit) VisibleValue() bool

VisibleValue 返回图元是否可见。OFD 未指定 Visible 时默认为可见。

type CTLaGouraudShd added in v0.1.9

type CTLaGouraudShd struct {
	// Point Gouraud 网格控制点列表。
	Point []LaGouraudPoint `xml:"Point"`
	// BackColor 网格背景颜色。
	BackColor *CTColor `xml:"BackColor,omitempty"`
	// VerticesPerRow 每行的顶点数量。
	VerticesPerRow int `xml:"VerticesPerRow,attr"`
	// Extend 渐变起止范围外的延伸方式。
	Extend int `xml:"Extend,attr,omitempty"`
}

CTLaGouraudShd Gouraud 网格渐变填充定义。

type CTM added in v0.1.9

type CTM [6]float64

CTM 是 GB/T 33190—2016 §8.5 的六分量仿射变换矩阵。 分量顺序为 a、b、c、d、e、f;点变换为 (a*x+c*y+e, b*x+d*y+f)。

func IdentityCTM added in v0.1.9

func IdentityCTM() CTM

IdentityCTM 返回独立的单位矩阵,调用方可修改而不会影响其他使用者。

func (*CTM) IsFinite added in v0.1.9

func (c *CTM) IsFinite() bool

IsFinite 判断矩阵的每个分量是否有限;nil 表示单位矩阵。

func (*CTM) IsInvertible added in v0.1.9

func (c *CTM) IsInvertible() bool

IsInvertible 判断矩阵是否可逆;nil 表示单位矩阵。

func (CTM) MarshalXML added in v0.1.9

func (c CTM) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML 将矩阵编码为六个数值,不使用 String 的诊断方括号。

func (CTM) MarshalXMLAttr added in v0.1.9

func (c CTM) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr 将矩阵编码为空格分隔的六个数值。

func (*CTM) Multiply added in v0.1.9

func (c *CTM) Multiply(other *CTM) *CTM

Multiply 返回当前矩阵乘以 other 的结果,不修改输入矩阵。

func (*CTM) RotationAngle added in v0.1.9

func (c *CTM) RotationAngle() float64

RotationAngle 返回旋转角度,单位为弧度。

func (*CTM) RotationAngleDegrees added in v0.1.9

func (c *CTM) RotationAngleDegrees() float64

RotationAngleDegrees 返回旋转角度,单位为度。

func (*CTM) String added in v0.1.9

func (c *CTM) String() string

String 返回用于诊断的矩阵字符串,不作为 XML 编码。

func (*CTM) Transform added in v0.1.9

func (c *CTM) Transform(x, y float64) (float64, float64)

Transform 变换给定的横纵坐标。

func (*CTM) TransformPoint added in v0.1.9

func (c *CTM) TransformPoint(p StPos) (float64, float64)

TransformPoint 变换点坐标。

func (*CTM) UnmarshalXML added in v0.1.9

func (c *CTM) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解码矩阵元素。

func (*CTM) UnmarshalXMLAttr added in v0.1.9

func (c *CTM) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 解码六个以空白分隔的有限数值。

func (*CTM) YScale added in v0.1.9

func (c *CTM) YScale() float64

YScale 返回纵轴方向的缩放量。

type CTPageBlock added in v0.1.9

type CTPageBlock struct {
	// Items 页面对象的文档顺序列表,用于保持原始绘制顺序,是所有消费方
	// 唯一使用的字段,避免为每个对象同时维护类型分组与文档顺序两份存储。
	Items []PageItem
}

CTPageBlock 是§7.7表16的页面内容块,Items 按文档顺序保存所有种类的图元。 本类型优先用于 XML 解码;完整 OFD 写入由 pkg/creator 提供。

func (*CTPageBlock) UnmarshalXML added in v0.1.9

func (p *CTPageBlock) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 按文档顺序解析页面块中的图形对象,保证绘制时各对象保持原始先后顺序。

type CTRadialShd added in v0.1.9

type CTRadialShd struct {
	// Segment 渐变颜色分段列表。
	Segment []Segment `xml:"Segment"`
	// MapType 渐变映射方式,可为 Direct、Repeat 或 Reflect。
	MapType string `xml:"MapType,attr,omitempty"` // Direct, Repeat, Reflect
	// MapUnit 渐变映射单元长度。
	MapUnit float64 `xml:"MapUnit,attr,omitempty"`
	// Eccentricity 径向渐变的离心率。
	Eccentricity float64 `xml:"Eccentricity,attr,omitempty"`
	// Angle 径向渐变的旋转角度。
	Angle float64 `xml:"Angle,attr,omitempty"`
	// StartPoint 起始圆心位置。
	StartPoint StPos `xml:"StartPoint,attr"`
	// StartRadius 起始半径,单位为毫米。
	StartRadius float64 `xml:"StartRadius,attr,omitempty"`
	// EndPoint 结束圆心位置。
	EndPoint StPos `xml:"EndPoint,attr"`
	// EndRadius 结束半径,单位为毫米。
	EndRadius float64 `xml:"EndRadius,attr"`
	// Extend 渐变起止范围外的延伸方式。
	Extend int `xml:"Extend,attr,omitempty"`
}

CTRadialShd 径向渐变填充定义。

type CellContent added in v0.1.9

type CellContent struct {
	// CTPageBlock 图案单元中的页面对象。
	CTPageBlock

	// Thumbnail 图案单元缩略图资源引用。
	Thumbnail StRefID `xml:"Thumbnail,attr,omitempty"`
}

CellContent 图案填充单元的内容。

type ClipArea added in v0.1.9

type ClipArea struct {
	// Path 用于定义裁剪区域的路径对象。
	Path *CtPath `xml:"Path"`
	// Text 用于定义裁剪区域的文字对象。
	Text *CtText `xml:"Text"`
	// DrawParam 裁剪对象使用的绘制参数引用。
	DrawParam *StRefID `xml:"DrawParam,attr,omitempty"`
	// CTM 裁剪对象使用的坐标变换矩阵。
	CTM *CTM `xml:"CTM,attr,omitempty"`
}

ClipArea 单个裁剪区域,可以由路径或文字对象定义。

type Clips added in v0.1.9

type Clips struct {
	// TransFlag 是否对裁剪区域应用透明处理。
	TransFlag *bool `xml:"TransFlag,attr,omitempty"`
	// Clip 裁剪定义列表。
	Clip []CtClip `xml:"Clip"`
}

Clips 图元裁剪集合。

type ColorSpace added in v0.1.9

type ColorSpace struct {
	// ID 是文档作用域内的资源标识。
	ID StID `xml:"ID,attr"` //nolint:tagliatelle // OFD 标准属性名为 ID。
	// Type 可为 GRAY、RGB 或 CMYK。
	Type string `xml:"Type,attr"`
	// BitsPerComponent 为每个颜色分量的位数,缺省时保持零值。
	BitsPerComponent int `xml:"BitsPerComponent,attr,omitempty"`
	// Profile 是包内颜色配置文件的词法路径。
	Profile StLoc `xml:"Profile,attr,omitempty"`
	// Palette 是可选调色板。
	Palette *Palette `xml:"Palette,omitempty"`
}

ColorSpace 是 §8.3.1 表25的颜色空间声明,按§7.9扩展资源 ID。 不加载 Profile、不转换颜色,也不将省略的 BitsPerComponent 补为默认值8。

type ColorSpaces added in v0.1.9

type ColorSpaces struct {
	// ColorSpace 按资源文件中的声明顺序保存颜色空间。
	ColorSpace []ColorSpace `xml:"ColorSpace"`
}

ColorSpaces 是 GB/T 33190—2016 §7.9 表18的颜色空间资源集合。

type ColorValue added in v0.1.9

type ColorValue struct {
	color.RGBA
	// contains filtered or unexported fields
}

ColorValue 保存 GB/T 33190—2016 §8.3.2 表26/27的原始颜色通道值。 RGBA 仅是既有的无颜色空间8位回退表示,不是按颜色空间转换后的颜色; 四通道在 CMYK 中不是 RGBA。实际解释须结合 ColorSpace 及 BitsPerComponent。 XML 解码保留原始通道文本,编码时优先使用它,不使用 RGBA 回退结果。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var value spec.ColorValue
	if err := xml.Unmarshal([]byte(`<Value>#FFFF 0 0</Value>`), &value); err != nil {
		panic(err)
	}
	components, count, _ := value.Components()
	fmt.Println(components[0], count)
	attribute, err := value.MarshalXMLAttr(xml.Name{Local: "Value"})
	if err != nil {
		panic(err)
	}
	fmt.Println(attribute.Name.Local, attribute.Value)
}
Output:
65535 3
Value #FFFF 0 0

func (ColorValue) Components added in v0.1.9

func (c ColorValue) Components() ([4]int, int, bool)

Components 返回按 ST_Array 原文解析出的通道取值与通道数。ok 为 false 表示没有 原始通道分量(例如空文本或直接用 RGBA 构造),此时使用方可回退到 RGBA 的8位分量。 返回的数组最多保存前四个分量,count 仍反映原始总数;多余分量的文本可继续 XML 往返。

func (ColorValue) MarshalXML added in v0.1.9

func (c ColorValue) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML 编码原始通道文本;直接用 RGBA 构造的值则沿用 String 的8位表示。

func (ColorValue) MarshalXMLAttr added in v0.1.9

func (c ColorValue) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr 编码原始通道属性,不将16位或 CMYK 分量缩减为8位 RGBA。

func (ColorValue) String added in v0.1.9

func (c ColorValue) String() string

String 返回8位回退表示的 "R G B" 或 "R G B A",不是原始通道的 XML 编码。

func (*ColorValue) UnmarshalXML added in v0.1.9

func (c *ColorValue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解析 XML 元素

func (*ColorValue) UnmarshalXMLAttr added in v0.1.9

func (c *ColorValue) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 解析 XML 属性

type CommandType added in v0.1.9

type CommandType string

CommandType 定义 GB/T 33190—2016 §9.1 表36的 OFD 紧缩路径命令类型。 S: SubPath起点 (Start point of SubPath) - 定义子路径的起始点坐标(x,y) M: 移动到 (Move to) - 移动画笔到指定点,不绘制线条 L: 直线到 (Line to) - 从当前点到指定点绘制直线 B: 三次贝塞尔曲线 (Cubic Bezier curve) - 需要两个控制点和一个终点的曲线 Q: 二次贝塞尔曲线 (Quadratic Bezier curve) - 需要一个控制点和一个终点的曲线 A: 椭圆弧 (Elliptical arc) - 绘制椭圆弧线 C: 闭合路径 (Close path) - 从当前点绘制直线回到子路径起点

const (
	// Start 表示子路径的起点。
	Start CommandType = "S"
	// MoveTo 表示移动到指定点但不绘制线条。
	MoveTo CommandType = "M"
	// LineTo 表示从当前点绘制直线到指定点。
	LineTo CommandType = "L"
	// CubicBezier 表示三次贝塞尔曲线,需要两个控制点和一个终点。
	CubicBezier CommandType = "B"
	// QuadTo 表示二次贝塞尔曲线,需要一个控制点和一个终点。
	QuadTo CommandType = "Q"
	// ArcTo 表示椭圆弧线。
	ArcTo CommandType = "A"
	// Close 表示闭合路径,从当前点绘制直线回到子路径起点。
	Close CommandType = "C"
)

type CommonData added in v0.1.9

type CommonData struct {
	// MaxUnitID 文档中已使用的最大对象标识。
	MaxUnitID StID `xml:"MaxUnitID"` //nolint:tagliatelle // 标准元素名为 MaxUnitID。
	// PageArea 文档页面区域定义。
	PageArea PageArea `xml:"PageArea"`
	// PublicRes 公共资源文件的位置列表。
	PublicRes []StLoc `xml:"PublicRes,omitempty"`
	// DocumentRes 文档资源文件的位置列表。
	DocumentRes []StLoc `xml:"DocumentRes,omitempty"`
	// TemplatePages 文档模板页列表。
	TemplatePages []TemplatePage `xml:"TemplatePage,omitempty"`
	// DefaultCS 文档默认颜色空间资源引用。
	DefaultCS *StRefID `xml:"DefaultCS,omitempty"` //nolint:tagliatelle // 标准元素名为 DefaultCS。
}

CommonData 是 §7.5 表6的文档公共数据,不自动补齐默认页面尺寸。

type CompositeGraphicUnit added in v0.1.9

type CompositeGraphicUnit struct {
	// ID 复合图形资源标识,在资源文件内唯一。
	ID StID `xml:"ID,attr"`
	// Width 复合图形的宽度,单位为毫米。
	Width float64 `xml:"Width,attr"`
	// Height 复合图形的高度,单位为毫米。
	Height float64 `xml:"Height,attr"`
	// Thumbnail 复合图形缩略图资源引用。
	Thumbnail StRefID `xml:"Thumbnail,omitempty"`
	// Substitution 复合图形替代资源引用。
	Substitution StRefID `xml:"Substitution,omitempty"`
	// Content 复合图形包含的页面对象内容。
	Content CTPageBlock `xml:"Content"`
}

CompositeGraphicUnit 复合图形资源定义。

type CompositeGraphicUnits added in v0.1.9

type CompositeGraphicUnits struct {
	// CompositeGraphicUnit 复合图形资源列表。
	CompositeGraphicUnit []CompositeGraphicUnit `xml:"CompositeGraphicUnit"`
}

CompositeGraphicUnits 复合图形资源集合。

type CompositeObject added in v0.1.9

type CompositeObject struct {
	// CtComposite 复合图元的通用属性和资源引用。
	CtComposite

	// ID 复合对象标识,在页面内唯一。
	ID StID `xml:"ID,attr"`
}

CompositeObject 页面中的复合对象。

func (*CompositeObject) UnmarshalXML added in v0.1.9

func (o *CompositeObject) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 手写解码复合对象。

type Content added in v0.1.9

type Content struct {
	// Layer 页面图层列表,顺序即图层的绘制顺序。
	Layer []*Layer `xml:"Layer"`
}

Content 页面内容容器。

type CtClip added in v0.1.9

type CtClip struct {
	// Area 裁剪区域列表。
	Area []ClipArea `xml:"Area"`
}

CtClip 裁剪定义。

type CtComposite added in v0.1.9

type CtComposite struct {
	// CTGraphicUnit 复合图元的通用属性。
	CTGraphicUnit

	// ResourceID 复合图形资源标识。
	ResourceID StRefID `xml:"ResourceID,attr"`
}

CtComposite 复合图元定义。

type CtImage added in v0.1.9

type CtImage struct {
	// CTGraphicUnit 图像图元的通用属性。
	CTGraphicUnit

	// Border 图像边框定义。
	Border *Border `xml:"Border"`
	// ResourceID 图像资源标识。
	ResourceID StRefID `xml:"ResourceID,attr"`
	// Substitution 替代图像资源标识。
	Substitution StRefID `xml:"Substitution,attr,omitempty"`
	// ImageMask 图像蒙版资源标识。
	ImageMask StRefID `xml:"ImageMask,attr,omitempty"`
}

CtImage 图像图元定义。

type CtLayer added in v0.1.9

type CtLayer struct {
	// CTPageBlock 图层中的页面对象。
	CTPageBlock

	// Type 图层类型,可为 Body、Background、Foreground 或 Custom。
	Type string `xml:"Type,attr,omitempty"`
	// DrawParam 图层使用的绘制参数引用。
	DrawParam StRefID `xml:"DrawParam,attr,omitempty"`
}

CtLayer 图层内容定义。

type CtPath added in v0.1.9

type CtPath struct {
	// CTGraphicUnit 路径图元的通用属性。
	CTGraphicUnit

	// StrokeColor 路径描边颜色。
	StrokeColor *CTColor `xml:"StrokeColor"`
	// FillColor 路径填充颜色。
	FillColor *CTColor `xml:"FillColor"`
	// AbbreviatedData 是表36的 OFD 紧缩路径,不是 SVG 路径。
	AbbreviatedData PathData `xml:"AbbreviatedData"`
	// Stroke 是否描边,默认值为 true。
	Stroke OptionalBool `xml:"Stroke,attr,omitempty"`
	// Fill 是否填充路径。
	Fill bool `xml:"Fill,attr,omitempty"`
	// Rule 填充规则,可为 NonZero 或 Even-Odd。
	Rule string `xml:"Rule,attr,omitempty"` // NonZero, Even-Odd
}

CtPath 路径图元定义。

type CtPattern added in v0.1.9

type CtPattern struct {
	// CellContent 图案单元中的内容。
	CellContent CellContent `xml:"CellContent"`
	// Width 图案单元宽度,单位为毫米。
	Width float64 `xml:"Width,attr"`
	// Height 图案单元高度,单位为毫米。
	Height float64 `xml:"Height,attr"`
	// XStep 图案在水平方向上的重复步长,单位为毫米。
	XStep float64 `xml:"XStep,attr,omitempty"`
	// YStep 图案在垂直方向上的重复步长,单位为毫米。
	YStep float64 `xml:"YStep,attr,omitempty"`
	// ReflectMethod 图案重复时的镜像方式,可为 Normal、Row、Column 或 RowAndColumn。
	ReflectMethod string `xml:"ReflectMethod,attr,omitempty"` // Normal, Row, Column, RowAndColumn
	// RelativeTo 图案坐标的参考对象,可为 Page 或 Object。
	RelativeTo string `xml:"RelativeTo,attr,omitempty"` // Page, Object
	// CTM 图案单元使用的坐标变换矩阵;缺省时为 nil,按单位矩阵处理。
	CTM *CTM `xml:"CTM,attr,omitempty"`
}

CtPattern 图案填充定义。

type CtText added in v0.1.9

type CtText struct {
	// CTGraphicUnit 文字图元的通用属性。
	CTGraphicUnit

	// FillColor 文字填充颜色。
	FillColor *CTColor `xml:"FillColor"`
	// StrokeColor 文字描边颜色。
	StrokeColor *CTColor `xml:"StrokeColor"`
	// CGTransform 字符图形变换列表。
	CGTransform []CTCGTransform `xml:"CGTransform"`
	// TextCode 文字编码及定位信息列表。
	TextCode []TextCode `xml:"TextCode"`
	// Font 文字使用的字体引用。
	Font StRefID `xml:"Font,attr"`
	// Size 字号,单位为毫米。
	Size float64 `xml:"Size,attr"`
	// Stroke 是否描边,默认值为 false;当文字对象被裁剪区引用时此属性被忽略。
	Stroke bool `xml:"Stroke,attr,omitempty"`
	// Fill 是否填充,默认值为 true;当文字对象被裁剪区引用时此属性被忽略。
	Fill OptionalBool `xml:"Fill,attr,omitempty"`
	// HScale 字形在水平方向的缩放比,默认值为 1.0。
	// 取值可小于 1(压缩)也可大于 1(拉伸);例如 HScale 为 0.5 时字宽减半,
	// 为 1.5 时字宽变为原来的 1.5 倍(对应 PDF 的 Tz>100%)。
	HScale float64 `xml:"HScale,attr,omitempty"`
	// ReadDirection 阅读方向,指定文字排列的方向,默认值为 0。
	ReadDirection int `xml:"ReadDirection,attr,omitempty"`
	// CharDirection 字符方向,指定文字放置的方式,默认值为 0。
	CharDirection int `xml:"CharDirection,attr,omitempty"`
	// Weight 字重,通常取 0、100 至 1000 之间的值。
	Weight int `xml:"Weight,attr,omitempty"` // 0,100,...,1000
	// Italic 是否为斜体样式,默认值为 false。
	Italic bool `xml:"Italic,attr,omitempty"`
}

CtText 文字图元定义。

type CustomData added in v0.1.9

type CustomData struct {
	Name  string `xml:"Name,attr"`
	Value string `xml:",chardata"`
}

CustomData 保存一项自定义元数据的名称及文本。

type CustomDatas added in v0.1.9

type CustomDatas struct {
	CustomData []CustomData `xml:"CustomData"`
}

CustomDatas 是表4的自定义元数据集合,保留条目顺序及重复名称。

type CustomTag added in v0.1.9

type CustomTag struct {
	// NameSpace 按附录A的 CustomTags.xsd 声明标引命名空间。
	NameSpace string `xml:"NameSpace,attr"`
	// TypeID 保留表63中的类型标识,兼容既有生产者写法。
	TypeID    string `xml:"TypeID,attr,omitempty"` //nolint:tagliatelle // 表63属性名为 TypeID。
	SchemaLoc *StLoc `xml:"SchemaLoc,omitempty"`
	FileLoc   StLoc  `xml:"FileLoc"`
}

CustomTag 是自定义标引入口,资源内容及定位结果由加载方处理。

type CustomTags added in v0.1.9

type CustomTags struct {
	XMLName    xml.Name    `xml:"CustomTags"`
	Xmlns      string      `xml:"xmlns,attr,omitempty"` //nolint:tagliatelle // XML 命名空间属性固定为小写 xmlns。
	CustomTags []CustomTag `xml:"CustomTag,omitempty"`
}

CustomTags 是 GB/T 33190—2016 §16 表63及附录A模式的自定义标引列表。

type DateTime added in v0.1.9

type DateTime struct {
	time.Time
}

DateTime 保存OFD的日期或日期时间,支持XML元素和属性解码。 零值表示未设置;除标准日期和RFC3339格式外,保留既有非规范日期格式的兼容解析。

func (*DateTime) UnmarshalXML added in v0.1.9

func (t *DateTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解析日期或日期时间元素。

func (*DateTime) UnmarshalXMLAttr added in v0.1.9

func (t *DateTime) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 解析日期或日期时间属性。

type DecryptSeed added in v0.1.9

type DecryptSeed struct {
	XMLName      xml.Name         `xml:"DecyptSeed"`
	ID           string           `xml:"ID,attr"` //nolint:tagliatelle // 标准属性名为 ID。
	Scheme       string           `xml:"EncryptCaseId,attr"`
	Users        []EncryptionUser `xml:"UserInfo"`
	ExtendParams *ExtensionData   `xml:"ExtendParams"`
}

DecryptSeed 是附录 C.2 表C.1的密钥描述,XML 根名沿用标准拼写 DecyptSeed。 Scheme 保存 EncryptCaseId 原文,不推断方案;ExtendParams 原样保留扩展子内容。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var seed spec.DecryptSeed
	data := `<DecyptSeed ID="e1" EncryptCaseId="1.1.1"><UserInfo UserName="示例"><EncryptedWK>YWJj</EncryptedWK></UserInfo><ExtendParams/></DecyptSeed>`
	if err := xml.Unmarshal([]byte(data), &seed); err != nil {
		panic(err)
	}
	fmt.Println(seed.ID, seed.Scheme)
	fmt.Println(seed.Users[0].Name, seed.Users[0].WrappedKey)
	fmt.Println(seed.Users[0].IV == nil, seed.ExtendParams != nil)
}
Output:
e1 1.1.1
示例 YWJj
true true

type Dest added in v0.1.9

type Dest struct {
	Type   DestType `xml:"Type,attr"`
	PageID StRefID  `xml:"PageID,attr"` //nolint:tagliatelle // 标准属性名为 PageID。
	Left   *float64 `xml:"Left,attr,omitempty"`
	Top    *float64 `xml:"Top,attr,omitempty"`
	Right  *float64 `xml:"Right,attr,omitempty"`
	Bottom *float64 `xml:"Bottom,attr,omitempty"`
	Zoom   *float64 `xml:"Zoom,attr,omitempty"`
}

Dest 保存目标页面的标识及可选坐标,不执行页码解析或坐标换算。

type DestType added in v0.1.9

type DestType string

DestType 是 GB/T 33190—2016 §14.2 表54的跳转目标描述方式。

type DocBody added in v0.1.9

type DocBody struct {
	// DocInfo 文档元数据信息。
	DocInfo DocInfo `xml:"DocInfo"`
	// DocRoot 文档根目录的位置。
	DocRoot StLoc `xml:"DocRoot"`
	// Versions 文档版本集合。
	Versions *Versions `xml:"Versions,omitempty"`
	// Signatures 签名文件的位置。
	Signatures *StLoc `xml:"Signatures,omitempty"`
}

DocBody OFD 文档体。

type DocInfo added in v0.1.9

type DocInfo struct {
	// DocID 文档标识。
	DocID string `xml:"DocID"` //nolint:tagliatelle // OFD标准元素名为DocID。
	// Title 文档标题。
	Title *string `xml:"Title,omitempty"`
	// Author 文档作者。
	Author *string `xml:"Author,omitempty"`
	// Subject 文档主题。
	Subject *string `xml:"Subject,omitempty"`
	// Abstract 文档摘要。
	Abstract *string `xml:"Abstract,omitempty"`
	// CreationDate 文档创建时间。
	CreationDate *DateTime `xml:"CreationDate,omitempty"`
	// ModDate 文档最后修改时间。
	ModDate *DateTime `xml:"ModDate,omitempty"`
	// DocUsage 文档用途。
	DocUsage *string `xml:"DocUsage,omitempty"`
	// Cover 文档封面文件的位置。
	Cover *StLoc `xml:"Cover,omitempty"`
	// Keywords 文档关键词集合。
	Keywords *Keywords `xml:"Keywords,omitempty"`
	// Creator 创建文档的软件名称。
	Creator *string `xml:"Creator,omitempty"`
	// CreatorVersion 创建文档的软件版本。
	CreatorVersion *string `xml:"CreatorVersion,omitempty"`
	// CustomDatas 文档自定义数据集合。
	CustomDatas *CustomDatas `xml:"CustomDatas,omitempty"`
}

DocInfo 是§7.4表4的文档元数据,保留可选字段的缺省状态。

type DocVersion added in v0.1.9

type DocVersion struct {
	// XMLName 文档版本根元素名称。
	XMLName xml.Name `xml:"DocVersion"`
	// Xmlns 文档版本命名空间地址。
	Xmlns string `xml:"xmlns,attr"` //nolint:tagliatelle // XML命名空间声明保留小写xmlns。
	// ID 文档版本标识。
	ID string `xml:"ID,attr"` //nolint:tagliatelle // OFD标准属性名为大写ID。
	// Version 文档版本号。
	Version *string `xml:"Version,attr,omitempty"`
	// Name 文档版本名称。
	Name *string `xml:"Name,attr,omitempty"`
	// CreationDate 文档版本创建时间。
	CreationDate *DateTime `xml:"CreationDate,attr,omitempty"`
	// FileList 文档版本包含的文件列表。
	FileList FileList `xml:"FileList"`
	// DocRoot 文档根目录的位置。
	DocRoot StLoc `xml:"DocRoot"`
}

DocVersion 是 GB/T 33190—2016 §19.2 表71的文档版本信息,不负责版本加载。

type Document added in v0.1.9

type Document struct {
	// XMLName 文档主体根元素名称。
	XMLName xml.Name `xml:"Document"`
	// XMLNS 保留命名空间声明字段;XML 解码后的根命名空间以 XMLName.Space 为准。
	XMLNS string `xml:"xmlns:ofd,attr,omitempty"`
	// CommonData 文档公共数据。
	CommonData CommonData `xml:"CommonData"`
	// Pages 文档页面列表。
	Pages PageList `xml:"Pages"`
	// Outlines 文档大纲。
	Outlines *OutlineList `xml:"Outlines,omitempty"`
	// Permissions 文档权限设置。
	Permissions *Permissions `xml:"Permissions,omitempty"`
	// Actions 文档级动作集合。
	Actions *ActionList `xml:"Actions,omitempty"`
	// VPreferences 文档视图首选项。
	VPreferences *VPreferences `xml:"VPreferences,omitempty"`
	// Bookmarks 文档书签列表。
	Bookmarks *BookmarkList `xml:"Bookmarks,omitempty"`
	// Annotations 注解文件的位置。
	Annotations *StLoc `xml:"Annotations,omitempty"`
	// CustomTags 自定义标签文件的位置。
	CustomTags *StLoc `xml:"CustomTags,omitempty"`
	// Attachments 附件文件的位置。
	Attachments *StLoc `xml:"Attachments,omitempty"`
	// Extensions 扩展文件的位置。
	Extensions *StLoc `xml:"Extensions,omitempty"`
}

Document 是 GB/T 33190—2016 §7.5 表5的文档主体声明,不包含加载状态。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var document spec.Document
	data := `<Document xmlns="http://www.ofdspec.org/2016"><CommonData><MaxUnitID>1</MaxUnitID><PageArea><PhysicalBox>0 0 210 297</PhysicalBox></PageArea></CommonData><Pages><Page ID="1" BaseLoc="Pages/Page_0/Content.xml"/></Pages></Document>`
	if err := xml.Unmarshal([]byte(data), &document); err != nil {
		panic(err)
	}
	fmt.Println(document.XMLName.Space)
	fmt.Println(document.Pages.Pages[0].ID, document.Pages.Pages[0].BaseLoc)
}
Output:
http://www.ofdspec.org/2016
1 Pages/Page_0/Content.xml

type DrawParam added in v0.1.9

type DrawParam struct {
	// ID 绘制参数标识,在资源文件内唯一。
	ID StID `xml:"ID,attr"`
	// Relative 继承的绘制参数资源引用。
	Relative StRefID `xml:"Relative,attr,omitempty"`
	// LineWidth 线宽,单位为毫米。
	LineWidth float64 `xml:"LineWidth,attr,omitempty"`
	// Join 线连接样式,可为 Miter、Round 或 Bevel。
	Join string `xml:"Join,attr,omitempty"`
	// Cap 线端点样式,可为 Butt、Round 或 Square。
	Cap string `xml:"Cap,attr,omitempty"`
	// DashOffset 虚线模式的起始偏移量。
	DashOffset float64 `xml:"DashOffset,attr,omitempty"`
	// DashPattern 虚线模式中实线段和空白段的长度数组。
	DashPattern *StArray[float64] `xml:"DashPattern,attr,omitempty"`
	// MiterLimit 斜接连接的长度限制。
	MiterLimit float64 `xml:"MiterLimit,attr,omitempty"`
	// FillColor 填充颜色。
	FillColor *CTColor `xml:"FillColor"`
	// StrokeColor 描边颜色。
	StrokeColor *CTColor `xml:"StrokeColor"`
	// contains filtered or unexported fields
}

DrawParam 是§8.2表21的绘制参数声明,按§7.9扩展 ID,保留 Relative 引用。

Example
package main

import (
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	parent := spec.DrawParam{LineWidth: 2}
	var override spec.DrawParam
	override.SetLineWidth(0)
	parent.Override(&override)
	fmt.Println(parent.LineWidth, parent.HasLineWidth())
}
Output:
0 true

func (DrawParam) HasDashOffset added in v0.1.9

func (p DrawParam) HasDashOffset() bool

HasDashOffset 判断虚线偏移是否显式给出,包含解码所得的零值。

func (DrawParam) HasLineWidth added in v0.1.9

func (p DrawParam) HasLineWidth() bool

HasLineWidth 判断线宽是否显式给出,包含解码所得的零值。

func (DrawParam) HasMiterLimit added in v0.1.9

func (p DrawParam) HasMiterLimit() bool

HasMiterLimit 判断斜接限制是否显式给出,包含解码所得的零值。

func (*DrawParam) Override added in v0.1.9

func (p *DrawParam) Override(source *DrawParam)

Override 使用 source 中明确指定的属性覆盖当前绘制参数。 对数值属性保留明确指定的零值。

func (*DrawParam) SetDashOffset added in v0.1.9

func (p *DrawParam) SetDashOffset(value float64)

SetDashOffset 设置显式虚线偏移,包括零值。

func (*DrawParam) SetLineWidth added in v0.1.9

func (p *DrawParam) SetLineWidth(value float64)

SetLineWidth 设置显式线宽,包括合法的零值。

func (*DrawParam) SetMiterLimit added in v0.1.9

func (p *DrawParam) SetMiterLimit(value float64)

SetMiterLimit 设置显式斜接限制,包括零值。

func (*DrawParam) UnmarshalXML added in v0.1.9

func (p *DrawParam) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解析绘制参数,并记录显式出现的数值属性。 这些标记用于区分未指定与合法的零值,以便正确处理 Relative 继承。

type DrawParams added in v0.1.9

type DrawParams struct {
	// DrawParam 绘制参数资源列表。
	DrawParam []*DrawParam `xml:"DrawParam"`
}

DrawParams 绘制参数资源集合。

type EncryptEntry added in v0.1.9

type EncryptEntry struct {
	Path  string `xml:"Path,attr"`
	EPath string `xml:"EPath,attr"`
	Seed  string `xml:"DecryptSeedLoc,attr"`
}

EncryptEntry 保存明密文包内路径和可选独立密钥描述路径,不补全缺省 EPath 或 Seed。

type EncryptInfo added in v0.1.9

type EncryptInfo struct {
	ID             string                `xml:"ID,attr"` //nolint:tagliatelle // 标准属性名为 ID。
	Relative       string                `xml:"Relative,attr"`
	Provider       EncryptionProvider    `xml:"Provider"`
	Scope          string                `xml:"EncryptScope"`
	Parameters     *EncryptionParameters `xml:"Parameters"`
	EncryptDate    string                `xml:"EncryptDate"`
	DecryptSeedLoc string                `xml:"DecryptSeedLoc"`
	EntriesMapLoc  string                `xml:"EntriesMapLoc"`
}

EncryptInfo 保存一次加密操作的原始声明,ID 和 Relative 使用 xs:ID/IDREF 字符串。 路径和日期文本保持原样,不执行路径规范化或根据 Scope 推断加密范围。

type EncryptedEntries added in v0.1.9

type EncryptedEntries struct {
	XMLName xml.Name       `xml:""`        //nolint:tagliatelle // 不指定根名,以保留标准图表中的两种拼写。
	ID      string         `xml:"ID,attr"` //nolint:tagliatelle // 标准属性名为 ID。
	Entries []EncryptEntry `xml:"EncryptEntry"`
}

EncryptedEntries 是附录 C.4 表C.3的明密文映射表。 XMLName 保留实际根名,以兼容标准图C.3与表C.3中的 EncryptEntries/EncryptedEntries。 具体根名、命名空间和路径的安全检查仍由加密读取链执行。

type EncryptionParameter added in v0.1.9

type EncryptionParameter struct {
	Name  string `xml:"Name,attr"`
	Type  string `xml:"Type,attr"`
	Value string `xml:",chardata"`
}

EncryptionParameter 保存附加描述的名称、可选类型及字符值,不解释厂商类型。

type EncryptionParameters added in v0.1.9

type EncryptionParameters struct {
	Items []EncryptionParameter `xml:"Parameter"`
}

EncryptionParameters 保存加密操作的附加描述集合。

type EncryptionProvider added in v0.1.9

type EncryptionProvider struct {
	Name        string `xml:"Name,attr"`
	Company     string `xml:"Company,attr"`
	Version     string `xml:"Version,attr"`
	ProtocolVer string `xml:"ProtocolVer,attr"`
	// ExtendData 保存 Base64 文本,不解码为二进制。
	ExtendData string `xml:"ExtendData"`
}

EncryptionProvider 是表C.2的加解密组件声明,与签名组件 Provider 的属性名不同。

type EncryptionUser added in v0.1.9

type EncryptionUser struct {
	Name        string `xml:"UserName,attr"`
	Type        string `xml:"UserType,attr"`
	Certificate string `xml:"UserCert"`
	WrappedKey  string `xml:"EncryptedWK"` //nolint:tagliatelle // 标准元素名为 EncryptedWK。
	// IV 为 nil 表示省略;显式空 IVValue 保持非 nil 空字符串,留给检查器拒绝。
	IV *string `xml:"IVValue"` //nolint:tagliatelle // 标准元素名为 IVValue。
}

EncryptionUser 保存接收者原始声明,不执行 UserType 或 IVValue 的默认值填充。 Certificate、WrappedKey 和 IV 均为 Base64 文本;解析不验证证书、不解包密钥。

type Encryptions added in v0.1.9

type Encryptions struct {
	XMLName    xml.Name      `xml:"Encryptions"`
	Operations []EncryptInfo `xml:"EncryptInfo"`
}

Encryptions 是 GM/T 0099—2020 附录 C.3 表C.2的解密入口声明。 本模型不检查操作依赖、不读取控制文件,也不执行加解密。

type Extension added in v0.1.9

type Extension struct {
	AppName    string  `xml:"AppName,attr"`
	Company    *string `xml:"Company,attr,omitempty"`
	AppVersion *string `xml:"AppVersion,attr,omitempty"`
	// Date 沿用 RFC3339 日期时间解析;缺省或不支持的日期文本保持 nil。
	Date       *time.Time          `xml:"Date,attr,omitempty"`
	RefID      StRefID             `xml:"RefId,attr"`
	Properties []ExtensionProperty `xml:"Property,omitempty"`
	// Data 为 nil 表示省略;非 nil 的空值表示存在空 Data 元素。
	Data       *ExtensionData `xml:"Data,omitempty"`
	ExtendData *StLoc         `xml:"ExtendData,omitempty"`
}

Extension 是 §17 表65的扩展信息,保留属性、内联数据和外部数据路径。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var extension spec.Extension
	data := `<Extension AppName="示例" RefId="1"><Data>前<Config xmlns="urn:example">子内容</Config>后</Data></Extension>`
	if err := xml.Unmarshal([]byte(data), &extension); err != nil {
		panic(err)
	}
	fmt.Println(extension.AppName, extension.RefID)
	fmt.Println(extension.Data.Text)
	fmt.Println(extension.Data.InnerXML)
}
Output:
示例 1
前后
前<Config xmlns="urn:example">子内容</Config>后

func (*Extension) UnmarshalXML added in v0.1.9

func (e *Extension) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解码扩展声明,只读取直接子元素;未知子树整体跳过。

type ExtensionData added in v0.1.9

type ExtensionData struct {
	// Attrs 保存扩展元素自身的属性,包括在该元素上声明的命名空间。
	Attrs []xml.Attr `xml:",any,attr"`
	// InnerXML 保存扩展元素的原始内部 XML,不包含元素自身的起止标签。
	InnerXML string `xml:",innerxml"` //nolint:tagliatelle // innerxml 是 encoding/xml 的固定选项,字段使用 XML 惯用缩写。
	// Text 保存扩展元素的直接字符数据(含 CDATA),不包含后代元素中的文本。
	Text string `xml:",chardata"`
}

ExtensionData 保存内联 XML 扩展子内容,包括 §17 的 xs:anyType 和密码方案扩展参数, 不解释或执行其中的 XML。 InnerXML 保留原始子内容,包括混合文本、注释和处理指令;前缀可能引用祖先命名空间, 不能脱离原始命名空间上下文直接当作独立 XML 文档使用,也不是完整文档编码接口。

type ExtensionProperty added in v0.1.9

type ExtensionProperty struct {
	Name  string  `xml:"Name,attr"`
	Type  *string `xml:"Type,attr,omitempty"`
	Value string  `xml:",chardata"`
}

ExtensionProperty 是扩展的名称、类型和文本值,不解释厂商自定义类型。

type Extensions added in v0.1.9

type Extensions struct {
	XMLName    xml.Name    `xml:"Extensions"`
	Xmlns      string      `xml:"xmlns,attr"` //nolint:tagliatelle // XML 命名空间属性固定为小写 xmlns。
	Extensions []Extension `xml:"Extension"`
}

Extensions 是 GB/T 33190—2016 §17 表64的扩展信息列表,不加载扩展数据文件。

type FileList added in v0.1.9

type FileList struct {
	// Files 文档版本文件列表。
	Files []VersionFile `xml:"File"`
}

FileList 文档版本文件列表。

type Font added in v0.1.9

type Font struct {
	// ID 是文档作用域内的资源标识。
	ID StID `xml:"ID,attr"` //nolint:tagliatelle // OFD 标准属性名为 ID。
	// FontName 是字型名称。
	FontName string `xml:"FontName,attr"`
	// FamilyName 是用于匹配替代字体的字型族名。
	FamilyName string `xml:"FamilyName,attr,omitempty"`
	// Charset 省略时保持空字符串,不提前补入标准缺省值 unicode。
	Charset string `xml:"Charset,attr,omitempty"`
	// Italic 指示斜体;字型标志按表44缺省为 false,不区分显式 false 与省略。
	Italic bool `xml:"Italic,attr,omitempty"`
	// Bold 指示粗体。
	Bold bool `xml:"Bold,attr,omitempty"`
	// Serif 指示衬线字体。
	Serif bool `xml:"Serif,attr,omitempty"`
	// FixedWidth 指示等宽字体。
	FixedWidth bool `xml:"FixedWidth,attr,omitempty"`
	// FontFile 是包内内嵌字体文件的词法路径。
	FontFile StLoc `xml:"FontFile,omitempty"`
}

Font 是 §11.1 表44的字体声明,按§7.9扩展资源 ID,不包含字体加载状态。 没有 FontFile 时是逻辑字体;实际字体匹配与回退由使用方负责。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var font spec.Font
	if err := xml.Unmarshal([]byte(`<Font ID="1" FontName="Example" FixedWidth="true"><FontFile>Fonts/Subset.otf</FontFile></Font>`), &font); err != nil {
		panic(err)
	}
	fmt.Println(font.ID, font.FontName, font.FixedWidth, font.FontFile)
}
Output:
1 Example true Fonts/Subset.otf

type Fonts added in v0.1.9

type Fonts struct {
	Font []Font `xml:"Font"`
}

Fonts 是 §7.9 表18的字体资源集合。

type GouraudPoint added in v0.1.9

type GouraudPoint struct {
	// Color 控制点颜色。
	Color CTColor `xml:"Color"`
	// X 控制点横坐标。
	X float64 `xml:"X,attr"`
	// Y 控制点纵坐标。
	Y float64 `xml:"Y,attr"`
	// EdgeFlag 是方向标志,决定本控制点如何与前一个三角形衔接,
	// 取值含义见 GB/T 33190 图 40「方向标志的控制作用」。设前一个三角形
	// 为 (V0,V1,V2),则:
	//
	//	0:本点与随后两点另起一个三角形 (V0,V1,V2),与前一个三角形无共享边。
	//	1:本点复用 V1-V2 边,与前一个三角形拼成四边形
	//	   (V0,V1,V2)+ (V1,V2,新点),共享边为 V1-V2。
	//	2:本点复用 V0-V2 边,与前一个三角形拼成四边形
	//	   (V0,V1,V2)+ (V0,V2,新点),共享边为 V0-V2。
	//
	// 只有 1、2 会产生共享边,从而拼成连续网格;0 表示两个互不相连的
	// 三角形,各自独立填充(重叠区域的结果取决于阅读器的合成顺序)。
	// 规范只定义 0/1/2,个别文件沿用 PDF 语义写出 3(复用 V0-V1 边),
	// 渲染端宽容处理以避免丢三角形。
	EdgeFlag int `xml:"EdgeFlag,attr"` // 0,1,2;3 兼容 PDF 语义
}

GouraudPoint Gouraud 渐变控制点。

type ImageObject added in v0.1.9

type ImageObject struct {
	// CtImage 图像图元的通用属性和资源引用。
	CtImage

	// ID 图像对象标识,在页面内唯一。
	ID StID `xml:"ID,attr"`
}

ImageObject 页面中的图像对象。

func (*ImageObject) UnmarshalXML added in v0.1.9

func (o *ImageObject) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 手写解码图像对象。

type IntegrityFile added in v0.1.9

type IntegrityFile struct {
	ID       string `xml:"ID,attr" json:"id"` //nolint:tagliatelle // 标准属性名为 ID。
	Location string `xml:"FileLoc,attr" json:"location"`
}

IntegrityFile 是 GM/T 0099—2020 附录 D.2 表D.1的物理文件声明。 ID 保留 xs:ID 字符串,Location 保留原始包内路径,不加载文件。

type IntegrityManifest added in v0.1.9

type IntegrityManifest struct {
	XMLName        xml.Name        `xml:"" json:"-"`         //nolint:tagliatelle // 不指定根名,以保留标准图表中的两种拼写。
	ID             string          `xml:"ID,attr" json:"id"` //nolint:tagliatelle // 标准属性名为 ID。
	CreatorName    string          `xml:"CreatorName,attr,omitempty" json:"creator_name,omitempty"`
	Version        string          `xml:"Version,attr,omitempty" json:"version,omitempty"`
	CreationDate   string          `xml:"CreationDate,attr,omitempty" json:"creation_date,omitempty"`
	Files          []IntegrityFile `xml:"FileList>File" json:"files"`
	SignedValueLoc string          `xml:"SignedValueLoc" json:"signed_value_location,omitempty"`
}

IntegrityManifest 是附录 D.2 的完整性保护描述,不含遍历、验签或信任结论。 XMLName 保留图D.1的 OFDEntries 或表D.1的 DocEntries,不在声明层校验根名。 JSON 标签沿用 pkg/integrity 的已发布报告格式;原始 XML 解码不会规范化文件路径。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var manifest spec.IntegrityManifest
	data := `<OFDEntries ID="m1"><FileList><File ID="f1" FileLoc="/OFD.xml"/></FileList></OFDEntries>`
	if err := xml.Unmarshal([]byte(data), &manifest); err != nil {
		panic(err)
	}
	fmt.Println(manifest.ID, manifest.Files[0].ID)
	fmt.Println(manifest.Files[0].Location)
}
Output:
m1 f1
/OFD.xml

type Keywords added in v0.1.9

type Keywords struct {
	// Keyword 关键词列表。
	Keyword []string `xml:"Keyword"`
}

Keywords 文档关键词集合。

type LaGouraudPoint added in v0.1.9

type LaGouraudPoint struct {
	// Color 控制点颜色。
	Color CTColor `xml:"Color"`
	// X 控制点横坐标。
	X float64 `xml:"X,attr,omitempty"`
	// Y 控制点纵坐标。
	Y float64 `xml:"Y,attr,omitempty"`
}

LaGouraudPoint Gouraud 网格渐变控制点。

type Layer added in v0.1.9

type Layer struct {
	// CTPageBlock 图层中的页面对象。
	CTPageBlock

	// ID 图层标识,在页面内唯一。
	ID StID `xml:"ID,attr"`
	// Type 图层类型,可为 Body、Background、Foreground 或 Custom。
	Type string `xml:"Type,attr,omitempty"`
	// DrawParam 图层使用的绘制参数引用。
	DrawParam StRefID `xml:"DrawParam,attr,omitempty"`
}

Layer 页面图层,包含按文档顺序排列的页面对象。

func (*Layer) UnmarshalXML added in v0.1.9

func (l *Layer) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解析 Layer,除了图层属性外,还需按文档顺序记录其中的图形对象。

type MovieOperator added in v0.1.9

type MovieOperator string

MovieOperator 是 §14.6 表59的视频播放操作。

type MultiMedia added in v0.1.9

type MultiMedia struct {
	// ID 是文档作用域内的资源标识。
	ID StID `xml:"ID,attr"` //nolint:tagliatelle // OFD 标准属性名为 ID。
	// Type 可为 Image、Audio 或 Video。
	Type string `xml:"Type,attr"`
	// Format 保留原声明,不根据扩展名或文件内容推断。
	Format string `xml:"Format,attr,omitempty"`
	// MediaFile 是包内媒体文件的词法路径。
	MediaFile StLoc `xml:"MediaFile"`
}

MultiMedia 是 §7.9 表19的多媒体声明,不加载或探测媒体内容。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var media spec.MultiMedia
	data := `<MultiMedia ID="2" Type="Image" Format="PNG"><MediaFile>Images/logo.png</MediaFile></MultiMedia>`
	if err := xml.Unmarshal([]byte(data), &media); err != nil {
		panic(err)
	}
	fmt.Println(media.ID, media.Type, media.Format, media.MediaFile)
}
Output:
2 Image PNG Images/logo.png

type MultiMedias added in v0.1.9

type MultiMedias struct {
	MultiMedia []*MultiMedia `xml:"MultiMedia"`
}

MultiMedias 是 §7.9 表18的多媒体资源集合。

type OFD added in v0.1.9

type OFD struct {
	// XMLName 文档根元素名称。
	XMLName xml.Name `xml:"OFD"` //nolint:tagliatelle // 标准根元素为大写OFD。
	// XMLNS OFD 命名空间地址。
	XMLNS string `xml:"xmlns:ofd,attr"`
	// Version OFD 文档规范版本。
	Version string `xml:"Version,attr"`
	// DocType 文档类型。
	DocType string `xml:"DocType,attr"`
	// DocBodies 文档体列表。
	DocBodies []DocBody `xml:"DocBody"`
}

OFD 是 GB/T 33190—2016 §7.4 表3的主入口,不包含包加载状态。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var root spec.OFD
	data := []byte(`<OFD xmlns="http://www.ofdspec.org/2016" Version="1.0" DocType="OFD"><DocBody><DocInfo><Title>示例文档</Title></DocInfo><DocRoot>Doc_0/Document.xml</DocRoot></DocBody></OFD>`)
	if err := xml.Unmarshal(data, &root); err != nil {
		panic(err)
	}
	body := root.DocBodies[0]
	fmt.Println(*body.DocInfo.Title)
	fmt.Println(body.DocRoot.Resolve("/"))
}
Output:
示例文档
/Doc_0/Document.xml

type OptionalBool added in v0.1.9

type OptionalBool struct {
	// contains filtered or unexported fields
}

OptionalBool 表示一个可选的布尔值,用于处理 XML 属性中 缺省时需要默认值为 true 的场景(如 OFD 的 Visible 属性)。 与元素形式的 Permissions 布尔指针不同,本类型可在编码属性时省略未设置值。

使用方式:

  • 属性未指定:Value() 返回默认值(由调用方指定)
  • 属性值为 true:Value() 返回 true
  • 属性值为 false:Value() 返回 false

示例:

// 判断是否可见(默认 true)
if unit.Visible.Value(true) { ... }

func NewOptionalBool added in v0.1.9

func NewOptionalBool(b bool) OptionalBool

NewOptionalBool 创建一个 OptionalBool

func (*OptionalBool) Bool added in v0.1.9

func (o *OptionalBool) Bool() *bool

Bool 获取底层的 *bool 指针

func (OptionalBool) IsSet added in v0.1.9

func (o OptionalBool) IsSet() bool

IsSet 返回属性是否被显式设置

func (OptionalBool) MarshalJSON added in v0.1.9

func (o OptionalBool) MarshalJSON() ([]byte, error)

MarshalJSON 将未设置、显式 true 和显式 false 分别编码为 null、true 和 false。

func (OptionalBool) MarshalXMLAttr added in v0.1.9

func (o OptionalBool) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr 省略未设置属性,并保留显式 true 或 false。

func (*OptionalBool) Reset added in v0.1.9

func (o *OptionalBool) Reset()

Reset 重置为未设置状态

func (*OptionalBool) Set added in v0.1.9

func (o *OptionalBool) Set(b bool)

Set 设置值

func (*OptionalBool) UnmarshalJSON added in v0.1.9

func (o *OptionalBool) UnmarshalJSON(data []byte) error

UnmarshalJSON 读取可选布尔值,null 将其恢复为未设置状态。

func (*OptionalBool) UnmarshalXMLAttr added in v0.1.9

func (o *OptionalBool) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 实现 XML 属性反序列化

func (OptionalBool) Value added in v0.1.9

func (o OptionalBool) Value(defaultIfNotSet bool) bool

Value 返回布尔值。defaultIfNotSet 为属性未设置时的默认值。

type OutlineElem added in v0.1.9

type OutlineElem struct {
	// Title 大纲项标题。
	Title string `xml:"Title,attr"`
	// Count 叶节点数的参考值,以实际子节点为准。
	Count *int `xml:"Count,attr,omitempty"`
	// Expanded 是否展开该大纲项的子项。
	Expanded *bool `xml:"Expanded,attr,omitempty"`
	// Actions 选择该大纲项时执行的动作集合。
	Actions *ActionList `xml:"Actions,omitempty"`
	// OutlineElem 子大纲项列表。
	OutlineElem []OutlineElem `xml:"OutlineElem,omitempty"`
}

OutlineElem 是 §7.8 表17的大纲项;动作及子大纲均按声明顺序保存。

type OutlineList added in v0.1.9

type OutlineList struct {
	// OutlineElems 大纲项列表。
	OutlineElems []OutlineElem `xml:"OutlineElem"`
}

OutlineList 是 §7.8 表17的文档大纲列表。

type PageAnnot added in v0.1.9

type PageAnnot struct {
	// XMLName 页面注解根元素名称。
	XMLName xml.Name `xml:"PageAnnot"`
	// Xmlns 页面注解命名空间地址。
	Xmlns string `xml:"xmlns,attr"` //nolint:tagliatelle // XML 命名空间属性固定为小写 xmlns。
	// Annots 页面中的注解列表。
	Annots []*Annot `xml:"Annot"`
}

PageAnnot 是 GB/T 33190—2016 §15 表61的分页注释文件,不包含资源加载状态。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var page spec.PageAnnot
	data := `<PageAnnot><Annot ID="1" Type="Link" Creator="示例" LastModDate="2026-01-02" Print="false"><Remark>说明</Remark><Appearance Boundary="1 2 30 40"/></Annot></PageAnnot>`
	if err := xml.Unmarshal([]byte(data), &page); err != nil {
		panic(err)
	}
	annot := page.Annots[0]
	fmt.Println(annot.Visible.IsSet(), annot.Visible.Value(true))
	fmt.Println(annot.Print.IsSet(), annot.Print.Value(true))
	fmt.Println(*annot.Remark)
}
Output:
false true
true false
说明

type PageArea added in v0.1.9

type PageArea struct {
	// PhysicalBox 页面物理区域。
	PhysicalBox StBox `xml:"PhysicalBox"`
	// ApplicationBox 页面显示区域。
	ApplicationBox *StBox `xml:"ApplicationBox,omitempty"`
	// ContentBox 页面版心区域。
	ContentBox *StBox `xml:"ContentBox,omitempty"`
	// BleedBox 页面出血区域。
	BleedBox *StBox `xml:"BleedBox,omitempty"`
}

PageArea 是 GB/T 33190—2016 §7.5 表7的页面区域声明。 不在解码时补齐 A4 尺寸或执行页面/模板/文档之间的区域继承。

type PageBlock added in v0.1.9

type PageBlock struct {
	// CTPageBlock 页面对象块中的子对象。
	CTPageBlock

	// ID 页面对象块标识,在页面内唯一。
	ID StID `xml:"ID,attr"`
}

PageBlock 页面对象块,可以包含嵌套的页面对象。

func (*PageBlock) UnmarshalXML added in v0.1.9

func (p *PageBlock) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解析 PageBlock,读取 ID 属性后按文档顺序解析其内容。

type PageContent added in v0.1.9

type PageContent struct {
	// Area 页面的区域定义,不自动执行区域继承。
	Area *PageArea `xml:"Area,omitempty"`
	// Template 页面使用的模板页引用。
	Template []Template `xml:"Template"`
	// PageRes 页面级资源文件的位置。
	PageRes []StLoc `xml:"PageRes"`
	// Content 页面图层和页面对象内容。
	Content *Content `xml:"Content"`
	// Actions 页面级动作集合。
	Actions *Actions `xml:"Actions"`
}

PageContent 是 GB/T 33190—2016 §7.7 表12的页面内容声明,不包含加载状态或 A4 兜底。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var page spec.PageContent
	data := `<Page><Content><Layer ID="1"><TextObject ID="2" Boundary="0 0 10 10" Font="3" Size="3"><TextCode>甲\0020乙</TextCode></TextObject><PathObject ID="4" Boundary="0 0 10 10"><AbbreviatedData>M 0 0 L 1 1</AbbreviatedData></PathObject></Layer></Content></Page>`
	if err := xml.Unmarshal([]byte(data), &page); err != nil {
		panic(err)
	}
	items := page.Content.Layer[0].Items
	fmt.Println(items[0].Text.TextCode[0].Value)
	fmt.Println(items[1].Path.ID)
}
Output:
甲 乙
4

type PageItem added in v0.1.9

type PageItem struct {
	// Kind 页面对象的类型。
	Kind PageItemKind
	// Text 当 Kind 为 PageItemText 时保存的文字对象。
	Text *TextObject
	// Path 当 Kind 为 PageItemPath 时保存的路径对象。
	Path *PathObject
	// Image 当 Kind 为 PageItemImage 时保存的图像对象。
	Image *ImageObject
	// Composite 当 Kind 为 PageItemComposite 时保存的复合对象。
	Composite *CompositeObject
	// Block 当 Kind 为 PageItemBlock 时保存的嵌套页面对象块。
	Block *PageBlock
}

PageItem 按文档顺序保存页面块中的一个图形对象。 负载字段保存指针而非按值内嵌,使切片增长时只拷贝指针而不是整个联合结构体。 只有一个 Kind 对应的字段非空。

type PageItemKind added in v0.1.9

type PageItemKind int

PageItemKind 页面块中对象的种类。

const (

	// PageItemText 表示文字对象。
	PageItemText PageItemKind
	// PageItemPath 表示路径对象。
	PageItemPath
	// PageItemImage 表示图像对象。
	PageItemImage
	// PageItemComposite 表示复合对象。
	PageItemComposite
	// PageItemBlock 表示嵌套页面对象块。
	PageItemBlock
)

type PageLayout added in v0.1.9

type PageLayout string

PageLayout 文档打开时的页面布局方式。

type PageList added in v0.1.9

type PageList struct {
	// Pages 页面列表。
	Pages []PageRef `xml:"Page"`
}

PageList 是 §7.6 表11的页树,页面引用顺序即文档页序。

type PageMode added in v0.1.9

type PageMode string

PageMode 文档打开时的页面显示模式。

type PageRef added in v0.1.9

type PageRef struct {
	ID      StID  `xml:"ID,attr"` //nolint:tagliatelle // 标准属性名为 ID。
	BaseLoc StLoc `xml:"BaseLoc,attr"`
}

PageRef 是页树中的页面标识和内容文件引用,不是页面内容本身。

type Palette added in v0.1.9

type Palette struct {
	CV [][]string `xml:"CV"` //nolint:tagliatelle // OFD 标准元素名为 CV。
}

Palette 是 §8.3.1 表25的调色板,CV 的行下标即从0开始的颜色索引。 分量保留词法值,不在模型层按位深转换或校验。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var palette spec.Palette
	data := `<Palette><CV>255 0 0</CV><CV>0 255 0</CV></Palette>`
	if err := xml.Unmarshal([]byte(data), &palette); err != nil {
		panic(err)
	}
	fmt.Println(palette.CV[0], palette.CV[1])
}
Output:
[255 0 0] [0 255 0]

func (*Palette) UnmarshalXML added in v0.1.9

func (p *Palette) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 将每个 CV 元素的空白分隔颜色分量解析为独立的一行。

type Parameter added in v0.1.9

type Parameter struct {
	// Name 参数名称。
	Name string `xml:"Name,attr"`
	// Value 参数值。
	Value string `xml:",chardata"`
}

Parameter 单个注解参数。

type Params added in v0.1.9

type Params struct {
	// Parameters 注解参数列表。
	Parameters []Parameter `xml:"Parameter"`
}

Params 注解参数集合。

type PathCommand added in v0.1.9

type PathCommand struct {
	// Type 路径命令类型。
	Type CommandType
	// Points 命令使用的坐标点;弧命令使用 Arc 保存参数。
	Points []StPos
	// Arc 椭圆弧参数,仅当 Type 为 ArcTo 时有效。
	Arc *ArcData
}

PathCommand 定义一条路径命令及其参数。

type PathData added in v0.1.9

type PathData []PathCommand

PathData 是 OFD AbbreviatedData 的命令序列,不是 SVG 的 d 属性。 标准命令见§9.1表36;B 表示三次贝塞尔曲线,C 表示闭合。 解码沿用 S 归一化为 M、隐式直线、逗号分隔、SVG Z/z 闭合及负半径取绝对值的兼容行为。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	path, err := spec.ParsePathData("M 1.23456789 2 B 3 4 5 6 7 8 C")
	if err != nil {
		panic(err)
	}
	data, err := xml.Marshal(path)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(data))
}
Output:
<PathData>M 1.23456789 2 B 3 4 5 6 7 8 C</PathData>

func ParsePathData added in v0.1.9

func ParsePathData(data string) (PathData, error)

ParsePathData 解析 OFD 紧缩路径字符串并返回 PathData,不执行文档级标准校验。 输入为空或仅包含空白字符时返回空路径。

func (*PathData) AddCommand added in v0.1.9

func (p *PathData) AddCommand(cmd PathCommand)

AddCommand 将一条路径命令追加到路径末尾。

func (PathData) CalculateBoundingBox added in v0.1.9

func (p PathData) CalculateBoundingBox() (float64, float64, float64, float64)

CalculateBoundingBox 计算路径中坐标点的轴对齐边界框。 返回值依次为最小 X、最小 Y、最大 X 和最大 Y;空路径返回四个零值。 仅统计显式坐标与弧终点,不计算曲线极值,不能用作曲线的精确可见范围。

func (*PathData) Clear added in v0.1.9

func (p *PathData) Clear()

Clear 清空路径中的全部命令。

func (PathData) CountCommands added in v0.1.9

func (p PathData) CountCommands() map[CommandType]int

CountCommands 统计路径中各类命令的数量。

func (PathData) Format added in v0.1.9

func (p PathData) Format() string

Format 按易读格式返回路径命令列表。 每条命令单独占一行,并包含坐标或椭圆弧参数。

func (PathData) GetCommand added in v0.1.9

func (p PathData) GetCommand(index int) (PathCommand, error)

GetCommand 获取指定索引处的路径命令。 当索引越界时返回错误。

func (PathData) GetStartPoint added in v0.1.9

func (p PathData) GetStartPoint(cmdIndex int) (StPos, error)

GetStartPoint 获取指定命令执行前的当前点;闭合后返回子路径起点。 对于首条命令或找不到有效点的情况返回错误。

func (PathData) Length added in v0.1.9

func (p PathData) Length() int

Length 返回路径中的命令数量。

func (PathData) MarshalXML added in v0.1.9

func (p PathData) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML 将路径编码为表36的紧缩命令文本,不使用 String 的两位小数诊断格式。 命令参数数量必须匹配,数值必须有限;完整文档的图形规则仍由校验器检查。

func (PathData) String added in v0.1.9

func (p PathData) String() string

String 返回供诊断的两位小数字符串;精确保留数值的 XML 输出使用 MarshalXML。

func (*PathData) UnmarshalXML added in v0.1.9

func (p *PathData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 从 XML 元素的文本内容中解析路径命令。 路径数据由命令字母和空格分隔的数值参数组成,例如 M 10 20 L 30 40。

type PathObject added in v0.1.9

type PathObject struct {
	// CtPath 路径图元的通用属性和路径数据。
	CtPath

	// ID 路径对象标识,在页面内唯一。
	ID StID `xml:"ID,attr"`
}

PathObject 页面中的路径对象。

func (*PathObject) UnmarshalXML added in v0.1.9

func (o *PathObject) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 手写解码路径对象。

type Permissions added in v0.1.9

type Permissions struct {
	// Edit 是否允许编辑文档内容。
	Edit *bool `xml:"Edit,omitempty"`
	// Annot 是否允许添加或修改注解。
	Annot *bool `xml:"Annot,omitempty"`
	// Export 是否允许导出文档内容。
	Export *bool `xml:"Export,omitempty"`
	// Signature 是否允许签名。
	Signature *bool `xml:"Signature,omitempty"`
	// Watermark 是否允许添加或修改水印。
	Watermark *bool `xml:"Watermark,omitempty"`
	// PrintScreen 是否允许截屏。
	PrintScreen *bool `xml:"PrintScreen,omitempty"`
	// Print 为nil时默认允许打印且不限份数。
	Print *PrintSettings `xml:"Print,omitempty"`
	// ValidPeriod 为nil时不限期限;非nil时至少应有一个端点。
	ValidPeriod *ValidPeriod `xml:"ValidPeriod,omitempty"`
}

Permissions 是 GB/T 33190—2016 §7.5 表8的文档权限声明。 布尔指针保留省略与显式取值的区别,省略时按标准解释为允许。 本类型只保存声明,不表示调用方已获业务授权。

func (*Permissions) Clone added in v0.1.9

func (p *Permissions) Clone() *Permissions

Clone 深拷贝原始声明;nil接收者返回nil。副本不共享可变字段,且不缓存授权结果。

type PrintSettings added in v0.1.9

type PrintSettings struct {
	// Printable 是否允许打印。
	Printable bool `xml:"Printable,attr"`
	// Copies 允许打印的份数。
	Copies int `xml:"Copies,attr"`
}

PrintSettings 是表8的打印设置。Copies负值不限份数,零禁止打印,正值为允许份数。 XML缺省值由解码器应用;直接构造时零值表示禁止打印,不代表缺省允许。

func (*PrintSettings) UnmarshalXML added in v0.1.9

func (p *PrintSettings) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 按表8应用允许打印、份数不限的属性缺省值。

type Provider added in v0.1.9

type Provider struct {
	ProviderName string `xml:"ProviderName,attr"`
	Version      string `xml:"Version,attr,omitempty"`
	Company      string `xml:"Company,attr,omitempty"`
	ProtocolVer  string `xml:"ProtocolVer,attr,omitempty"`
	// ExtendData 按 GM/T 0099 图 B.2 写在 Provider 的子元素中。
	ExtendData string `xml:"ExtendData,omitempty"`
}

Provider 保存签章组件信息,ProtocolVer 和 ExtendData 为 GM/T 0099 扩展。

type Reference added in v0.1.9

type Reference struct {
	FileRef StLoc `xml:"FileRef,attr"`
	// CheckValue 沿用读取链的表示,保存 Base64 文本字节,而非解码后的二进制摘要。
	CheckValue []byte `xml:"CheckValue"`
}

Reference 保存原始文件引用和摘要文本。

type References added in v0.1.9

type References struct {
	CheckMethod string      `xml:"CheckMethod,attr,omitempty"` // MD5、SHA1、SHA256、SHA384、SHA512、SM3 或 SM3 OID
	Reference   []Reference `xml:"Reference"`
}

References 是 §18.2.2 表68的文件摘要列表,不加载引用文件。

type Region added in v0.1.9

type Region struct {
	Areas []RegionArea `xml:"Area"`
}

Region 是 §9.3 及附录A的复杂区域,可用于动作启动范围。

type RegionArea added in v0.1.9

type RegionArea struct {
	Start StPos        `xml:"Start,attr"`
	Paths []RegionPath `xml:",any"`
}

RegionArea 保存一个区域的起点及按文档顺序排列的线段。

type RegionPath added in v0.1.9

type RegionPath struct {
	XMLName        xml.Name          `xml:""` //nolint:tagliatelle // 空标签保留 XMLName 动态选择的线段元素名。
	Point1         *StPos            `xml:"Point1,attr,omitempty"`
	Point2         *StPos            `xml:"Point2,attr,omitempty"`
	Point3         *StPos            `xml:"Point3,attr,omitempty"`
	SweepDirection *bool             `xml:"SweepDirection,attr,omitempty"`
	LargeArc       *bool             `xml:"LargeArc,attr,omitempty"`
	RotationAngle  *float64          `xml:"RotationAngle,attr,omitempty"`
	EllipseSize    *StArray[float64] `xml:"EllipseSize,attr,omitempty"`
	EndPoint       *StPos            `xml:"EndPoint,attr,omitempty"`
}

RegionPath 保存 Move、Line、QuadraticBezier、CubicBezier、Arc 或 Close 元素。 XMLName 决定具体线段名称,既有解码行为也会保留未知元素名,不在这里执行校验。

type Res added in v0.1.9

type Res struct {
	// BaseLoc 资源文件的基础路径。
	BaseLoc StLoc `xml:"BaseLoc,attr"`
	// ColorSpaces 颜色空间资源集合。
	ColorSpaces *ColorSpaces `xml:"ColorSpaces"`
	// DrawParams 绘制参数资源集合。
	DrawParams *DrawParams `xml:"DrawParams"`
	// Fonts 字体资源集合。
	Fonts *Fonts `xml:"Fonts"`
	// MultiMedias 多媒体资源集合。
	MultiMedias *MultiMedias `xml:"MultiMedias"`
	// CompositeGraphicUnits 复合图形资源集合。
	CompositeGraphicUnits *CompositeGraphicUnits `xml:"CompositeGraphicUnits"`
}

Res 是 GB/T 33190—2016 §7.9 表18的资源文件声明,不包含资源数据或加载状态。 本批提供 XML 解码及声明访问,不提供完整资源文件的 XML 编码契约。

type Seal added in v0.1.9

type Seal struct {
	BaseLoc StLoc `xml:"BaseLoc,omitempty"`
	// ImageLoc 按图 B.2 的 ST_Loc 解释;表 B.2 的 ST_Box 与“图片存储位置”文字矛盾。
	ImageLoc StLoc `xml:"ImageLoc,omitempty"`
}

Seal 保存电子印章数据路径及 GM/T 0099 的图像路径扩展。

type Segment added in v0.1.9

type Segment struct {
	// Color 当前分段的颜色。
	Color CTColor `xml:"Color"`
	// Position 当前颜色在渐变中的位置。缺省时为零值,须结合 PositionSet 判断。
	Position float64 `xml:"Position,attr,omitempty"`
	// PositionSet 表示 Position 属性是否出现在 XML 中。
	PositionSet bool `xml:"-"`
}

Segment 渐变中的颜色分段。

func (*Segment) UnmarshalXML added in v0.1.9

func (s *Segment) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解码渐变段,并记录 Position 是否显式给出。

type Signature added in v0.1.9

type Signature struct {
	// ID 保留部分生产者在签名描述中重复写入的标识;标准标识位于签名索引中。
	ID          string     `xml:"ID,attr,omitempty"` //nolint:tagliatelle // OFD 标准属性名为 ID。
	SignedInfo  SignedInfo `xml:"SignedInfo"`
	SignedValue StLoc      `xml:"SignedValue"`
}

Signature 是 GB/T 33190—2016 §18.2 表67的签名描述,不包含索引属性和加载路径。 解码只保存声明,不读取签名值、不计算摘要,也不验证数字签名。

type SignatureParameter added in v0.1.9

type SignatureParameter struct {
	Name  string `xml:"Name,attr"`
	Type  string `xml:"Type,attr,omitempty"`
	Value string `xml:",chardata"`
}

SignatureParameter 是签名的扩展键值属性。

type SignatureParameters added in v0.1.9

type SignatureParameters struct {
	Items []SignatureParameter `xml:"Parameter"`
}

SignatureParameters 对应 GM/T 0099 表 B.2 的扩展属性集。

type SignatureRef added in v0.1.9

type SignatureRef struct {
	ID       string `xml:"ID,attr"` //nolint:tagliatelle // OFD 标准属性名为 ID。
	BaseLoc  StLoc  `xml:"BaseLoc,attr"`
	Type     string `xml:"Type,attr"`
	Relative string `xml:"Relative,attr"`
}

SignatureRef 保存签名的索引属性;Relative 是 GM/T 0099 的基础签名关联扩展。 ID 和 Relative 均保留字符串原文,不将 xs:ID 当作数字 ST_ID 处理。

type Signatures added in v0.1.9

type Signatures struct {
	XMLName    xml.Name       `xml:"Signatures"`
	Xmlns      string         `xml:"xmlns,attr"` //nolint:tagliatelle // XML 命名空间属性固定为小写 xmlns。
	MaxSignID  *string        `xml:"MaxSignId,omitempty"`
	Signatures []SignatureRef `xml:"Signature,omitempty"`
}

Signatures 是 GB/T 33190—2016 §18.1 表66的签名索引,不包含已加载的签名描述。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var index spec.Signatures
	data := `<Signatures><Signature ID="s1" BaseLoc="Sign_0/Signature.xml" Type="Sign"/></Signatures>`
	if err := xml.Unmarshal([]byte(data), &index); err != nil {
		panic(err)
	}
	ref := index.Signatures[0]
	fmt.Println(ref.ID, ref.Type)
	fmt.Println(ref.BaseLoc.Resolve("/Doc_0/Signs"))
}
Output:
s1 Sign
/Doc_0/Signs/Sign_0/Signature.xml

type SignedInfo added in v0.1.9

type SignedInfo struct {
	Provider          Provider             `xml:"Provider"`
	SignatureMethod   string               `xml:"SignatureMethod,omitempty"`
	SignatureDateTime string               `xml:"SignatureDateTime,omitempty"`
	Parameters        *SignatureParameters `xml:"Parameters,omitempty"`
	References        References           `xml:"References"`
	StampAnnot        []*StampAnnot        `xml:"StampAnnot,omitempty"`
	Seal              *Seal                `xml:"Seal,omitempty"`
}

SignedInfo 保存受签名保护的文件范围和签章组件信息。

type StArray added in v0.1.9

type StArray[T float64 | int] []T

StArray 是 GB/T 33190—2016 §7.3 表2的数值数组;T 按具体字段选择浮点值或整型值。 浮点数组支持文字定位使用的 g 重复记法;展开数量限制属于解析资源保护,不是标准限制。 整数数组沿用既有解析行为,忽略无法解析为整数的 token。

func (StArray[T]) MarshalXML added in v0.1.9

func (s StArray[T]) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML 将数组编码为空格分隔的数值元素,不重新压缩 g 重复记法。

func (StArray[T]) MarshalXMLAttr added in v0.1.9

func (s StArray[T]) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr 将数组编码为空格分隔的数值属性。

func (*StArray[T]) UnmarshalXML added in v0.1.9

func (s *StArray[T]) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 实现 xml.Unmarshaler 接口

func (*StArray[T]) UnmarshalXMLAttr added in v0.1.9

func (s *StArray[T]) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 实现 xml.UnmarshalerAttr 接口

type StBox added in v0.1.9

type StBox struct {
	X      float64 `xml:"X,attr"`
	Y      float64 `xml:"Y,attr"`
	Width  float64 `xml:"Width,attr"`
	Height float64 `xml:"Height,attr"`
}

StBox 是 §7.3 表2的矩形区域,字段顺序为 X、Y、Width、Height。 标准要求宽高大于零;解码为兼容既有文档保留零值和负值,不在这里执行文档校验。

func (*StBox) Area added in v0.1.9

func (b *StBox) Area() float64

Area 返回矩形区域的面积。

func (*StBox) CopyAndShift added in v0.1.9

func (b *StBox) CopyAndShift(box *StBox) StBox

CopyAndShift 返回按给定矩形的原点偏移后的副本。

func (StBox) IsFinite added in v0.1.9

func (b StBox) IsFinite() bool

IsFinite 判断矩形的坐标和尺寸是否都是有限数值。

func (*StBox) IsPortrait added in v0.1.9

func (b *StBox) IsPortrait() bool

IsPortrait 判断矩形是否纵向放置。

func (StBox) MarshalXML added in v0.1.9

func (b StBox) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML 按表2编码矩形区域元素。

func (StBox) MarshalXMLAttr added in v0.1.9

func (b StBox) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr 按表2编码矩形区域属性。

func (*StBox) String added in v0.1.9

func (b *StBox) String() string

String 返回按 X、Y、Width、Height 排列的字符串。

func (*StBox) UnmarshalXML added in v0.1.9

func (b *StBox) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解码矩形区域元素。

func (*StBox) UnmarshalXMLAttr added in v0.1.9

func (b *StBox) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 解码矩形区域属性。

type StID added in v0.1.9

type StID uint64

StID 是 GB/T 33190—2016 §7.3 表2的无符号对象标识,0 表示无效标识。 解码保留既有非规范文档兼容行为:非十进制或溢出的值映射为 CRC64。 该映射不是标准要求,也不保证无碰撞;编码只输出映射后的十进制整数。

func (*StID) UnmarshalText added in v0.1.9

func (p *StID) UnmarshalText(text []byte) error

UnmarshalText 解码十进制对象标识,并对非规范值沿用确定性的兼容映射。

func (*StID) UnmarshalXML added in v0.1.9

func (p *StID) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解码对象标识元素。

func (*StID) UnmarshalXMLAttr added in v0.1.9

func (p *StID) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 解码对象标识属性。

type StLoc added in v0.1.9

type StLoc string

StLoc 是 GB/T 33190—2016 §7.3 表2的包内位置字符串,区分大小写,使用斜杠分隔。 路径操作只做词法处理,不验证ZIP条目安全性,也不授权访问文件系统。

func (StLoc) Base added in v0.1.9

func (p StLoc) Base() string

Base 返回文件名部分

func (StLoc) Clean added in v0.1.9

func (p StLoc) Clean() StLoc

Clean 清理路径

func (StLoc) Dir added in v0.1.9

func (p StLoc) Dir() StLoc

Dir 返回目录部分

func (StLoc) Ext added in v0.1.9

func (p StLoc) Ext() string

Ext 返回扩展名

func (StLoc) HasPrefix added in v0.1.9

func (p StLoc) HasPrefix(prefix StLoc) bool

HasPrefix 判断是否有指定前缀

func (StLoc) In added in v0.1.9

func (p StLoc) In(dir StLoc) bool

In 按字符串前缀判断是否位于目录下;不清理路径,不能用于安全校验。

func (StLoc) IsAbsolute added in v0.1.9

func (p StLoc) IsAbsolute() bool

IsAbsolute 判断是否是绝对路径

func (StLoc) IsEmpty added in v0.1.9

func (p StLoc) IsEmpty() bool

IsEmpty 判断是否为空

func (StLoc) Join added in v0.1.9

func (p StLoc) Join(elem ...string) StLoc

Join 拼接路径

func (StLoc) Resolve added in v0.1.9

func (p StLoc) Resolve(base StLoc) StLoc

Resolve 解析路径 base: 基础路径

func (StLoc) String added in v0.1.9

func (p StLoc) String() string

String 转换为字符串

func (StLoc) TrimPrefix added in v0.1.9

func (p StLoc) TrimPrefix(prefix StLoc) StLoc

TrimPrefix 去除前缀

type StPos added in v0.1.9

type StPos struct {
	X float64
	Y float64
}

StPos 是 GB/T 33190—2016 §7.3 表2的点坐标,编码为以空格分隔的 X、Y。 解码额外保留既有逗号分隔的兼容写法。

func (StPos) MarshalXML added in v0.1.9

func (p StPos) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML 按表2编码点坐标元素。

func (StPos) MarshalXMLAttr added in v0.1.9

func (p StPos) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr 按表2编码点坐标属性。

func (*StPos) UnmarshalXML added in v0.1.9

func (p *StPos) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解码点坐标元素。

func (*StPos) UnmarshalXMLAttr added in v0.1.9

func (p *StPos) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 解码点坐标属性。

type StRefID added in v0.1.9

type StRefID StID

StRefID 是表2中对文档内对象标识的引用,解码与 StID 使用相同的兼容映射。

func (*StRefID) UnmarshalXML added in v0.1.9

func (p *StRefID) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解码标识引用元素。

func (*StRefID) UnmarshalXMLAttr added in v0.1.9

func (p *StRefID) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr 解码标识引用属性。

type StampAnnot added in v0.1.9

type StampAnnot struct {
	ID       string  `xml:"ID,attr"` //nolint:tagliatelle // 标准使用 xs:ID,不能映射为数字 ST_ID。
	PageRef  StRefID `xml:"PageRef,attr"`
	Boundary StBox   `xml:"Boundary,attr"`
	// Clip 是印章图上的裁剪窗口,坐标相对 Boundary 左上角、且不得超过
	// Boundary:只显示印章落在该窗口内的部分,贴在 Boundary 左上角加上
	// Clip 偏移处。骑缝章用它把同一枚印章按页切成若干条,每页用不同的 Clip
	// 显示其中一片。缺省(全零)表示显示整枚印章。
	Clip StBox `xml:"Clip,attr,omitempty"`
}

StampAnnot 是 §18.2.3 表69的签名外观定位,不加载印章图像。

type TabDisplay added in v0.1.9

type TabDisplay string

TabDisplay 文档标签中显示的标题类型。

type Template added in v0.1.9

type Template struct {
	// TemplateID 被引用模板页的标识。
	TemplateID StRefID `xml:"TemplateID,attr"`
	// ZOrder 模板页的叠放顺序,可为 Background 或 Foreground。
	ZOrder ZOrder `xml:"ZOrder,attr,omitempty"`
}

Template 页面使用的模板引用。

type TemplatePage added in v0.1.9

type TemplatePage struct {
	// ID 模板页标识,在文档内唯一。
	ID StID `xml:"ID,attr"` //nolint:tagliatelle // 标准属性名为 ID。
	// Name 模板页名称。
	Name *string `xml:"Name,attr,omitempty"`
	// ZOrder 模板页的叠放顺序。
	ZOrder ZOrder `xml:"ZOrder,attr,omitempty"`
	// BaseLoc 模板页内容文件的位置。
	BaseLoc StLoc `xml:"BaseLoc,attr"`
}

TemplatePage 是 §7.7 表13的模板页声明。

type TextCode added in v0.1.9

type TextCode struct {
	// Value 文字内容。
	Value string `xml:",chardata"`
	// X 文字起始位置的横坐标,单位为毫米。
	X float64 `xml:"X,attr,omitempty"`
	// Y 文字起始位置的纵坐标,单位为毫米。
	Y float64 `xml:"Y,attr,omitempty"`
	// DeltaX 字符在水平方向上的位置增量。
	DeltaX StArray[float64] `xml:"DeltaX,attr,omitempty"`
	// DeltaY 字符在垂直方向上的位置增量。
	DeltaY StArray[float64] `xml:"DeltaY,attr,omitempty"`
}

TextCode 文字编码及其定位信息。

type TextObject added in v0.1.9

type TextObject struct {
	// CtText 文字图元的通用属性和文字内容。
	CtText

	// ID 文字对象标识,在页面内唯一。
	ID StID `xml:"ID,attr"`
}

TextObject 页面中的文字对象。

func (*TextObject) UnmarshalXML added in v0.1.9

func (o *TextObject) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 手写解码文字对象。

type VPreferences added in v0.1.9

type VPreferences struct {
	// PageMode 文档打开时的页面显示模式。
	PageMode *PageMode `xml:"PageMode,omitempty"`
	// PageLayout 文档打开时的页面布局方式。
	PageLayout *PageLayout `xml:"PageLayout,omitempty"`
	// TabDisplay 文档标签中显示的标题类型。
	TabDisplay *TabDisplay `xml:"TabDisplay,omitempty"`
	// HideToolbar 是否隐藏工具栏。
	HideToolbar *bool `xml:"HideToolbar,omitempty"`
	// HideMenubar 是否隐藏菜单栏。
	HideMenubar *bool `xml:"HideMenubar,omitempty"`
	// HideWindowUI 是否隐藏窗口用户界面。
	HideWindowUI *bool `xml:"HideWindowUI,omitempty"` //nolint:tagliatelle // 标准元素名为 HideWindowUI。
	// Zoom 文档打开时的缩放设置。
	Zoom *ZoomSetting `xml:"-"`
}

VPreferences 是 §7.5 表9的视图首选项,保留可选字段的省略状态。 Zoom 在 Go 中分组保存,XML 解码从同级的 ZoomMode 和 Zoom 元素取得其值。

Example
package main

import (
	"encoding/xml"
	"fmt"

	"github.com/zc310/ofd/pkg/spec"
)

func main() {
	var preferences spec.VPreferences
	data := `<VPreferences><ZoomMode>FitWidth</ZoomMode><Zoom>1.25</Zoom></VPreferences>`
	if err := xml.Unmarshal([]byte(data), &preferences); err != nil {
		panic(err)
	}
	fmt.Println(*preferences.Zoom.Mode, *preferences.Zoom.Value)
}
Output:
FitWidth 1.25

func (*VPreferences) UnmarshalXML added in v0.1.9

func (p *VPreferences) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 按表9解码同级的 ZoomMode 和 Zoom,不应用显示策略缺省值。

type ValidPeriod added in v0.1.9

type ValidPeriod struct {
	// StartDate 权限生效时间。
	StartDate DateTime `xml:"StartDate,attr,omitempty"`
	// EndDate 权限失效时间。
	EndDate DateTime `xml:"EndDate,attr,omitempty"`
}

ValidPeriod 是表8的访问期限。端点均包含该时刻,缺失端点用零值表示。 空期限或倒置期限保留原声明,是否拒绝由权限策略判断。

type Version added in v0.1.9

type Version struct {
	// ID 文档版本标识。
	ID string `xml:"ID,attr"` //nolint:tagliatelle // OFD标准属性名为大写ID。
	// Index 文档版本序号。
	Index int `xml:"Index,attr"`
	// Current 是否为当前使用的版本。
	Current bool `xml:"Current,attr"`
	// BaseLoc 版本文件的基础路径。
	BaseLoc StLoc `xml:"BaseLoc,attr"`
}

Version 文档版本定义。

type VersionFile added in v0.1.9

type VersionFile struct {
	// ID 文件标识。
	ID string `xml:"ID,attr"` //nolint:tagliatelle // OFD标准属性名为大写ID。
	// Path 文件路径。
	Path StLoc `xml:",chardata"`
}

VersionFile 文档版本中的单个文件。

type Versions added in v0.1.9

type Versions struct {
	// Version 文档版本列表。
	VersionList []Version `xml:"Version"`
}

Versions 是§19.1表70的版本入口集合。

type ZOrder added in v0.1.9

type ZOrder string

ZOrder 模板页相对于页面内容的叠放顺序。

值可为 Background(背景层)或 Foreground(前景层)。 页面模板引用未显式指定时,按 OFD 规范取默认值 Background。

func (ZOrder) String added in v0.1.9

func (z ZOrder) String() string

String 返回叠放顺序的字符串形式。

type ZoomSetting added in v0.1.9

type ZoomSetting struct {
	// Mode 缩放模式。
	Mode *string `xml:"ZoomMode,omitempty"`
	// Value 缩放比例。
	Value *float64 `xml:"Zoom,omitempty"`
}

ZoomSetting 文档打开时的页面缩放设置。

Jump to

Keyboard shortcuts

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