feat(文字图像): 修复文字定位及图像导出
build.yaml / build (push) Successful in 44s

This commit is contained in:
xiaoqidun committed 2026-10-03 12:38:05 +08:00
1 parent f2dbf72885
commit 8de701dbd4
7 files changed
+162 -12

No files matched your search

+26 -1
View File
@@ -17,15 +17,19 @@ package ofdgo
import (
"fmt"
"image"
"image/color"
"github.com/tdewolff/canvas"
cimage "github.com/tdewolff/canvas/image"
"github.com/tdewolff/canvas/renderers/pdf"
)
// pdfRenderer PDF渲染器
type pdfRenderer struct {
*pdf.PDF
glyphPaths map[*canvas.Path]*canvas.Path
glyphPaths map[*canvas.Path]*canvas.Path
images [][]image.Image
exactImages bool
}
// pdfNavigation PDF导航信息
@@ -58,6 +62,27 @@ type pdfOutline struct {
// RenderImage 在图像局部保存状态前同步不透明画笔,避免恢复后的透明度与后端缓存不一致
// 入参: img 图像, matrix 图像变换
func (r *pdfRenderer) RenderImage(img image.Image, matrix canvas.Matrix) {
if len(r.images) != 0 {
var original image.Image
opaque := false
if source, ok := img.(interface{ Opaque() bool }); ok {
opaque = source.Opaque()
}
switch img.ColorModel() {
case color.GrayModel, color.CMYKModel:
case color.RGBAModel, color.NRGBAModel, color.AlphaModel:
if !opaque {
original = img
}
default:
if source, ok := img.(*cimage.Image); !ok || source.Mimetype != "image/jpeg" || source.Mask != nil {
original = img
}
}
r.exactImages = r.exactImages || original != nil
last := len(r.images) - 1
r.images[last] = append(r.images[last], original)
}
style := canvas.DefaultStyle
style.Fill = canvas.Paint{Color: canvas.White}
style.Stroke = canvas.Paint{Color: canvas.Black}