From 526a207aa65b6112ba9cd7de227656b4be27121b Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Fri, 18 Sep 2026 09:10:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=89=8D=E7=AB=AF=E7=95=8C=E9=9D=A2):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B0=B4=E5=8D=B0=E9=80=89=E4=B8=AD=E4=B8=8E?= =?UTF-8?q?=E6=89=B9=E6=B3=A8=E6=98=BE=E7=A4=BA=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?PDF=E5=A4=9A=E4=BD=99=E8=BE=B9=E6=A1=86=EF=BC=8C=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E5=BC=B9=E7=AA=97=E6=96=87=E6=A1=88=E4=B8=8E=E5=B8=83?= =?UTF-8?q?=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/webui/index.html | 4 ++-- assets/webui/ofdgo.css | 18 ++++++++++++++---- assets/webui/ofdgo_edit.js | 11 +++++++++-- internal/webui/wasm.go | 19 +++++++++---------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/assets/webui/index.html b/assets/webui/index.html index 204e66e..87bd6b8 100644 --- a/assets/webui/index.html +++ b/assets/webui/index.html @@ -270,11 +270,11 @@
- + - +
diff --git a/assets/webui/ofdgo.css b/assets/webui/ofdgo.css index fb9ba85..205df7a 100644 --- a/assets/webui/ofdgo.css +++ b/assets/webui/ofdgo.css @@ -1316,6 +1316,7 @@ button.outline-link:hover { .navigation-tabs[hidden], .page-selection-tools[hidden], .form-row[hidden], +.form-pair[hidden], .form-actions > [hidden], .annotation-detail[hidden], .tool-group[hidden], @@ -1644,10 +1645,6 @@ button.outline-link:hover { content: ""; } -.edit-object.selected { - background: rgba(15, 123, 104, 0.04); -} - .edit-object.erasing { background: var(--accent-soft); outline-style: dashed; @@ -1849,6 +1846,19 @@ button.outline-link:hover { --note-rotation: calc(-1 * var(--surface-rotation, 0deg)); } +.edit-note-icon { + position: absolute; + inset: 0; + display: grid; + place-items: center; + border: 1px solid var(--line-strong); + background: var(--panel); + color: var(--accent-strong); + font-size: 16px; + line-height: 1; + pointer-events: none; +} + .annotation-detail { display: grid; gap: 8px; diff --git a/assets/webui/ofdgo_edit.js b/assets/webui/ofdgo_edit.js index 66f6ba3..84c7c8d 100644 --- a/assets/webui/ofdgo_edit.js +++ b/assets/webui/ofdgo_edit.js @@ -303,14 +303,21 @@ export class CanvasEditor { node.setAttribute("aria-label", { ImageObject: "图片对象", TextObject: "文字对象", PathObject: "图形对象", CompositeObject: "复合对象", CompositeGraphicUnit: "复合对象", Annotation: "注解对象" }[object.type]); const item = { ...object, index, page: { width: page.width, height: page.height }, node, surface }; item.artwork = artwork.get(object.id)?.node; - if (object.type === "PathObject" && (object.shape || object.outline) || (object.scoped || object.type === "CompositeObject" || object.type === "CompositeGraphicUnit" || object.type === "Annotation") && object.contours?.length) { + if (object.note) { + const icon = document.createElement("span"); + icon.className = "edit-note-icon"; + icon.setAttribute("aria-hidden", "true"); + icon.textContent = "\u24d8"; + node.append(icon); + } + if (object.type === "PathObject" && (object.shape || object.outline || object.contours?.length)) { node.classList.add("edit-contour"); const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svg.classList.add("edit-outline"); svg.setAttribute("aria-hidden", "true"); svg.setAttribute("preserveAspectRatio", "none"); let contour; - if (object.type === "PathObject" && (object.shape || object.oriented || !object.contours?.length)) { + if (object.shape || object.oriented || !object.contours?.length) { const shape = object.shape || object.oriented?.kind; contour = document.createElementNS("http://www.w3.org/2000/svg", shape === "line" ? "line" : shape === "ellipse" ? "ellipse" : shape === "rectangle" ? "rect" : "path"); if (!shape) contour.setAttribute("d", object.outline); diff --git a/internal/webui/wasm.go b/internal/webui/wasm.go index 55292f1..3dd0a52 100644 --- a/internal/webui/wasm.go +++ b/internal/webui/wasm.go @@ -898,9 +898,15 @@ func editorObjects(index int, text *ofdgo.PageText) ([]any, error) { mixed = true } } - objects = append(objects, map[string]any{"id": "annotation:" + annotation.ID, "type": "Annotation", "annotationType": annotation.Type, - "x": box.X, "y": box.Y, "width": box.W, "height": box.H, "contours": paths, "remark": annotation.Remark, "creator": annotation.Creator, - "alpha": alpha, "alphaMixed": mixed, "capabilities": capabilities}) + item := map[string]any{"id": "annotation:" + annotation.ID, "type": "Annotation", "annotationType": annotation.Type, + "x": box.X, "y": box.Y, "width": box.W, "height": box.H, "remark": annotation.Remark, "creator": annotation.Creator, + "alpha": alpha, "alphaMixed": mixed, "capabilities": capabilities} + if len(annotation.Appearance.Objects) == 0 && strings.TrimSpace(annotation.Remark) != "" { + item["note"] = true + } else { + item["contours"] = paths + } + objects = append(objects, item) } return objects, nil } @@ -1066,13 +1072,6 @@ func writeAnnotation(args []js.Value) (any, error) { switch options.Kind { case "note": annotation.Type, annotation.Remark = "Path", options.Text - shape, shapeErr := ofdgo.NewShape(ofdgo.ShapeRectangle, ofdgo.Box{W: box.W, H: box.H}) - if shapeErr != nil { - return shapeErr - } - shape.LineWidth = 0.3 - shape.StrokeColor = &ofdgo.StrokeColor{Value: "0 128 112"} - annotation.Appearance.Objects = []ofdgo.GraphicObject{{Type: "PathObject", PathObject: shape}} case "watermark", "stamp": annotation.Type = "Watermark" if options.Kind == "stamp" {