creator

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Unlicense Imports: 24 Imported by: 0

Documentation

Overview

Package creator 根据高层文档模型创建 OFD 文件包。

Index

Constants

View Source
const (
	// LayerBody 表示普通正文图层。
	LayerBody = "Body"
	// LayerBackground 表示背景图层。
	LayerBackground = "Background"
	// LayerForeground 表示前景图层。
	LayerForeground = "Foreground"
	// LayerCustom 表示自定义图层。
	LayerCustom = "Custom"
)
View Source
const (
	PageModeNone          = "None"
	PageModeFullScreen    = "FullScreen"
	PageModeUseOutlines   = "UseOutlines"
	PageModeUseThumbs     = "UseThumbs"
	PageModeUseCustomTags = "UseCustomTags"
	PageModeUseLayers     = "UseLayers"
	PageModeUseAttatchs   = "UseAttatchs"
	PageModeUseBookmarks  = "UseBookmarks"

	PageLayoutOnePage    = "OnePage"
	PageLayoutOneColumn  = "OneColumn"
	PageLayoutTwoPageL   = "TwoPageL"
	PageLayoutTwoColumnL = "TwoColumnL"
	PageLayoutTwoPageR   = "TwoPageR"
	PageLayoutTwoColumnR = "TwoColumnR"

	TabDisplayDocTitle = "DocTitle"
	TabDisplayFileName = "FileName"
	ZoomModeDefault    = "Default"
	ZoomModeFitHeight  = "FitHeight"
	ZoomModeFitWidth   = "FitWidth"
	ZoomModeFitRect    = "FitRect"
)

Variables

View Source
var A4 = PageSize{Width: 210, Height: 297}

A4 是毫米单位的标准 A4 页面尺寸。

Functions

func Create

func Create(document Document, w io.Writer) error

Create 将完整的 OFD ZIP 文件包写入 w。

func CreateFile

func CreateFile(document Document, filename string) (err error)

CreateFile 在 filename 指定的位置创建 OFD 文件包。

func CreateWithOptions

func CreateWithOptions(document Document, w io.Writer, options CreateOptions) error

CreateWithOptions 按指定选项将完整的 OFD ZIP 文件包写入 w。

func Marshal

func Marshal(document Document) ([]byte, error)

Marshal 返回完整 OFD 文件包的字节数据。

func MarshalWithOptions

func MarshalWithOptions(document Document, options CreateOptions) ([]byte, error)

MarshalWithOptions 按指定选项返回完整 OFD 文件包的字节数据。

Types

type Action

type Action struct {
	Event  ActionEvent
	Region *ActionRegion
	URI    *URIAction
	Goto   *GotoAction
	GotoA  *GotoAAction
	Sound  *SoundAction
	Movie  *MovieAction
}

Action 描述一个 URI、页面、附件或媒体动作,且只能设置一个动作目标。

type ActionArea

type ActionArea struct {
	Start    Point
	Commands []RegionCommand
}

ActionArea 描述动作区域中的一条路径。

type ActionEvent

type ActionEvent string

ActionEvent 表示动作触发事件。

const (
	// ActionEventDO 表示文档打开或对象执行事件。
	ActionEventDO ActionEvent = "DO"
	// ActionEventPO 表示页面打开事件。
	ActionEventPO ActionEvent = "PO"
	// ActionEventClick 表示点击事件,也是默认事件。
	ActionEventClick ActionEvent = "CLICK"
)

type ActionRegion

type ActionRegion struct {
	Areas []ActionArea
}

ActionRegion 描述动作触发区域。

type Annotation

type Annotation struct {
	ID          uint64
	Type        string
	Creator     string
	LastModDate time.Time
	Visible     *bool
	Subtype     string
	Print       *bool
	NoZoom      bool
	NoRotate    bool
	ReadOnly    bool
	// ReadOnlyValue 用于显式写出 ReadOnly=false。为空时沿用 ReadOnly 的兼容行为。
	ReadOnlyValue *bool
	Remark        string
	Parameters    []AnnotationParameter
	Boundary      *Box
	Items         []Item
}

Annotation 描述页面注解及其外观。

type AnnotationPage

type AnnotationPage struct {
	Page  int
	Items []Annotation
}

AnnotationPage 描述某个页面的注解集合,Page 使用从 0 开始的页面索引。

type AnnotationParameter

type AnnotationParameter struct {
	Name  string
	Value string
}

AnnotationParameter 描述注解的自定义参数。

type Attachment

type Attachment struct {
	ID           string
	Name         string
	Format       string
	CreationDate time.Time
	ModDate      time.Time
	Visible      *bool
	Usage        string
	Data         []byte
	FileName     string
}

Attachment 描述文档附件及其包内数据。

type AxialShading

type AxialShading struct {
	MapType    string
	MapUnit    float64
	Extend     int
	StartPoint string
	EndPoint   string
	Segments   []ColorStop
}

AxialShading 描述轴向渐变。

type Bookmark

type Bookmark struct {
	Name string
	Goto GotoAction
}

Bookmark 描述文档书签及其页面目标。

type Box

type Box struct {
	X      float64
	Y      float64
	Width  float64
	Height float64
}

Box 描述页面区域或图元边界,单位为毫米。

type CGTransform

type CGTransform struct {
	CodePosition int
	CodeCount    int
	GlyphCount   int
	Glyphs       []int
}

CGTransform 描述文字分段中的字形映射关系。 CodePosition 是相对于整个文字对象的字符位置,从 0 开始。

type CTM

type CTM [6]float64

CTM 是 OFD 六参数坐标变换矩阵,顺序为 a、b、c、d、e、f。

type Clip

type Clip struct {
	Areas []ClipArea
}

Clip 描述一个裁剪区域定义。

type ClipArea

type ClipArea struct {
	DrawParam string
	CTM       *CTM
	Path      *ClipPath
	Text      *ClipText
}

ClipArea 描述一个路径或文字裁剪区域。

type ClipPath

type ClipPath struct {
	Boundary    Box
	Name        string
	Visible     *bool
	CTM         *CTM
	Data        string
	Stroke      bool
	StrokeSet   *bool
	Fill        bool
	Rule        string
	LineWidth   float64
	Cap         string
	Join        string
	MiterLimit  float64
	DashOffset  float64
	DashPattern []float64
	Alpha       *uint8
	StrokeColor *Color
	FillColor   *Color
}

ClipPath 是裁剪区域中的路径,Boundary 为必填边界。

type ClipText

type ClipText struct {
	Boundary      Box
	CTM           *CTM
	Font          string
	Size          float64
	Value         string
	TextCodes     []TextCode
	Stroke        bool
	Fill          *bool
	HScale        float64
	ReadDirection int
	CharDirection int
	Weight        int
	Italic        bool
	FillColor     *Color
	StrokeColor   *Color
}

ClipText 是裁剪区域中的文字,Font 为空时使用 SimSun。

type Clips

type Clips struct {
	Items []Clip
}

Clips 描述图元使用的裁剪区域集合。

type Color

type Color struct {
	R          uint8
	G          uint8
	B          uint8
	Components []int
	ColorSpace uint64
	Index      *int
	Alpha      *uint8
	Axial      *AxialShading
	Radial     *RadialShading
	Gouraud    *GouraudShading
	LaGouraud  *LaGouraudShading
	Pattern    *Pattern
}

Color 描述颜色值或渐变填充。未设置 Components、ColorSpace 和渐变时使用 RGB。

type ColorSpace

type ColorSpace struct {
	ID               uint64
	Type             string
	BitsPerComponent int
	Profile          string
	ProfileData      []byte
	Palette          []string
}

ColorSpace 描述 DocumentRes.xml 中的颜色空间资源。

type ColorStop

type ColorStop struct {
	Position float64
	Color    Color
}

ColorStop 描述渐变中的颜色分段。

type Composite

type Composite struct {
	X          float64
	Y          float64
	Width      float64
	Height     float64
	ResourceID uint64
	Name       string
	Visible    *bool
	DrawParam  string
	Actions    []Action
	CTM        *CTM
	Clips      *Clips
}

Composite 是页面中的复合图元对象。

type CompositeGraphicUnit

type CompositeGraphicUnit struct {
	ID           uint64
	Width        float64
	Height       float64
	Thumbnail    uint64
	Substitution uint64
	Items        []Item
}

CompositeGraphicUnit 描述资源中的复合图元定义。 ID 必须显式指定且在文档资源中唯一,Items 保存复合图元内部内容。

type CompressionMode

type CompressionMode string

CompressionMode 表示 OFD ZIP 条目的压缩策略。

const (
	// CompressionAuto 对已压缩格式使用 Store,其他文件使用 Deflate。
	CompressionAuto CompressionMode = "auto"
	// CompressionDeflate 对所有条目使用 Deflate。
	CompressionDeflate CompressionMode = "deflate"
	// CompressionStore 对所有条目使用 Store。
	CompressionStore CompressionMode = "store"
)

type CreateOptions

type CreateOptions struct {
	Compression   CompressionMode
	Deterministic bool
}

CreateOptions 控制 OFD ZIP 包的生成方式。

type CustomData

type CustomData struct {
	Name  string
	Value string
}

CustomData 描述 DocInfo 中的自定义元数据。

type CustomTag

type CustomTag struct {
	NameSpace  string
	Schema     []byte
	SchemaName string
	Data       []byte
	DataName   string
}

CustomTag 描述一个自定义标签清单及其数据文件。

type Document

type Document struct {
	ID             string
	Title          string
	Author         string
	Subject        string
	Abstract       string
	DocUsage       string
	Cover          string
	CoverData      []byte
	CoverName      string
	Keywords       []string
	CustomDatas    []CustomData
	Creator        string
	CreatorVersion string
	CreationDate   time.Time
	ModDate        time.Time
	PageSize       PageSize
	Area           *PageArea
	DrawParams     []DrawParam
	Fonts          []Font
	ColorSpaces    []ColorSpace
	DefaultCS      uint64
	PublicRes      []PublicResource
	Media          []Media
	Composites     []CompositeGraphicUnit
	Pages          []Page
	Templates      []TemplatePage
	Actions        []Action
	Outlines       []Outline
	Permissions    *Permissions
	Preferences    *ViewPreferences
	Bookmarks      []Bookmark
	Annotations    []AnnotationPage
	Attachments    []Attachment
	CustomTags     []CustomTag
	Extensions     []Extension
	Signatures     []Signature
	Versions       []DocumentVersion
}

Document 是 OFD 文件包的输入模型。 页面、对象坐标、对象尺寸和文字字号的单位均为毫米。

type DocumentVersion

type DocumentVersion struct {
	ID           string
	Index        int
	Current      bool
	Version      string
	Name         string
	CreationDate time.Time
	Files        []VersionFile
	DocRoot      []byte
	DocRootName  string
}

DocumentVersion 描述文档的一个版本及其文件清单。

type DrawParam

type DrawParam struct {
	Name        string
	Relative    string
	LineWidth   float64
	Join        string
	Cap         string
	DashOffset  float64
	DashPattern []float64
	MiterLimit  float64
	FillColor   *Color
	StrokeColor *Color
}

DrawParam 描述可被图层或图元引用的绘制参数资源。 Relative 使用另一个绘制参数的 Name 作为继承来源。

type Extension

type Extension struct {
	AppName    string
	Company    string
	AppVersion string
	Date       time.Time
	RefID      uint64
	Properties []ExtensionProperty
	Data       string
	// DataXML 是 Data 元素中的原始 XML 内容。设置后会作为子元素写入,
	// 与 Data 互斥;Data 适合只需要文本内容的扩展。
	DataXML  []byte
	DataFile []byte
	DataName string
}

Extension 描述文档扩展及其属性、内联数据或外部数据文件。

type ExtensionProperty

type ExtensionProperty struct {
	Name  string
	Type  string
	Value string
}

ExtensionProperty 描述扩展的键值属性。

type Font

type Font struct {
	Name       string
	FamilyName string
	Charset    string
	Italic     bool
	Bold       bool
	Serif      bool
	FixedWidth bool
	Format     string
	Data       []byte
}

Font 描述文档字体资源,Name 必须与 Text.Font 的值一致。 Data 非空时,字体数据会嵌入 OFD 文件包。

type GotoAAction

type GotoAAction struct {
	AttachID  string
	NewWindow *bool
}

GotoAAction 描述跳转到文档附件的动作。

type GotoAction

type GotoAction struct {
	Page     int
	Bookmark string
	Type     string
	Left     *float64
	Top      *float64
	Right    *float64
	Bottom   *float64
	Zoom     *float64
}

GotoAction 描述当前文档内的页面跳转动作。 Page 是从 0 开始的页面索引;Type 为空时使用 Fit。

type GouraudPoint

type GouraudPoint struct {
	X        float64
	Y        float64
	EdgeFlag int
	Color    Color
}

GouraudPoint 描述三角网格渐变控制点。

type GouraudShading

type GouraudShading struct {
	Extend    int
	Points    []GouraudPoint
	BackColor *Color
}

GouraudShading 描述三角网格渐变。

type Image

type Image struct {
	X            float64
	Y            float64
	Width        float64
	Height       float64
	Data         []byte
	ResourceID   uint64
	Substitution uint64
	ImageMask    uint64
	Format       string
	Name         string
	Visible      *bool
	LineWidth    float64
	Cap          string
	Join         string
	MiterLimit   float64
	DashOffset   float64
	DashPattern  []float64
	Alpha        *uint8
	DrawParam    string
	Actions      []Action
	CTM          *CTM
	Clips        *Clips
	Border       *ImageBorder
}

Image 是图片对象,Data 保存编码后的图片数据。 Format 是 PNG 或 JPEG 等 OFD 图片格式;为空时会尽量根据文件头识别。

type ImageBorder

type ImageBorder struct {
	LineWidth        float64
	HorizontalRadius float64
	VerticalRadius   float64
	DashOffset       float64
	DashPattern      []float64
	Color            *Color
}

ImageBorder 描述图片边框的线宽、圆角和虚线样式。

type Item

type Item interface {
	// contains filtered or unexported methods
}

Item 是 OFD 页面上的对象,可使用 Text、Path、Image、Composite 或 PageBlock。

type LaGouraudPoint

type LaGouraudPoint struct {
	X     float64
	Y     float64
	Color Color
}

LaGouraudPoint 描述四边形网格渐变控制点。

type LaGouraudShading

type LaGouraudShading struct {
	VerticesPerRow int
	Extend         int
	Points         []LaGouraudPoint
	BackColor      *Color
}

LaGouraudShading 描述四边形网格渐变。

type Layer

type Layer struct {
	Type      string
	DrawParam string
	Items     []Item
}

Layer 表示页面中的一个图层,图层顺序就是绘制顺序。

type Media

type Media struct {
	ID     uint64
	Type   string
	Format string
	Data   []byte
	Name   string
}

Media 描述文档级图片、音频或视频资源。

type MovieAction

type MovieAction struct {
	ResourceID uint64
	Operator   string
}

MovieAction 描述影片控制动作。

type Outline

type Outline struct {
	Title    string
	Count    *int
	Expanded *bool
	Actions  []Action
	Children []Outline
}

Outline 描述文档大纲项。大纲动作使用当前文档页面索引作为目标。

type Page

type Page struct {
	Area      *PageArea
	Resources []PageResource
	Templates []TemplateRef
	LayerType string
	Items     []Item
	Layers    []Layer
	Actions   []Action
}

Page 按绘制顺序保存页面对象。

type PageArea

type PageArea struct {
	PhysicalBox    *Box
	ApplicationBox *Box
	ContentBox     *Box
	BleedBox       *Box
}

PageArea 描述页面的物理区域、应用区域、内容区域和出血区域。 PhysicalBox 为空时使用文档的页面尺寸。

type PageBlock

type PageBlock struct {
	Items []Item
}

PageBlock 是可嵌套的页面对象容器。

type PageImage

type PageImage struct {
	ID     uint64
	Format string
	Data   []byte
	Name   string
}

PageImage 描述页面资源中的图片。ID 在文档内必须唯一。

type PageResource

type PageResource struct {
	Images []PageImage
	// Data 是完整的 OFD Res XML。用于页面专属的颜色空间、字体、绘制参数、
	// 多媒体或复合图元等资源;设置后不能同时设置 Images。
	Data []byte
	// Files 是 Data 中引用的、相对于 PageRes XML 所在目录的二进制文件。
	Files []PageResourceFile
}

PageResource 描述页面专属的资源文件。Images 适合快速创建页面图片资源; Data 可用于完整的 OFD Res 资源集合。

type PageResourceFile

type PageResourceFile struct {
	Path string
	Data []byte
}

PageResourceFile 描述页面资源 XML 引用的包内文件。

type PageSize

type PageSize struct {
	Width  float64
	Height float64
}

PageSize 描述页面尺寸,单位为毫米。

type Path

type Path struct {
	X           float64
	Y           float64
	Width       float64
	Height      float64
	Data        string
	Stroke      bool
	StrokeSet   *bool
	Fill        bool
	Rule        string
	Name        string
	Visible     *bool
	LineWidth   float64
	Cap         string
	Join        string
	MiterLimit  float64
	DashOffset  float64
	DashPattern []float64
	Alpha       *uint8
	DrawParam   string
	Actions     []Action
	CTM         *CTM
	Clips       *Clips
	StrokeColor *Color
	FillColor   *Color
}

Path 是路径对象。Data 使用 OFD 缩略路径语法,例如 "M 10 10 L 100 10 L 100 100 C"。

type Pattern

type Pattern struct {
	Width         float64
	Height        float64
	XStep         float64
	YStep         float64
	ReflectMethod string
	RelativeTo    string
	CTM           *CTM
	Thumbnail     uint64
	Items         []Item
	Layers        []Layer
	// contains filtered or unexported fields
}

Pattern 描述用于填充颜色的平铺图案。 图案单元中的对象使用 Items 或 Layers 配置,坐标单位为毫米。

type Permissions

type Permissions struct {
	Edit        *bool
	Annot       *bool
	Export      *bool
	Signature   *bool
	Watermark   *bool
	PrintScreen *bool
	Print       *PrintSettings
	ValidPeriod *ValidPeriod
}

Permissions 描述文档编辑、导出、打印等权限。

type Point

type Point struct {
	X float64
	Y float64
}

Point 描述区域路径中的二维点。

type PrintSettings

type PrintSettings struct {
	Printable bool
	Copies    *int
}

PrintSettings 描述打印权限和允许的打印份数。

type PublicResource

type PublicResource struct {
	Name  string
	Data  []byte
	Files []PublicResourceFile
}

PublicResource 描述一个嵌入 OFD 包的公共资源 XML 文件。 Name 是相对于 Doc_0 的文件名,Data 应为 Res 根元素的 XML 内容。

type PublicResourceFile

type PublicResourceFile struct {
	Path string
	Data []byte
}

PublicResourceFile 描述公共资源 XML 引用的包内文件。 Path 相对于公共资源 XML 所在目录。

type RadialShading

type RadialShading struct {
	MapType      string
	MapUnit      float64
	Eccentricity float64
	Angle        float64
	StartPoint   string
	StartRadius  float64
	EndPoint     string
	EndRadius    float64
	Extend       int
	Segments     []ColorStop
}

RadialShading 描述径向渐变。

type RegionArc

type RegionArc struct {
	SweepDirection bool
	LargeArc       bool
	RotationAngle  float64
	EllipseSize    Point
	EndPoint       Point
}

RegionArc 描述椭圆弧。

type RegionClose

type RegionClose struct{}

RegionClose 关闭当前路径。

type RegionCommand

type RegionCommand interface {
	// contains filtered or unexported methods
}

RegionCommand 是动作区域路径命令。

type RegionCubicBezier

type RegionCubicBezier struct {
	Control1 Point
	Control2 Point
	End      Point
}

RegionCubicBezier 描述三次贝塞尔曲线。

type RegionLine

type RegionLine struct{ Point Point }

RegionLine 连接到指定点。

type RegionMove

type RegionMove struct{ Point Point }

RegionMove 移动到指定点。

type RegionQuadraticBezier

type RegionQuadraticBezier struct {
	Control Point
	End     Point
}

RegionQuadraticBezier 描述二次贝塞尔曲线。

type Signature

type Signature struct {
	ID              string
	Type            string
	ProviderName    string
	ProviderVersion string
	Company         string
	Method          string
	Date            time.Time
	CheckMethod     string
	References      []SignatureReference
	StampAnnots     []SignatureStamp
	SealFile        []byte
	SealName        string
	SignedValue     []byte
	SignedValueName string
}

Signature 描述一个 OFD 签名清单项及其签名文件。

type SignatureReference

type SignatureReference struct {
	FileRef    string
	CheckValue []byte
}

SignatureReference 描述签名摘要引用。FileRef 相对于签名 XML 文件。

type SignatureStamp

type SignatureStamp struct {
	ID       string
	Page     int
	Boundary Box
	Clip     *Box
}

SignatureStamp 描述签名在页面上的盖章区域。

type SoundAction

type SoundAction struct {
	ResourceID  uint64
	Volume      *int
	Repeat      *bool
	Synchronous *bool
}

SoundAction 描述声音播放动作。

type TemplatePage

type TemplatePage struct {
	ID     uint64
	Name   string
	ZOrder string
	Area   *PageArea
	Items  []Item
	Layers []Layer
}

TemplatePage 描述文档模板页及其页面内容。 ID 必须在文档内唯一,页面通过该 ID 引用模板页。

type TemplateRef

type TemplateRef struct {
	ID     uint64
	ZOrder string
}

TemplateRef 描述页面使用的模板页引用。

type Text

type Text struct {
	X             float64
	Y             float64
	Width         float64
	Height        float64
	Value         string
	Font          string
	Size          float64
	Visible       *bool
	Stroke        bool
	Fill          *bool
	HScale        float64
	ReadDirection int
	CharDirection int
	Weight        int
	Italic        bool
	DrawParam     string
	CTM           *CTM
	TextCodes     []TextCode
	CGTransforms  []CGTransform
	Actions       []Action
	Clips         *Clips
	FillColor     *Color
	StrokeColor   *Color
}

Text 是文字对象,Size 表示字号,单位为毫米。

type TextCode

type TextCode struct {
	Value  string
	X      *float64
	Y      *float64
	DeltaX []float64
	DeltaY []float64
}

TextCode 描述文字对象中的一段文字及其定位信息。 X、Y 为空时沿用文字对象的排版位置;DeltaX、DeltaY 表示字符位置增量。

type URIAction

type URIAction struct {
	URI    string
	Base   string
	Target string
}

URIAction 描述外部 URI 动作。

type ValidPeriod

type ValidPeriod struct {
	Start time.Time
	End   time.Time
}

ValidPeriod 描述权限的生效和失效时间。

type VersionFile

type VersionFile struct {
	ID   string
	Path string
}

VersionFile 描述文档版本中的文件。

type ViewPreferences

type ViewPreferences struct {
	PageMode     string
	PageLayout   string
	TabDisplay   string
	HideToolbar  *bool
	HideMenubar  *bool
	HideWindowUI *bool
	ZoomMode     string
	Zoom         *float64
}

ViewPreferences 描述阅读器打开文档时的显示设置。

Jump to

Keyboard shortcuts

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