feat(文本渲染): 加强文本渲染兼容性

This commit is contained in:
2026-07-02 23:44:10 +08:00
parent 3de4d1c85a
commit 64646b74a0
+12 -1
View File
@@ -1000,6 +1000,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
} }
dxs, dys := parseFloats(tc.DeltaX), parseFloats(tc.DeltaY) dxs, dys := parseFloats(tc.DeltaX), parseFloats(tc.DeltaY)
xs, ys := parseFloats(tc.X), parseFloats(tc.Y) xs, ys := parseFloats(tc.X), parseFloats(tc.Y)
drawAsPath := embeddedFont || textCodePositioned(tc)
cx, cy := 0.0, 0.0 cx, cy := 0.0, 0.0
if len(xs) > 0 { if len(xs) > 0 {
cx = xs[0] cx = xs[0]
@@ -1054,7 +1055,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
x, y = 0, 0 x, y = 0, 0
defer ctx.Pop() defer ctx.Pop()
} }
if embeddedFont { if drawAsPath {
path, width := face.ToPath(str) path, width := face.ToPath(str)
textWidth = width * hScale textWidth = width * hScale
ctx.DrawPath(x, y, path) ctx.DrawPath(x, y, path)
@@ -1101,6 +1102,16 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
ctx.Pop() ctx.Pop()
} }
// textCodePositioned 判断文本编码是否带显式定位
// 入参: textCode 文本编码
// 返回: bool 是否带显式定位
func textCodePositioned(textCode TextCode) bool {
return strings.TrimSpace(textCode.DeltaX) != "" ||
strings.TrimSpace(textCode.DeltaY) != "" ||
len(parseFloats(textCode.X)) > 1 ||
len(parseFloats(textCode.Y)) > 1
}
// textDelta 获取文本偏移量 // textDelta 获取文本偏移量
// 入参: deltas 偏移量数组, index 偏移量索引 // 入参: deltas 偏移量数组, index 偏移量索引
// 返回: float64 偏移量, bool 是否存在 // 返回: float64 偏移量, bool 是否存在