canvas

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 33 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 canvas 提供 tdewolff/canvas 的 render 后端实现:DrawContext (canvasBackend)、矢量表面与 PDF 写入器(VectorSurface/PDFDocument)、 SVG 场景、离屏栅格表面、内置栅格后端(BackendCanvas),以及默认字体引擎 (Fonts)。

空白导入本包即可注册上述能力:

import _ "github.com/zc310/ofd/internal/render/backends/canvas"

Index

Constants

View Source
const (
	FontRegular    = drawing.FontRegular
	FontThin       = drawing.FontThin
	FontExtraLight = drawing.FontExtraLight
	FontLight      = drawing.FontLight
	FontMedium     = drawing.FontMedium
	FontSemiBold   = drawing.FontSemiBold
	FontBold       = drawing.FontBold
	FontExtraBold  = drawing.FontExtraBold
	FontBlack      = drawing.FontBlack
	FontItalic     = drawing.FontItalic
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CTColor

type CTColor = drawing.CTColor

字体样式常量与类型的本地别名,便于包内代码与测试直接引用。

type FontFace

type FontFace = drawing.FontFace

字体样式常量与类型的本地别名,便于包内代码与测试直接引用。

type FontFamily

type FontFamily = drawing.FontFamily

字体样式常量与类型的本地别名,便于包内代码与测试直接引用。

type FontStyle

type FontStyle = drawing.FontStyle

字体样式常量与类型的本地别名,便于包内代码与测试直接引用。

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) FaceObject

func (p *Fonts) FaceObject(family drawing.FontFamily, object models.TextObject, fill *drawing.CTColor) drawing.FontFace

FaceObject 为字体族与文字对象创建一个中性字体面。fill 为文字填充色/渐变。

func (*Fonts) FallbackFontFamily

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

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

func (*Fonts) HasLoadedEmbeddedFont

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

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

func (*Fonts) LoadFont

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

func (*Fonts) RegisterGlyphs

func (p *Fonts) RegisterGlyphs(id models.StRefID, pairs map[rune]uint16)

RegisterGlyphs 登记某个字体的 Unicode→字形映射。新增或变更映射时会作废该 字体已加载的族,使后续 LoadFont 用完整映射重建,保证渲染使用原始文本。

func (*Fonts) RegisterPageGlyphs

func (p *Fonts) RegisterPageGlyphs(doc *parser.Document, page *parser.Page, content *models.PageContent)

registerPageGlyphs 扫描页面(含模板与注释)的文字对象并登记字形映射。

func (*Fonts) RemoveFallbackFont

func (p *Fonts) RemoveFallbackFont(family string)

RemoveFallbackFont 移除本字体上下文先前通过 UseFallbackFont 登记的回退字体族, 使缺失字体不再回退到该族。全局注册表不回滚,但本上下文的回退集合与解析缓存会 重建,后续渲染即恢复为内嵌或默认字体。

func (*Fonts) RenderLock

func (p *Fonts) RenderLock(handle drawing.FontFamily) *sync.Mutex

func (*Fonts) UseFallbackFont

func (p *Fonts) UseFallbackFont(family string) error

UseFallbackFont 使当前字体上下文在缺失字体时使用已全局注册的回退字体族。 该字体族必须先通过 RegisterFallbackFont 注册;其全部已注册样式都会生效。

type TextRun

type TextRun = drawing.TextRun

字体样式常量与类型的本地别名,便于包内代码与测试直接引用。

Directories

Path Synopsis
Package canvasconv 提供 internal/render/geom 的中性几何类型与 tdewolff/canvas 类型之间的转换,供 canvas 后端(把 geom 绘制指令转成 canvas.Canvas 用于 Page()/PDF/SVG 矢量输出)以及迁移期的适配层使用。
Package canvasconv 提供 internal/render/geom 的中性几何类型与 tdewolff/canvas 类型之间的转换,供 canvas 后端(把 geom 绘制指令转成 canvas.Canvas 用于 Page()/PDF/SVG 矢量输出)以及迁移期的适配层使用。

Jump to

Keyboard shortcuts

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