Documentation
¶
Overview ¶
Package compare 提供 OFD 包内文件、XML 结构、OFD/PDF 页面文字和画面、PNG/JPEG/WebP 图片及 TXT 全文的对比能力。
Index ¶
- Constants
- Variables
- func DocumentPageCount(ctx context.Context, filename string) (int, error)
- func WriteReport(w io.Writer, report *Report, format string) error
- type Comparison
- type DocumentInfo
- type DocumentPagePlan
- type DocumentPageSelection
- type DocumentPairOptions
- type Environment
- type File
- type FileChange
- type FontEnvironment
- type FontFace
- type IgnoreRegion
- type ImageSettings
- type Input
- type Options
- type PDFOptions
- type PDFProgramDiff
- type PDFProgress
- type PDFResourceBinding
- type PDFResourceChange
- type PDFSettings
- type PDFSourceUse
- type PDFStreamSource
- type PDFStructurePage
- type PDFStructureResult
- type Page
- type PageChange
- type PageMatchInfo
- type PagePair
- type PageRange
- type Report
- type Summary
- type TextBlock
- type TextLine
- type TextLocation
- type TextOrigin
- type TextRegion
- type TextResult
- type TextRow
- type TextSettings
- type TextSource
- type TextSpan
- type ValueChange
- type VisualChange
- type VisualRegion
- type XMLView
- type XMLViewBlock
- type XMLViewLine
Examples ¶
Constants ¶
const SchemaVersion = "1"
SchemaVersion 标识 JSON 报告格式,与工具发行版本相互独立。
Variables ¶
var ErrDocumentSelection = errors.New("文档选页参数无效")
ErrDocumentSelection 表示文档选页模式、范围或页对无效。
Functions ¶
func DocumentPageCount ¶ added in v0.2.5
DocumentPageCount 只检查文档目录和页数,供选页预览使用,不提取文字或渲染。 输入仍受 512 MiB 和 10000 页限制;比较时会重新读取独立快照。
Types ¶
type Comparison ¶
type Comparison struct {
Text *TextResult `json:"text,omitempty"`
PDFStructure *PDFStructureResult `json:"pdf_structure,omitempty"`
AllChecksEqual *bool `json:"all_checks_equal,omitempty"`
Target int `json:"target"`
Equal bool `json:"equal"`
PagesEqual bool `json:"pages_equal"`
Summary Summary `json:"summary"`
DirectoriesAdded []string `json:"directories_added"`
DirectoriesRemoved []string `json:"directories_removed"`
Files []FileChange `json:"files"`
Pages []PageChange `json:"pages"`
// CoverageWarnings 说明 PDF 比较未覆盖的内容,不改变当前规则下的相同判定。
CoverageWarnings []string `json:"coverage_warnings,omitempty"`
}
type DocumentInfo ¶
type DocumentPagePlan ¶ added in v0.2.5
DocumentPagePlan 保存确定的原始页配对。某侧为 0 表示该侧缺页。
func PlanDocumentPages ¶ added in v0.2.5
func PlanDocumentPages(counts [2]int, selection *DocumentPageSelection) (DocumentPagePlan, error)
PlanDocumentPages 按两侧实际总页数生成配对预览,不读取输入或渲染。 实际比较会使用快照的总页数重新校验,不依赖预览时的文件状态。
type DocumentPageSelection ¶ added in v0.2.5
type DocumentPageSelection struct {
Mode string `json:"mode"`
Pages [2]string `json:"pages,omitempty"`
Pairs string `json:"pairs,omitempty"`
}
DocumentPageSelection 指定文档之间的局部比较。nil 表示沿用整份文档检查。 Mode 为 ranges(默认,按两侧选中页的顺序配对)或 pairs(只比较列出的页对)。 Pages 使用原始全局页码,例如 "1-3,5";空值选择该侧全部页。 Pairs 使用 "2:3,4:7" 格式,两侧页码均不可重复;pairs 模式不同时设置 Pages。
type DocumentPairOptions ¶ added in v0.2.5
type DocumentPairOptions struct {
// PageSelection 非空时只比较选定页的文字和画面,不检查整包文件或文档结构。
// 仅适用于 OFD/PDF 文档之间;两侧使用独立的原始页范围或明确页对。
PageSelection *DocumentPageSelection
// TextEncodings 分别指定两侧 TXT 编码;空值为 auto。
TextEncodings [2]string
// TextMode 为 strict 或 content。TXT 之间默认 strict,TXT 与文档默认 content。
TextMode string
// TextPages 仅用于 TXT 与文档,空值为全文;范围使用原始文档页码。
TextPages string
// PDFBackend 为 poppler(默认)或 pdfium,同一次比较的文字和画面共用此后端。
// 原始图片之间的比较不使用此选项。
PDFBackend string
OnProgress func(PDFProgress)
// DocumentPage 用于图片与文档的画面对比;DPI 同时用于文档之间的画面对比。
// 零值分别为第 1 页和 144 DPI。
// 页码是文档从 1 开始的全局页码;图片始终使用原始像素,不缩放。
DocumentPage int
DPI float64
}
DocumentPairOptions 设置桌面式文档、图片或文本比较的选项及进度通知。
func NormalizeDocumentPairOptions ¶ added in v0.2.5
func NormalizeDocumentPairOptions(options DocumentPairOptions) (DocumentPairOptions, error)
NormalizeDocumentPairOptions 补全文档选页、DPI 和文本编码的默认值并校验,不读取输入。 PDF 后端是否适用及其校验由实际输入组合决定。
type Environment ¶ added in v0.2.4
type Environment struct {
Platform string `json:"platform"`
GoVersion string `json:"go_version"`
BuildRevision string `json:"build_revision,omitempty"`
BuildModified *bool `json:"build_modified,omitempty"`
Renderers map[string]string `json:"renderers"`
Tools map[string]string `json:"tools"`
Fonts FontEnvironment `json:"fonts"`
}
Environment 保存本次比较的工具版本及字体目录信息,供各格式报告复现环境。 字体清单描述 Fontconfig 可见的字体,不表示每页实际使用的字体。
type FileChange ¶
type FileChange struct {
Status string `json:"status"`
Before *File `json:"before,omitempty"`
After *File `json:"after,omitempty"`
XMLChanges []ValueChange `json:"xml_changes,omitempty"`
XMLTruncated bool `json:"xml_truncated,omitempty"`
// XMLView 保存有大小限制的规范化 XML 行对照;字段差异仍由 XMLChanges 提供。
XMLView *XMLView `json:"xml_view,omitempty"`
BeforePreview string `json:"before_preview,omitempty"`
AfterPreview string `json:"after_preview,omitempty"`
}
type FontEnvironment ¶ added in v0.2.4
type FontEnvironment struct {
Source string `json:"source"`
Status string `json:"status"`
CatalogSHA256 string `json:"catalog_sha256,omitempty"`
Catalog []FontFace `json:"catalog,omitempty"`
Note string `json:"note"`
}
FontEnvironment 的摘要只覆盖按顺序排列的家族与样式,不包含字体文件字节。
type IgnoreRegion ¶ added in v0.2.4
type IgnoreRegion struct {
Page int `json:"page"`
X float64 `json:"x_mm"`
Y float64 `json:"y_mm"`
Width float64 `json:"width_mm"`
Height float64 `json:"height_mm"`
}
IgnoreRegion 指定忽略区域。Page 为 0 时应用于所有页,否则为原始页码。
type ImageSettings ¶ added in v0.2.5
type ImageSettings struct {
Alignment string `json:"alignment"`
Background string `json:"background"`
// DocumentInput 从 1 开始标识文档一侧,0 表示两侧都是原始图片。
DocumentInput int `json:"document_input,omitempty"`
DocumentPage int `json:"document_page,omitempty"`
}
ImageSettings 记录含图片输入的比较规则。相同判定仅覆盖白底合成后的像素和尺寸。
type Input ¶
type Input struct {
Text *TextSource `json:"text,omitempty"`
// Format 标记实际输入格式:ofd、pdf、png、jpeg、webp 或 txt。
Format string `json:"format,omitempty"`
Name string `json:"name"`
Size int64 `json:"size"`
SHA256 string `json:"sha256,omitempty"`
Documents int `json:"documents"`
Files []File `json:"files"`
Directories []string `json:"directories"`
Pages []Page `json:"pages"`
Metadata []DocumentInfo `json:"metadata"`
}
type Options ¶
type Options struct {
// Language 选择报告语言(zh-CN、zh-Hant 或 en),不支持的语言回退到 zh-CN。
Language string `json:"language,omitempty"`
// Baseline 是从 0 开始的输入索引,其他文件分别与该基准比较。
Baseline int `json:"baseline_index"`
// PageMatch 为 auto(默认)或 number。自动匹配优先关联相同页面内容或
// 唯一的相同非空文字,再结合定位点和文字相似度配对修改页。
PageMatch string `json:"page_match"`
// PageMap 手工指定各目标相对基准的原始页码,例如 "2:3,4:5"。
// 两侧页码不能重复,必须在所选范围内;仅适用于 auto 匹配。
PageMap string `json:"page_map,omitempty"`
// Pages 指定各输入中从 1 开始的全局页码,例如 "1-3,5"。
// 空值选择全部页面;包内文件对比始终覆盖所有条目。
Pages string `json:"pages,omitempty"`
// Visual 启用像素对比及页面预览,默认内嵌图片。
Visual bool `json:"visual"`
// DPI 默认为 72;PixelTolerance 是每个颜色通道允许的差值,范围为 0–255。
DPI float64 `json:"dpi"`
PixelTolerance int `json:"pixel_tolerance"`
// MinRegionPixels 过滤较小的视觉区域,不改变原始像素统计和相同判定。
// 零值按 1 处理,即保留所有变化区域。
MinRegionPixels int `json:"min_region_pixels"`
// MaxXMLBytes 限制每个 XML 的结构分析大小,默认为 8 MiB。超过上限时
// 仍计算文件摘要,并明确记录未进行结构比较。
MaxXMLBytes int64 `json:"max_xml_bytes"`
// MaxXMLStructureBytes 限制单个 XML 字段表的估算大小,默认 32 MiB。
// 每次只保留当前文件两侧的字段表,比较后释放。
MaxXMLStructureBytes int64 `json:"max_xml_structure_bytes"`
// MaxChanges 限制每个 XML 的差异明细条数,默认为 200。
MaxChanges int `json:"max_changes"`
// MaxPagePixels 和 MaxTotalPixels 限制单页与累计视觉工作量,默认分别为 1000 万和 10 亿。
MaxPagePixels int64 `json:"max_page_pixels"`
MaxTotalPixels int64 `json:"max_total_pixels"`
// MaxPreviewBytes 限制所有预览图累计编码后的 PNG 字节数,默认 64 MiB。
// MaxReportBytes 限制保留的报告数据和最终输出字节数,默认 256 MiB。
MaxPreviewBytes int64 `json:"max_preview_bytes"`
MaxReportBytes int64 `json:"max_report_bytes"`
// BaselineCacheBytes 限制基准页 RGBA 缓存,默认 64 MiB;-1 禁用。
// 缓存命中不重复扣渲染像素预算,超过容量的单页不会缓存。
BaselineCacheBytes int64 `json:"baseline_cache_bytes"`
// ImageWriter 可将每张 PNG 写入外部存储并返回相对图片 URL。
// 返回地址必须为安全的相对路径;零值将图片以 base64 内嵌。
// 外部图片的创建和失败清理由调用方负责,写入错误会终止比较。
ImageWriter func([]byte) (string, error) `json:"-"`
// contains filtered or unexported fields
}
Options 控制对比范围。零值启用文件、结构和文字对比。
type PDFOptions ¶ added in v0.2.4
type PDFOptions struct {
Options
// Structure 检查所选页面的绘图指令及其使用的资源。
Structure bool
// PreviewUnchanged 在画面一致的配对页保存一张宽高均不超过 640 像素的基准预览。
PreviewUnchanged bool
// Profile 为 review(默认)或 regression,分别默认按内容或页序配对。
// 显式指定的 PageMatch 和 DPI 优先于模式默认值。
Profile string
// Backend 选择文字提取和画面渲染后端:poppler(默认)或 pdfium。
// 实际后端在文本提取与渲染间保持一致,失败时不自动切换。
Backend string
// IgnoreRegions 同时过滤区域内的文字和画面,使用旋转后可见页面的毫米坐标。
IgnoreRegions []IgnoreRegion
// MaxInputBytes、MaxTextBytes 分别限制每份 PDF 和每页文字提取输出。
// 默认分别为 512 MiB 和 8 MiB;MaxPages 默认 10000。
MaxInputBytes int64
MaxTextBytes int64
MaxPages int
// TempDir 是临时快照目录的父目录,空值使用系统临时目录。
TempDir string
// OnProgress 在比较协程中同步通知当前阶段;回调应快速返回。
// 多次并行比较共用回调时,调用方负责同步共享数据。
OnProgress func(PDFProgress)
}
PDFOptions 控制 PDF 比较。零值使用审阅模式,仅比较文字与页面尺寸; Visual 为 true 时同时渲染画面。嵌入的 Options 中 XML 选项不适用于 PDF。
func NormalizePDFOptions ¶ added in v0.2.4
func NormalizePDFOptions(options PDFOptions) (PDFOptions, error)
NormalizePDFOptions 校验并补全规则,不读取输入或运行外部工具。 CLI 可在进入业务处理前调用它,区分参数错误与运行失败。
type PDFProgramDiff ¶ added in v0.2.4
type PDFProgress ¶ added in v0.2.4
PDFProgress 描述即将执行的工作。Stage 为 tools、snapshot、inspect、 text、structure、compare 或 render;Path 为原始输入路径,工具检查阶段为空。 Page 使用原始页码,0 表示整个文件;Pages 为文档总页数,未知时为 0。
type PDFResourceBinding ¶ added in v0.2.4
type PDFResourceBinding struct {
Slot string `json:"slot"`
Before string `json:"before,omitempty"`
After string `json:"after,omitempty"`
}
PDFResourceBinding 将规范化指令中的资源编号映射到两个输入的原始名称和对象引用。
type PDFResourceChange ¶ added in v0.2.4
type PDFResourceChange struct {
ValueChange
BeforeRef string `json:"before_ref,omitempty"`
AfterRef string `json:"after_ref,omitempty"`
Pages []PagePair `json:"pages"`
}
PDFResourceChange 将同一对资源中的同一字段差异关联到各引用页。
type PDFSettings ¶ added in v0.2.4
type PDFSettings struct {
Structure bool `json:"structure,omitempty"`
Profile string `json:"profile"`
Backend string `json:"backend"`
TextNormalization string `json:"text_normalization"`
IgnoreRegions []IgnoreRegion `json:"ignore_regions,omitempty"`
MaxInputBytes int64 `json:"max_input_bytes"`
MaxTextBytes int64 `json:"max_text_bytes"`
MaxPages int `json:"max_pages"`
Tools map[string]string `json:"tools"`
Platform string `json:"platform"`
FontCatalogSHA256 string `json:"font_catalog_sha256,omitempty"`
FontNote string `json:"font_note"`
Warnings []string `json:"warnings,omitempty"`
}
PDFSettings 保存实际生效的规则和环境,随 JSON、HTML 和文本报告输出。
type PDFSourceUse ¶ added in v0.2.4
PDFSourceUse 指向本目标报告中从 1 开始的流编号。
type PDFStreamSource ¶ added in v0.2.4
type PDFStreamSource struct {
Path string `json:"path"`
Reference string `json:"reference,omitempty"`
Filters []string `json:"filters,omitempty"`
StoredBytes int `json:"stored_bytes"`
StoredSHA256 string `json:"stored_sha256"`
PayloadBytes int `json:"payload_bytes"`
Preview string `json:"preview,omitempty"`
Truncated bool `json:"truncated,omitempty"`
Pages []int `json:"pages,omitempty"`
Side string `json:"side,omitempty"`
}
PDFStreamSource 记录存储信息。绘图流额外保留带字节转义的有界原文。
type PDFStructurePage ¶ added in v0.2.4
type PDFStructurePage struct {
Bindings []PDFResourceBinding `json:"bindings,omitempty"`
Equal bool `json:"equal"`
Fields []ValueChange `json:"fields,omitempty"`
Programs []PDFProgramDiff `json:"programs,omitempty"`
BeforeSources []PDFSourceUse `json:"before_sources,omitempty"`
AfterSources []PDFSourceUse `json:"after_sources,omitempty"`
ResourceChanges []int `json:"resource_changes,omitempty"`
Truncated bool `json:"truncated,omitempty"`
}
PDFStructurePage 的字段路径以页或 Form 的有效资源作用域为起点。
type PDFStructureResult ¶ added in v0.2.4
type PDFStructureResult struct {
// CreationDateOnly 仅在核实文件其余字节完全相同时提供。
CreationDateOnly *ValueChange `json:"creation_date_only,omitempty"`
Sources []PDFStreamSource `json:"sources,omitempty"`
ResourceChanges []PDFResourceChange `json:"resource_changes,omitempty"`
Equal bool `json:"equal"`
FileBytesEqual bool `json:"file_bytes_equal"`
ChangedPages int `json:"changed_pages"`
DetailsHidden bool `json:"details_hidden,omitempty"`
// contains filtered or unexported fields
}
PDFStructureResult 描述选中页面的结构比较与整份文件的字节比较。
type Page ¶
type Page struct {
// PixelWidth、PixelHeight 用于原始图片及混合比较中实际渲染的文档页。
// 原始图片没有毫米尺寸;文档页保留其物理尺寸。
PixelWidth int `json:"pixel_width,omitempty"`
PixelHeight int `json:"pixel_height,omitempty"`
Number int `json:"number"`
Document int `json:"document"`
PageInDocument int `json:"page_in_document"`
Width float64 `json:"width_mm"`
Height float64 `json:"height_mm"`
Text string `json:"text"`
ContentSHA256 string `json:"content_sha256"`
Rotation int `json:"rotation,omitempty"`
// Selected 标记是否属于 Options.Pages 或 DocumentPair 的单侧选页范围。未选页只保留序号,
// 不提取文字、尺寸或内容摘要,也不参与配对和渲染。
Selected bool `json:"selected"`
}
type PageChange ¶
type PageChange struct {
PDFStructure *PDFStructurePage `json:"pdf_structure,omitempty"`
Status string `json:"status"`
Before int `json:"before,omitempty"`
After int `json:"after,omitempty"`
Moved bool `json:"moved"`
// Match 记录实际采用的配对依据,独立于页面是否发生变化。
Match PageMatchInfo `json:"match"`
TextChanged bool `json:"text_changed"`
SizeChanged bool `json:"size_changed"`
TextDiff []TextSpan `json:"text_diff,omitempty"`
TextDiffCoarse bool `json:"text_diff_coarse,omitempty"`
Visual *VisualChange `json:"visual,omitempty"`
// TextRegions 定位 PDF 中发生文字变化的词,坐标单位为毫米。
TextRegions []TextRegion `json:"text_regions,omitempty"`
}
type PageMatchInfo ¶
type PageMatchInfo struct {
Method string `json:"method"`
// TextSimilarity 仅用于 text_similarity,范围为 0–1,是文字特征相似度,
// 不代表页面相同的概率或视觉相似度。
TextSimilarity float64 `json:"text_similarity,omitempty"`
// SearchLimited 表示相似度搜索达到工作量上限;只标记随后顺序配对或未匹配的页面。
SearchLimited bool `json:"search_limited,omitempty"`
}
PageMatchInfo 描述配对依据:manual、content、text、text_similarity、 sequence(自动匹配的顺序兜底)、number(显式顺序匹配)、unmatched。
Example ¶
package main
import (
"context"
"fmt"
"github.com/zc310/ofd/pkg/compare"
)
func main() {
file := "../../testdata/ofd-creator/helloworld.ofd"
report, err := compare.Files(context.Background(), []string{file, file}, compare.Options{})
if err != nil {
panic(err)
}
fmt.Println(report.Comparisons[0].Pages[0].Match.Method)
}
Output: content
type PagePair ¶
PagePair 指定基准和目标中从 1 开始的原始全局页码。
func ParsePageMap ¶
ParsePageMap 解析 "2:3,4:5" 格式的手工页映射,拒绝重复或无效页码。
Example ¶
package main
import (
"fmt"
"github.com/zc310/ofd/pkg/compare"
)
func main() {
pairs, err := compare.ParsePageMap("2:3,4:5")
if err != nil {
panic(err)
}
for _, pair := range pairs {
fmt.Printf("%d → %d\n", pair.Before, pair.After)
}
}
Output: 2 → 3 4 → 5
type PageRange ¶
type PageRange struct{ First, Last int }
PageRange 是从 1 开始的全局页码闭区间。
func ParsePageRanges ¶
ParsePageRanges 将 "1-3,5" 解析为排序并合并后的区间,空值表示全部页面。 区间不展开为逐页列表,避免极大端点造成无界分配或页码循环溢出。
type Report ¶
type Report struct {
// PageSelection 非空时结论只覆盖两侧指定页的文字和画面,不包含整包或结构检查。
PageSelection *DocumentPageSelection `json:"page_selection,omitempty"`
// Text 非空表示全文文字比较,结论仅覆盖所选规则下的解码或提取文字。
Text *TextSettings `json:"text,omitempty"`
// Image 非空表示至少一侧为图片,仅比较画面像素和尺寸,不检查文字或文档结构。
Image *ImageSettings `json:"image,omitempty"`
CrossFormat bool `json:"cross_format,omitempty"`
SchemaVersion string `json:"schema_version"`
ToolVersion string `json:"tool_version"`
Baseline int `json:"baseline"`
Options Options `json:"options"`
Inputs []Input `json:"inputs"`
Comparisons []Comparison `json:"comparisons"`
// Environment 记录文档或图片比较实际使用的环境。
Environment *Environment `json:"environment,omitempty"`
// PDF 在涉及 PDF 的文档报告中存在,记录模式和实际比较环境。
PDF *PDFSettings `json:"pdf,omitempty"`
}
Report 记录各目标相对 Inputs[Baseline-1] 的差异。报告中的输入和页面序号 从 1 开始;页面或文件在一侧不存在时,省略对应字段。
func DocumentPair ¶ added in v0.2.4
func DocumentPair(ctx context.Context, baseline, target string, settings *DocumentPairOptions) (*Report, error)
DocumentPair 比较文档、图片或文本,并支持 TXT 与文档全文及图片与文档指定页。 文档默认整篇按页序以 144 DPI 比较,可设置 DPI 或 PageSelection;图片保持原始像素。 文档同格式检查对应的内部结构,跨格式只比较可见页面和提取文字;图片只比较尺寸和像素。 TXT 默认严格比较,TXT 与文档默认按内容比较;均只核对文字,不生成 TXT 文档页或执行 OCR。 每份输入先复制为独立快照,后续源文件更新不影响已复制的输入。 settings 为 nil 时,涉及 PDF 的比较使用 Poppler,且不发送进度通知。
func Files ¶ added in v0.2.4
Files 对比两份或多份本地 OFD 文件,源文件只读。 每份输入先复制为独立临时快照,解析、包内摘要、XML 和渲染均读取该快照。 输入、解析、渲染或取消失败均返回错误;选中页面不会因失败而被静默跳过。
Example ¶
package main
import (
"context"
"fmt"
"github.com/zc310/ofd/pkg/compare"
)
func main() {
file := "../../testdata/ofd-creator/helloworld.ofd"
report, err := compare.Files(context.Background(), []string{file, file}, compare.Options{})
if err != nil {
panic(err)
}
fmt.Println(report.Comparisons[0].Equal)
}
Output: true
func PDFFiles ¶ added in v0.2.4
PDFFiles 比较两份或多份本地 PDF。文档检查使用 pdfcpu; 默认使用 Poppler 的 pdftotext 和 pdftoppm;Backend 为 pdfium 时使用内嵌 WebAssembly。 输入先复制到独立临时快照,保证报告摘要与实际读取内容一致。 相同判定覆盖所选页面的文字、尺寸、页序和已启用的画面,不比较 PDF 内部字节或元数据。
func (*Report) HasPackageComparison ¶ added in v0.2.5
HasPackageComparison 表示报告是否检查了 OFD 包内文件和 XML。
func (*Report) HasTextComparison ¶ added in v0.2.5
HasTextComparison 表示报告是否比较全文或提取文字;原始图片没有文字提取或 OCR。
type Summary ¶
type Summary struct {
FilesAdded int `json:"files_added"`
FilesRemoved int `json:"files_removed"`
FilesModified int `json:"files_modified"`
FilesMoved int `json:"files_moved"`
PagesAdded int `json:"pages_added"`
PagesRemoved int `json:"pages_removed"`
PagesModified int `json:"pages_modified"`
PagesMoved int `json:"pages_moved"`
VisualPagesChanged int `json:"visual_pages_changed"`
}
type TextBlock ¶ added in v0.2.5
type TextBlock struct {
Equal bool `json:"equal"`
Folded bool `json:"folded"`
Rows []TextRow `json:"rows"`
}
TextBlock 的 Folded 只是建议的初始展示状态,不影响比较结论。
type TextLine ¶ added in v0.2.5
type TextLine struct {
Number int `json:"number"`
Start int `json:"start"`
End int `json:"end"`
Text string `json:"text"`
Page int `json:"page,omitempty"`
Origins []TextOrigin `json:"origins,omitempty"`
}
TextLine 的 Start、End 是规范化全文中从 0 开始的 Unicode 字符半开区间。 Text 包含原始行末换行(若有),Number 是从 1 开始的原始行号。
type TextLocation ¶ added in v0.2.5
TextLocation 描述比较单元所覆盖的原始行号及文档原始页码。
type TextOrigin ¶ added in v0.2.5
type TextOrigin struct {
Start int `json:"start"`
End int `json:"end"`
SourceStart int `json:"source_start"`
SourceEnd int `json:"source_end"`
Line int `json:"line"`
Page int `json:"page,omitempty"`
}
TextOrigin 将比较字符区间映射回原文字符区间和来源行、页;均采用半开区间。
type TextRegion ¶ added in v0.2.4
TextRegion 标出变化词的完整边界;Side 为 before 或 after,坐标单位为毫米。
type TextResult ¶ added in v0.2.5
type TextResult struct {
Blocks []TextBlock `json:"blocks"`
Changes int `json:"changes"`
Added int `json:"added_lines"`
Removed int `json:"removed_lines"`
Modified int `json:"modified_lines"`
Coarse bool `json:"coarse"`
}
TextResult 按连续相同或变化的行组织全文差异;达到搜索上限时保留完整原文。
type TextRow ¶ added in v0.2.5
type TextRow struct {
Before int `json:"before,omitempty"`
After int `json:"after,omitempty"`
Spans []TextSpan `json:"spans,omitempty"`
Coarse bool `json:"coarse,omitempty"`
}
TextRow 按来源行号关联两侧文字,0 表示该侧缺行;Spans 保留换行字符。
type TextSettings ¶ added in v0.2.5
type TextSettings struct {
Normalization string `json:"normalization"`
Encodings [2]string `json:"encodings"`
Mode string `json:"mode"`
DocumentInput int `json:"document_input,omitempty"`
DocumentPages string `json:"document_pages,omitempty"`
EmptyPages []int `json:"empty_pages,omitempty"`
}
TextSettings 记录参与相同判定的文本规则;编码和 BOM 不参与判定。
type TextSource ¶ added in v0.2.5
type TextSource struct {
Encoding string `json:"encoding"`
Lines []TextLine `json:"lines"`
// ComparedLines 保存内容模式的比较单元,Lines 始终保留未整理的原文。
ComparedLines []TextLine `json:"compared_lines"`
}
TextSource 保存快照解码并统一换行后的原文和来源行位置,不虚构文档页。
func (*TextSource) Location ¶ added in v0.2.5
func (s *TextSource) Location(number int) TextLocation
Location 返回比较单元的原文位置,number 从 1 开始,越界时返回零值。
func (*TextSource) ReviewLines ¶ added in v0.2.5
func (s *TextSource) ReviewLines() []TextLine
ReviewLines 返回参与差异判定的文字;复制和原文审阅使用 Lines。
type TextSpan ¶
TextSpan 描述按 Unicode 字符计算的编辑操作:equal 为共同文字,delete 只属于基准,insert 只属于目标。拼接 equal+delete 可还原基准原文, 拼接 equal+insert 可还原目标原文,空白字符完整保留。
type ValueChange ¶
type ValueChange struct {
Path string `json:"path"`
Before *string `json:"before,omitempty"`
After *string `json:"after,omitempty"`
}
ValueChange 使用命名空间展开名标识 XML 元素或属性。 nil 表示该值不存在,非 nil 的空字符串表示值存在但为空。
type VisualChange ¶
type VisualChange struct {
ChangedPixels int64 `json:"changed_pixels"`
TotalPixels int64 `json:"total_pixels"`
Ratio float64 `json:"ratio"`
// Bounds 是变化像素的整体矩形,采用半开区间 [x0,y0,x1,y1)。
Bounds [4]int `json:"bounds"`
BeforePNG string `json:"before_png,omitempty"`
AfterPNG string `json:"after_png,omitempty"`
DiffPNG string `json:"diff_png,omitempty"`
Width int `json:"width"`
Height int `json:"height"`
Regions []VisualRegion `json:"regions,omitempty"`
RegionCount int `json:"region_count"`
RegionsTruncated bool `json:"regions_truncated,omitempty"`
IgnoredRegionPixels int64 `json:"ignored_region_pixels"`
}
type VisualRegion ¶
type VisualRegion struct {
Bounds [4]int `json:"bounds"`
ChangedPixels int64 `json:"changed_pixels"`
}
VisualRegion 聚合相邻的变化网格。Bounds 以页面像素坐标覆盖这些网格, ChangedPixels 保存实际变化像素数量。
type XMLView ¶
type XMLView struct {
Kind string `json:"kind"`
Blocks []XMLViewBlock `json:"blocks,omitempty"`
Coarse bool `json:"coarse,omitempty"`
Note string `json:"note,omitempty"`
}
XMLView 区分 format(仅格式变化)、structure、added、removed、unavailable。 规范化显示统一前缀、属性顺序和缩进,忽略注释;行号属于显示内容。
type XMLViewBlock ¶
type XMLViewBlock struct {
Equal bool `json:"equal"`
Folded bool `json:"folded"`
Lines []XMLViewLine `json:"lines"`
}
XMLViewBlock 将相邻的相同行或变化行聚合;Folded 表示默认折叠相同部分。
Source Files
¶
- budget.go
- cache.go
- compare.go
- diff.go
- document_pages.go
- document_pair.go
- environment.go
- image.go
- image_document.go
- input_snapshot.go
- matching.go
- pages.go
- pdf.go
- pdf_date.go
- pdf_snapshot.go
- pdf_structure.go
- pdf_structure_diff.go
- pdf_text.go
- pdf_tools.go
- pdfium.go
- pdfium_text.go
- plain_text.go
- plain_text_report.go
- regions.go
- report.go
- snapshot.go
- text.go
- text_content.go
- text_document.go
- visual.go
- xml.go
- xml_view.go