From 64646b74a06119e5c1d4559e4ec59a2e4bac92f0 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Thu, 2 Jul 2026 23:44:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=96=87=E6=9C=AC=E6=B8=B2=E6=9F=93):=20?= =?UTF-8?q?=E5=8A=A0=E5=BC=BA=E6=96=87=E6=9C=AC=E6=B8=B2=E6=9F=93=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdgo_renderer.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ofdgo_renderer.go b/ofdgo_renderer.go index 6509179..9801959 100644 --- a/ofdgo_renderer.go +++ b/ofdgo_renderer.go @@ -1000,6 +1000,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64 } dxs, dys := parseFloats(tc.DeltaX), parseFloats(tc.DeltaY) xs, ys := parseFloats(tc.X), parseFloats(tc.Y) + drawAsPath := embeddedFont || textCodePositioned(tc) cx, cy := 0.0, 0.0 if len(xs) > 0 { cx = xs[0] @@ -1054,7 +1055,7 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64 x, y = 0, 0 defer ctx.Pop() } - if embeddedFont { + if drawAsPath { path, width := face.ToPath(str) textWidth = width * hScale ctx.DrawPath(x, y, path) @@ -1101,6 +1102,16 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64 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 获取文本偏移量 // 入参: deltas 偏移量数组, index 偏移量索引 // 返回: float64 偏移量, bool 是否存在