feat(文字预览): 优化文字预览内存占用
build.yaml / build (push) Successful in 46s

This commit is contained in:
xiaoqidun committed 2026-10-10 14:00:41 +08:00
1 parent 5545c3d4b5
commit e99501ca5f
2 files changed
+11 -4

No files matched your search

+2 -2
View File
@@ -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()) {
+9 -2
View File
@@ -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 {