feat(性能优化): 优化PDF字形复用,降低多页导出耗时与内存分配
build.yaml / build (push) Successful in 42s

This commit is contained in:
xiaoqidun committed 2026-09-13 23:49:21 +08:00
1 parent e488d25775
commit ad00e95ae6
3 files changed
+28 -1

No files matched your search

+21
View File
@@ -21,6 +21,27 @@ import (
"github.com/tdewolff/canvas/renderers/pdf"
)
// pdfRenderer PDF渲染器
type pdfRenderer struct {
*pdf.PDF
glyphPaths map[*canvas.Path]*canvas.Path
}
// glyphPath 复用相似变换下的PDF字形圆弧转换
// 入参: path 缓存字形路径, matrix 字形变换
// 返回: *canvas.Path PDF字形路径
func (r *pdfRenderer) glyphPath(path *canvas.Path, matrix canvas.Matrix) *canvas.Path {
if !matrix.IsSimilarity() {
return path
}
if cached, ok := r.glyphPaths[path]; ok {
return cached
}
converted := path.ReplaceArcs()
r.glyphPaths[path] = converted
return converted
}
// pdfPage PDF页面数据
type pdfPage struct {
Content *PageContent