From e99501ca5f18e6e874902834a37cf2c483ad6f28 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Sat, 10 Oct 2026 14:00:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=96=87=E5=AD=97=E9=A2=84=E8=A7=88):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E5=AD=97=E9=A2=84=E8=A7=88=E5=86=85?= =?UTF-8?q?=E5=AD=98=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/webui/ofdgo_edit.js | 4 ++-- internal/webui/wasm.go | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/assets/webui/ofdgo_edit.js b/assets/webui/ofdgo_edit.js index c0aad6a..b03ea6c 100644 --- a/assets/webui/ofdgo_edit.js +++ b/assets/webui/ofdgo_edit.js @@ -1379,6 +1379,8 @@ export class CanvasEditor { bottom = Math.max(bottom, y + size - baseline); } for (const char of run.text) { + x = run.positions[index][0] * PX_PER_MM; + y = run.positions[index][1] * PX_PER_MM; const span = document.createElement("span"), node = document.createTextNode(char); span.append(node); Object.assign(span.style, { display: "inline-block", opacity: String((item.alpha ?? 255) / 255), transformOrigin: "left top", transform: `translate(${x - naturalX}px,${y - baseline - lineIndex * size}px) scaleX(${source.scale})` }); @@ -1391,8 +1393,6 @@ export class CanvasEditor { right = Math.max(right, x + advance * source.scale); bottom = Math.max(bottom, y + size - baseline); naturalX += advance; - x += run.dx?.length ? run.dx[Math.min(index, run.dx.length - 1)] * PX_PER_MM : 0; - y += run.dy?.length ? run.dy[Math.min(index, run.dy.length - 1)] * PX_PER_MM : 0; index++; } if (!line.hasChildNodes()) { diff --git a/internal/webui/wasm.go b/internal/webui/wasm.go index 6758578..ffd88fd 100644 --- a/internal/webui/wasm.go +++ b/internal/webui/wasm.go @@ -2346,8 +2346,15 @@ func previewText(args []js.Value) (any, error) { offset++ } content := (ofdgo.TextObject{TextCode: []ofdgo.TextCode{code}}).Text() - runs = append(runs, map[string]any{"text": content, "x": x, "y": y, "dx": code.GetDeltaX(), "dy": code.GetDeltaY(), "line": line}) - offset += len([]rune(content)) + code.X, code.Y = fmt.Sprint(x), fmt.Sprint(y) + positioner := ofdgo.NewTextPositioner(code) + positions := make([][2]float64, len([]rune(content))) + for i := range positions { + point := positioner.Next() + positions[i] = [2]float64{point.X, point.Y} + } + runs = append(runs, map[string]any{"text": content, "x": x, "y": y, "positions": positions, "line": line}) + offset += len(positions) } scale := text.HScale if scale == 0 {