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

report

package
v0.1.7 Latest Latest
Warning

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

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

README

校验报告排版

pkg/validator/report 使用 pkg/creator/flow 的默认 Material 主题将 validator.Report 排版为 A4 OFD, 包含摘要、检查结果表格、问题明细表格、页码和章节大纲。PDF 由同一 OFD 通过 converter.PDF 转换,保留可搜索文字与矢量内容;中间 OFD 保存在内存中。 检查状态用颜色区分:未通过为红色,有警告或未完成为橙色,已通过为绿色,已跳过或未执行为灰色。 问题明细按「序号、级别/阶段、文件/XML 路径、问题说明」四列展示,前两列表头与正文水平居中,级别保留对应颜色。 说明列完整保留诊断信息、代码、引擎代码、依据和提示;空字段省略,原有顺序保持。 长路径自动换行,超长明细按完整文字行跨页续排,续页重复表头。

import (
    "context"
    "io"

    "github.com/zc310/ofd/pkg/validator"
    validatorreport "github.com/zc310/ofd/pkg/validator/report"
)

func writeReport(ctx context.Context, w io.Writer, result validator.Report) error {
    return validatorreport.RenderOFD(ctx, w, result, validatorreport.Options{
        Font: "/path/to/cjk-font.ttf",
    })
}

RenderPDF 接收相同参数。Build(ctx, result, options) 返回已分页的 *creator.Document,可供预览或进一步处理。上下文取消通过 errors.Is 识别。

Options.Font 支持 TTF、OTF 和 TTC;TTC 自动选择包含中文的字体面并提取为独立字体。 省略时自动查找常见中文系统字体。报告沿用默认主题的字号、行距、间距和配色,并按字体族查找 实际中文粗体,供标题和表头使用。同族粗体不可用时沿用常规字体。 TrueType 与 CFF 字体均按实际使用字形子集化,CID CFF 子集保留正确的 GID/CID 对应关系。 字体需要覆盖中文报告标签;诊断中的缺字、控制字符和非法 XML 字符以 \uXXXX 或 \UXXXXXXXX 展示。过长的不可断片段按字素补充换行,避免长路径、XML 路径或连续字符串越界。 需要原始诊断字段时使用 JSON 报告。

报告包独立于校验核心,创建器及 flow 的测试可以继续使用 pkg/validator 严格校验产物。

go test ./pkg/validator/... ./cmd/ofd-validator

Documentation

Overview

Package report 将校验结果排版为 OFD 报告,并由同一 OFD 生成可搜索的 PDF。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(ctx context.Context, report validator.Report, options Options) (*creator.Document, error)

Build 构建已分页的报告模型,供 OFD 输出、预览和其他标准格式转换复用。

func RenderOFD

func RenderOFD(ctx context.Context, w io.Writer, report validator.Report, options Options) error

RenderOFD 以 flow 排版并写出带嵌入字体、页码和大纲的标准 OFD 报告。

func RenderPDF

func RenderPDF(ctx context.Context, w io.Writer, report validator.Report, options Options) error

RenderPDF 先生成 OFD,再经 converter.PDF 写出文字和矢量 PDF;不创建中间文件。

Types

type Options

type Options struct {
	// Font 是中文 TTF、OTF 或 TTC 文件;为空时查找中文系统字体。
	// TTC 自动选择含中文的字体面,最终嵌入独立字体。
	Font string
}

Options 配置 OFD 和 PDF 共用的报告字体。

Jump to

Keyboard shortcuts

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