mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 13:56:32 +08:00
1 parent
09bb08987e
commit
7e774f99df
2 files changed
+9
-5
No files matched your search
@@ -136,7 +136,7 @@ func (CanvasBackend) RenderPDF(r *Renderer, pages []RenderDocumentPage, writer i
|
||||
}
|
||||
start := buf.Len()
|
||||
p := pdf.New(buf, pages[0].Box.W, pages[0].Box.H, nil)
|
||||
renderer := &pdfRenderer{PDF: p, glyphPaths: make(map[*canvas.Path]*canvas.Path), images: make([][]image.Image, 1), text: make([]pdfPageText, 1), navigation: navigation}
|
||||
renderer := &pdfRenderer{PDF: p, glyphPaths: renderCache[*canvas.Path, *canvas.Path]{limit: 16 << 20}, images: make([][]image.Image, 1), text: make([]pdfPageText, 1), navigation: navigation}
|
||||
defer func() {
|
||||
if renderer.imageError != nil {
|
||||
r.canvasState().images = renderCache[*EncodedImage, image.Image]{limit: imageCacheLimit}
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
// pdfRenderer PDF渲染器
|
||||
type pdfRenderer struct {
|
||||
*pdf.PDF
|
||||
glyphPaths map[*canvas.Path]*canvas.Path
|
||||
glyphPaths renderCache[*canvas.Path, *canvas.Path]
|
||||
fonts map[*canvas.Font]*canvas.Font
|
||||
images [][]image.Image
|
||||
exactImages bool
|
||||
@@ -136,18 +136,22 @@ func (r *pdfRenderer) RenderImage(img image.Image, matrix canvas.Matrix) {
|
||||
r.PDF.RenderImage(img, matrix)
|
||||
}
|
||||
|
||||
// glyphPath 复用相似变换下的PDF字形圆弧转换
|
||||
// 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 {
|
||||
if cached, ok := r.glyphPaths.get(path); ok {
|
||||
return cached
|
||||
}
|
||||
converted := path.ReplaceArcs()
|
||||
r.glyphPaths[path] = converted
|
||||
cost := 256 + cap(path.Data())*8
|
||||
if converted != path {
|
||||
cost += cap(converted.Data()) * 8
|
||||
}
|
||||
r.glyphPaths.put(path, converted, cost)
|
||||
return converted
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user