render

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Unlicense Imports: 23 Imported by: 0 modules, 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 render 将解析后的 OFD 文档渲染为图形内容。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CTColor

type CTColor struct {
	Value    *color.RGBA
	Gradient canvas.Gradient
}

type Document

type Document struct {
	*parser.Document
	// contains filtered or unexported fields
}

func NewDocument

func NewDocument(background color.Color, doc *parser.Document) *Document

func (*Document) AddFallbackFont added in v0.0.9

func (p *Document) AddFallbackFont(data []byte, family string, style canvas.FontStyle) error

AddFallbackFont 注册在文档字体未内嵌时使用的字体。

func (*Document) Annot

func (p *Document) Annot(ctx *canvas.Context, annot *models.Annot, pb models.StBox)

func (*Document) Composite added in v0.0.5

func (p *Document) Composite(ctx *canvas.Context, object models.CompositeObject, dp *models.DrawParam, pb models.StBox)

Composite 绘制复合图元(CompositeObject)。

CompositeGraphicUnit 的内容位于自身的 [0,Width]x[0,Height] 坐标系中, 先渲染完整单元,再使用 CompositeObject 的 Boundary 和 CTM 映射到页面, 保留单元内部坐标,不根据透明像素重新裁剪内容。

func (*Document) Draw

func (p *Document) Draw(ctx *canvas.Context, page *parser.Page) error

func (*Document) FallbackFontFamily added in v0.0.9

func (p *Document) FallbackFontFamily(id models.StRefID) string

FallbackFontFamily 返回为文档字体选择的外部字体族。

func (*Document) HasLoadedEmbeddedFont added in v0.0.9

func (p *Document) HasLoadedEmbeddedFont(id models.StRefID) bool

HasLoadedEmbeddedFont 判断文档字体是否可以作为内嵌字体族提供给浏览器。

func (*Document) Image

func (p *Document) Image(ctx *canvas.Context, object models.ImageObject, dp *models.DrawParam, pb models.StBox)

func (*Document) Layer

func (p *Document) Layer(ctx *canvas.Context, layer *models.Layer, pb models.StBox)

func (*Document) Page

func (p *Document) Page(page *parser.Page) (*canvas.Canvas, error)

func (*Document) PageContent

func (p *Document) PageContent(ctx *canvas.Context, page *parser.Page, seal bool)

func (*Document) Path

func (p *Document) Path(ctx *canvas.Context, object models.PathObject, dp *models.DrawParam, pb models.StBox)

func (*Document) Seal

func (p *Document) Seal(ctx *canvas.Context, info *parser.SealInfo, pb models.StBox) error

func (*Document) Template

func (p *Document) Template(ctx *canvas.Context, template models.Template, pb models.StBox)

func (*Document) Text

func (p *Document) Text(ctx *canvas.Context, object models.TextObject, dp *models.DrawParam, pb models.StBox)

func (*Document) TextLayouts added in v0.0.9

func (p *Document) TextLayouts(page *parser.Page) []TextLayout

TextLayouts 返回页面文字的字符级布局。字符步进使用渲染器的字体度量、 DeltaX/DeltaY、ReadDirection 和 CTM 基础计算,避免网页字体度量造成高亮偏移。

type Fonts

type Fonts struct {
	*parser.Document
	Fonts map[models.StRefID]*canvas.FontFamily
	// contains filtered or unexported fields
}

func NewFonts

func NewFonts(doc *parser.Document) *Fonts

func (*Fonts) AddFallbackFont added in v0.0.9

func (p *Fonts) AddFallbackFont(data []byte, family string, style canvas.FontStyle) error

AddFallbackFont 为缺失的文档字体注册调用方提供的字体。 主要供 WASM 调用方在浏览器中获取 Web 字体后使用。

func (*Fonts) FallbackFontFamily added in v0.0.9

func (p *Fonts) FallbackFontFamily(id models.StRefID) string

FallbackFontFamily 返回为文档字体选择的外部字体族。 必须先调用 LoadFont;TextLayouts 和 Text 会自动完成这一步。

func (*Fonts) HasLoadedEmbeddedFont added in v0.0.9

func (p *Fonts) HasLoadedEmbeddedFont(id models.StRefID) bool

HasLoadedEmbeddedFont 判断文档字体是否解析为可用且已加载的字体族。 仅声明 FontFile 并不够,因为文件可能缺失、格式错误或被字体解析器拒绝。

func (*Fonts) LoadFont

func (p *Fonts) LoadFont(id models.StRefID) (*canvas.FontFamily, error)

type GlyphLayout added in v0.0.9

type GlyphLayout struct {
	Text   string
	X      float64
	Y      float64
	Width  float64
	Height float64
	Angle  float64
}

GlyphLayout 描述一个文字字符在页面上的近似区域。坐标单位为毫米, 使用页面左上角作为原点。

type TextLayout added in v0.0.9

type TextLayout struct {
	Text          string
	X             float64
	Y             float64
	Width         float64
	Height        float64
	Font          uint64
	Size          float64
	Weight        int
	ReadDirection int
	CharDirection int
	Bold          bool
	Italic        bool
	Glyphs        []GlyphLayout
}

TextLayout 描述一个 TextCode 及其字符级几何信息。

Jump to

Keyboard shortcuts

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