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

report

package
v0.1.6 Latest Latest
Warning

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

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

Documentation

Overview

Package report 提供报告格式推断、flow 排版、字体加载与标准文档输出。

Index

Constants

View Source
const Width = 174.0

Variables

View Source
var (
	Ink    = creator.Color{R: 35, G: 48, B: 62}
	Muted  = creator.Color{R: 91, G: 104, B: 117}
	Green  = creator.Color{R: 38, G: 125, B: 85}
	Red    = creator.Color{R: 184, G: 59, B: 58}
	Orange = creator.Color{R: 186, G: 113, B: 25}
	Blue   = creator.Color{R: 47, G: 104, B: 157}
)

Functions

func FromOutput

func FromOutput(output string) (string, bool)

FromOutput 根据报告输出路径扩展名推断报告格式。

func WriteOFD

func WriteOFD(ctx context.Context, w io.Writer, document *creator.Document) error

WriteOFD 将已分页模型写出,按实际使用字形子集化嵌入字体。

func WritePDF

func WritePDF(ctx context.Context, w io.Writer, document *creator.Document) error

WritePDF 先在内存中生成 OFD,再转换为可搜索的矢量 PDF。

Types

type Builder

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

Builder 累积报告内容,Build 统一返回文字准备或分页错误。

func New

func New(ctx context.Context, metadata creator.Document, fontPath string) (*Builder, error)

New 基于 flow 默认 Material 主题创建 A4、18mm 页边距、中文页码和章节大纲的报告。

func (*Builder) Block

func (b *Builder) Block(kind string, level int, text string, style flow.TextStyle)

Block 按块级样式添加内容,提前处理长路径和不可显示字符。

func (*Builder) Build

func (b *Builder) Build() (*creator.Document, error)

Build 返回完成分页的标准 creator 模型。

func (*Builder) Heading

func (b *Builder) Heading(level int, text string, color *creator.Color)

Heading 添加标题及其大纲,color 为空时使用标题颜色。

func (*Builder) Paragraph

func (b *Builder) Paragraph(text string, color *creator.Color)

Paragraph 添加可跨页的正文段落,color 为空时使用正文颜色。

func (*Builder) Table

func (b *Builder) Table(headers []string, rows [][]flow.TableCell, widths []float64, options ...TableOptions)

Table 添加带重复表头的网格表格;列宽包含单元格四周 1.5mm 的内边距。

type Font

type Font struct {
	Data []byte
	Face *sfnt.Font
	// contains filtered or unexported fields
}

Font 是排版度量与嵌入共用的字体快照。

func LoadFont

func LoadFont(explicit string) (Font, error)

LoadFont 加载显式字体或自动查找中文系统字体。

func (Font) PrepareText

func (f Font) PrepareText(ctx context.Context, text string, size, width float64) (string, error)

PrepareText 将控制字符、非法 XML 字符和缺字转义为可见文本。 仅当 UAX #14 的不可断片段超过整行时按字素补硬换行,不向文字层插入零宽字符。

type TableOptions

type TableOptions struct {
	// SplitRows 允许长单元格按完整文字行跨页续排,续页仍重复表头。
	SplitRows bool
	// ColumnAlign 按列设置表头和正文的水平对齐,空字符串沿用主题。
	ColumnAlign []string
}

TableOptions 配置报告表格的跨页方式。

Jump to

Keyboard shortcuts

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