@knowvah/dot-engine 2.8.0 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowvah/dot-engine",
3
- "version": "2.8.0",
3
+ "version": "2.8.1",
4
4
  "description": "Faithful TypeScript port of Graphviz (dot, neato, fdp, sfdp, circo, twopi, osage, patchwork) — no C: no native binary, no WASM. Oracle-verified against the C implementation, runs in the browser.",
5
5
  "keywords": [
6
6
  "graphviz",
@@ -29,6 +29,7 @@ import type { RendererPlugin } from '../gvc/context.js';
29
29
  import type { TextSpan } from './emit-types.js';
30
30
  import type { PlacedHtml, PlacedCell, PlacedLine, PlacedImage } from './htmltable-pos.js';
31
31
  import { transformPoint } from '../gvc/device.js';
32
+ import { gvrenderUsershape } from '../gvc/render-usershape.js';
32
33
  import { gvrenderTextspan } from '../gvc/textspan-emit.js';
33
34
  import {
34
35
  withHtmlPaint, findHtmlStopColor, doBorder, mkPts,
@@ -194,61 +195,25 @@ function emitCellDecoration(
194
195
  }
195
196
  }
196
197
 
197
- /** Scale the intrinsic image size per the IMG SCALE attribute. */
198
- function scaleImage(d: { iw: number; ih: number; pw: number; ph: number; scale?: string }):
199
- { iw: number; ih: number } {
200
- const sx = d.pw / d.iw;
201
- const sy = d.ph / d.ih;
202
- const mode = (d.scale ?? '').toLowerCase();
203
- if (mode === 'width') return { iw: d.iw * sx, ih: d.ih };
204
- if (mode === 'height') return { iw: d.iw, ih: d.ih * sy };
205
- if (mode === 'both') return { iw: d.iw * sx, ih: d.ih * sy };
206
- if (mode === 'true' || mode === 'yes' || mode === '1') {
207
- const f = Math.min(sx, sy);
208
- return { iw: d.iw * f, ih: d.ih * f };
209
- }
210
- return { iw: d.iw, ih: d.ih };
211
- }
212
-
213
198
  /**
214
- * Emit a placed HTML IMG through the renderer's usershape hook.
215
- *
216
- * Ports gvrender_usershape: compute the target box from the placed
217
- * box, apply the SCALE modes against the intrinsic size, then center
218
- * the result (imagepos "mc" — hardcoded by emit_html_img).
219
- *
220
- * SCALE falls back to the object's imagescale attribute (C
221
- * env->imgscale, default "false") when the IMG has no SCALE attr.
199
+ * Emit a placed HTML IMG through the shared gvrender_usershape: the cell's
200
+ * content box is the polygon, imagepos is the fixed "mc", and the scale is the
201
+ * IMG's own SCALE, else the object's imagescale (C env->imgscale).
222
202
  *
223
- * @see lib/common/htmltable.c:emit_html_img (line 597)
224
- * @see lib/gvc/gvrender.c:gvrender_usershape (line 670)
203
+ * @see lib/common/htmltable.c:emit_html_img
204
+ * @see lib/gvc/gvrender.c:gvrender_usershape
225
205
  */
226
206
  export function emitHtmlImg(
227
207
  img: PlacedImage,
228
208
  pos: Point,
229
- renderer: RendererPlugin,
209
+ _renderer: RendererPlugin,
230
210
  job: RenderJob,
231
211
  ): void {
232
- if (img.iw <= 0 && img.ih <= 0) return; // C: zero-size image → skip
233
- const b: Box = {
234
- ll: { x: img.box.ll.x + pos.x, y: img.box.ll.y + pos.y },
235
- ur: { x: img.box.ur.x + pos.x, y: img.box.ur.y + pos.y },
236
- };
237
- const pw = b.ur.x - b.ll.x;
238
- const ph = b.ur.y - b.ll.y;
239
- // @see lib/common/htmltable.c:emit_html_img (:615-618)
212
+ const ll = { x: img.box.ll.x + pos.x, y: img.box.ll.y + pos.y };
213
+ const ur = { x: img.box.ur.x + pos.x, y: img.box.ur.y + pos.y };
214
+ const a: Point[] = [ur, { x: ll.x, y: ur.y }, ll, { x: ur.x, y: ll.y }];
240
215
  const scale = img.scale !== undefined ? img.scale : htmlObjImgscale();
241
- const { iw, ih } = scaleImage({ iw: img.iw, ih: img.ih, pw, ph, scale });
242
- // imagepos "mc": center the (possibly scaled) image in the target box
243
- if (iw < pw) {
244
- b.ll.x += (pw - iw) / 2.0;
245
- b.ur.x -= (pw - iw) / 2.0;
246
- }
247
- if (ih < ph) {
248
- b.ll.y += (ph - ih) / 2.0;
249
- b.ur.y -= (ph - ih) / 2.0;
250
- }
251
- renderer.usershape?.(img.src, b, job);
216
+ gvrenderUsershape(job, img.src, a, true, scale, 'mc');
252
217
  }
253
218
 
254
219
  /**
@@ -15,7 +15,7 @@ import type { TextMeasurer } from './textmeasure.js';
15
15
  import type { PolygonT, ShapeDesc, TextlabelT } from './types.js';
16
16
  import { ShapeKind } from './types.js';
17
17
  import { bindShape } from './shapes.js';
18
- import { assignShapeInfo, buildNodeLabel, nodeAttr, nodeImageSize, readFontAttrs } from './poly-init.js';
18
+ import { assignShapeInfo, buildNodeLabel, nodeAttr, nodeImageSize, readFontAttrs, warnPolyInitImages } from './poly-init.js';
19
19
  import { makeAnyLabel } from './make-label.js';
20
20
  import { isHtmlValue, htmlValueContent } from './html-string.js';
21
21
  import { NODE_XLABEL } from '../layout/dot/rank.js';
@@ -243,6 +243,8 @@ function initNodeFromLabel(n: Node, g: Graph, measurer: TextMeasurer): boolean {
243
243
  }
244
244
  buildNodeLabel(n, g, measurer);
245
245
  initNodeXLabel(n, g, measurer);
246
+ // Layout-time poly_init warnings (once per layout; render-time polyInit is silent).
247
+ if (shape.kind !== ShapeKind.SH_POINT) warnPolyInitImages(n, g);
246
248
  const poly = shape.polygon;
247
249
  if (poly === null) return false;
248
250
  if (shape.kind === ShapeKind.SH_POINT) {
@@ -34,10 +34,11 @@ import {
34
34
  styleTokens,
35
35
  } from './style-resolve.js';
36
36
  import { stripedBox, wedgedEllipse } from '../render/svg-multicolor.js';
37
- import { resolveRenderColor, reportColorNames } from '../render/color-resolve.js';
37
+ import { resolveFillColorName, resolveRenderColor, reportColorNames } from '../render/color-resolve.js';
38
38
  import { htmlLabelColors } from './htmltable-emit-fill.js';
39
39
  import { svgNodeId } from '../render/svg-id.js';
40
40
  import { drawRoundCorners, mcircleHack, underlineDraw } from './poly-shapes.js';
41
+ import { gvrenderUsershape } from '../gvc/render-usershape.js';
41
42
 
42
43
  // ---------------------------------------------------------------------------
43
44
  // Multicolor test
@@ -175,6 +176,51 @@ function renderPeripheries(
175
176
  }
176
177
  }
177
178
 
179
+ // ---------------------------------------------------------------------------
180
+ // User shapes / images
181
+ // ---------------------------------------------------------------------------
182
+
183
+ /** The `custom` shape: a user shape only when `shapefile` names a file. */
184
+ const CUSTOM_SHAPE_NAME = 'custom';
185
+
186
+ /**
187
+ * The image name poly_gencode hands to gvrender_usershape, or undefined when
188
+ * the node draws none: a usershape shape (a `custom` one needs a non-empty
189
+ * `shapefile`, otherwise the shape's own name is the file) or a non-empty
190
+ * `image=`.
191
+ * @see lib/common/shapes.c:poly_gencode :3058-3067
192
+ */
193
+ function usershapeName(n: Node): string | undefined {
194
+ const shape = n.info.shape as ShapeDesc | undefined;
195
+ if (shape?.usershape === true) {
196
+ if (shape.name !== CUSTOM_SHAPE_NAME) return shape.name;
197
+ const shapefile = nodeAttr(n, n.root, 'shapefile');
198
+ return shapefile !== undefined && shapefile !== '' ? shapefile : undefined;
199
+ }
200
+ const image = nodeAttr(n, n.root, 'image');
201
+ return image !== undefined && image !== '' ? image : undefined;
202
+ }
203
+
204
+ /**
205
+ * Draw the node's image over its innermost periphery.
206
+ * `filled` is C's value after the peripheries loop (0 once any periphery was
207
+ * drawn); it is only meaningful to loadimage plugins that paint a background.
208
+ * @see lib/common/shapes.c:poly_gencode :3068-3080
209
+ */
210
+ function renderUsershape(n: Node, d: NodeDrawCtx): void {
211
+ const name = usershapeName(n);
212
+ if (name === undefined) return;
213
+ const { poly, coord } = d;
214
+ const sides = poly.sides <= 2 ? 2 : poly.sides;
215
+ // get coords of innermost periphery
216
+ const af = poly.vertices!.slice(0, sides).map((v) => ({ x: v.x + coord.x, y: v.y + coord.y }));
217
+ gvrenderUsershape(
218
+ d.ringCtx.job, name, af, poly.peripheries === 0 && d.filled,
219
+ nodeAttr(n, n.root, 'imagescale') ?? 'false',
220
+ nodeAttr(n, n.root, 'imagepos') ?? 'mc',
221
+ );
222
+ }
223
+
178
224
  // ---------------------------------------------------------------------------
179
225
  // Label rendering
180
226
  // ---------------------------------------------------------------------------
@@ -338,7 +384,8 @@ function applyFillState(obj: ObjState, n: Node, job: RenderJob): boolean {
338
384
  if (fillRes.kind === 'none') { obj.fill = FillType.None; return false; }
339
385
  if (fillRes.kind === 'solid') {
340
386
  obj.fill = FillType.Solid;
341
- obj.fillColor = resolveRenderColor(fillRes.color);
387
+ // gvrender_set_fillcolor hands an empty name (":red") to colorxlate.
388
+ obj.fillColor = resolveFillColorName(fillRes.color);
342
389
  return true;
343
390
  }
344
391
  applyGradientFields(obj, fillRes);
@@ -496,6 +543,8 @@ export function polyGencode(rawJob: unknown, rawNode: unknown): void {
496
543
  const savedPts = job.obj?.urlMapPts;
497
544
  let inAnchor = clustersLast ? false : beginNodeAnchor(n, renderer, job);
498
545
  renderPeripheries(ctx.poly, ctx.coord, ctx.filled, ctx.ringCtx);
546
+ // point_gencode has no usershape branch.
547
+ if (!isPointNode(n)) renderUsershape(n, ctx);
499
548
  // point_gencode never emits a label (AD-3).
500
549
  if (!isPointNode(n)) renderNodeLabel(n, ctx.coord, renderer, job);
501
550
  if (clustersLast) {
@@ -99,13 +99,23 @@ export function buildNodeLabel(n: Node, g: Graph, measurer: TextMeasurer): void
99
99
  }
100
100
 
101
101
  /**
102
- * poly_init's `image` branch (a non-custom shape): when the caller supplies no
103
- * image, gvusershape_size fails and C warns after gvusershape_open's own
104
- * warning. The port never sizes node images.
105
- * @see lib/common/shapes.c:2043-2046
102
+ * poly_init's shapefile and `image` warnings, emitted once per layout from
103
+ * common_init_node after the label is made. For a custom shape gvusershape_size
104
+ * fails (the port never sizes shapefiles), so gvusershape_open's "while
105
+ * opening" line precedes the "No or improper shapefile" line. For a non-custom
106
+ * shape's `image=`, the caller-supplied sizer/resolver decides; when it
107
+ * supplies nothing the same pair is emitted.
108
+ * @see lib/common/shapes.c:2027-2046
106
109
  */
107
- function warnMissingImage(n: Node, g: Graph, shapefile: string | undefined): void {
108
- if (shapefile !== undefined && shapefile !== '' && nodeAttr(n, g, 'shape') !== 'epsf') return;
110
+ export function warnPolyInitImages(n: Node, g: Graph): void {
111
+ const shapefile = nodeAttr(n, g, 'shapefile');
112
+ if (shapefile !== undefined && shapefile !== '') {
113
+ if (nodeAttr(n, g, 'shape') !== 'epsf') {
114
+ agwarningf(imageOpenWarning(shapefile));
115
+ agwarningf(`No or improper shapefile="${shapefile}" for node "${n.name}"`);
116
+ return;
117
+ }
118
+ }
109
119
  const image = nodeAttr(n, g, 'image');
110
120
  if (image === undefined || image === '') return;
111
121
  const gvc = g.root.info.gvc;
@@ -135,16 +145,10 @@ export function polyInit(n: Node, g: Graph, measurer: TextMeasurer): void {
135
145
  const shapeName = nodeAttr(n, g, 'shape') ?? 'ellipse';
136
146
  const shapefile = nodeAttr(n, g, 'shapefile');
137
147
  n.info.shape = bindShape(shapeName, shapefile);
138
- // C warns when the custom shape's image cannot be sized (headless: always).
139
- // @see lib/common/shapes.c:2027-2033
140
- if (shapefile !== undefined && shapefile !== '' && shapeName !== 'epsf') {
141
- agwarningf(`No or improper shapefile="${shapefile}" for node "${n.name}"`);
142
- }
143
148
  if ((n.info.shape as ShapeDesc).kind === ShapeKind.SH_RECORD) {
144
149
  if (n.info.shape_info === undefined) recordNodeInit(n, g, measurer);
145
150
  return;
146
151
  }
147
- warnMissingImage(n, g, shapefile);
148
152
  buildNodeLabel(n, g, measurer);
149
153
 
150
154
  // Layout-time common_init_node already installed the attr-resolved
@@ -17,7 +17,7 @@ import {
17
17
  resolveClusterFillEx, styleTokens,
18
18
  } from '../common/style-resolve.js';
19
19
  import { gvrenderSetStyle, checkClusterStyleTokens } from './gvrender-set-style.js';
20
- import { resolveRenderColor, reportColorNames } from '../render/color-resolve.js';
20
+ import { resolveFillColorName, resolveRenderColor, reportColorNames } from '../render/color-resolve.js';
21
21
  import { parseSegs } from '../common/multicolor.js';
22
22
  import { graphAttrInherited } from '../common/attr-get.js';
23
23
 
@@ -181,7 +181,8 @@ function applyClusterFill(obj: ObjState, fillRes: ResolvedFill): boolean {
181
181
  if (fillRes.kind === 'none') { obj.fill = FillType.None; return false; }
182
182
  if (fillRes.kind === 'solid') {
183
183
  obj.fill = FillType.Solid;
184
- obj.fillColor = resolveRenderColor(fillRes.color);
184
+ // gvrender_set_fillcolor hands an empty name (":red") to colorxlate.
185
+ obj.fillColor = resolveFillColorName(fillRes.color);
185
186
  return true;
186
187
  }
187
188
  applyClusterGradient(obj, fillRes);
package/src/gvc/device.ts CHANGED
@@ -426,6 +426,7 @@ export function render(ctx: GvcContext, g: Graph, format: string, inlineImages =
426
426
  const job = new RenderJob(format, ctx.textMeasurer);
427
427
  job.inlineImages = inlineImages;
428
428
  if (ctx.imageResolver !== undefined) job.imageResolver = ctx.imageResolver;
429
+ if (ctx.imageSizer !== undefined) job.imageSizer = ctx.imageSizer;
429
430
  // gvc->bb = GD_bb(g) verbatim -- no recompute fallback. Every layout engine
430
431
  // sets g.info.bb itself before render() runs (set_aspect for dot,
431
432
  // compute_bb-equivalent computeSubgraphBB calls in neato/circo/sfdp/fdp/
@@ -0,0 +1,209 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * `gvrender_usershape`: fit an image (node `image=`, HTML `<IMG>`) into the
5
+ * bounding box of a polygon according to `imagescale` / `imagepos`, then hand
6
+ * the resulting box to the renderer's loadimage hook (`usershape`).
7
+ *
8
+ * @see lib/gvc/gvrender.c:gvrender_usershape (670-790)
9
+ */
10
+
11
+ import type { Box, Point } from '../model/geom.js';
12
+ import type { RenderJob } from './job.js';
13
+ import { imageIsSupplied, usershapeSizePts, type ImageSizer } from './usershape.js';
14
+ import { mapbool } from '../layout/dot/rank.js';
15
+
16
+ /** @see lib/gvc/gvcjob.h:imagescale_t */
17
+ export const ImageScale = {
18
+ False: 'false',
19
+ True: 'true',
20
+ Width: 'width',
21
+ Height: 'height',
22
+ Both: 'both',
23
+ } as const;
24
+ export type ImageScale = (typeof ImageScale)[keyof typeof ImageScale];
25
+
26
+ /** @see lib/gvc/gvcjob.h:imagepos_t */
27
+ export const ImagePos = {
28
+ TopLeft: 'tl',
29
+ TopCenter: 'tc',
30
+ TopRight: 'tr',
31
+ MiddleLeft: 'ml',
32
+ MiddleCenter: 'mc',
33
+ MiddleRight: 'mr',
34
+ BottomLeft: 'bl',
35
+ BottomCenter: 'bc',
36
+ BottomRight: 'br',
37
+ } as const;
38
+ export type ImagePos = (typeof ImagePos)[keyof typeof ImagePos];
39
+
40
+ const IMAGE_POSITIONS: ReadonlySet<string> = new Set(Object.values(ImagePos));
41
+
42
+ /** @see lib/gvc/gvrender.c:get_imagescale */
43
+ export function getImagescale(s: string): ImageScale {
44
+ if (s === '') return ImageScale.False;
45
+ const l = s.toLowerCase();
46
+ if (l === 'width') return ImageScale.Width;
47
+ if (l === 'height') return ImageScale.Height;
48
+ if (l === 'both') return ImageScale.Both;
49
+ if (mapbool(s)) return ImageScale.True;
50
+ return ImageScale.False;
51
+ }
52
+
53
+ /** @see lib/gvc/gvrender.c:get_imagepos */
54
+ export function getImagepos(s: string): ImagePos {
55
+ if (s === '') return ImagePos.MiddleCenter;
56
+ const l = s.toLowerCase();
57
+ return IMAGE_POSITIONS.has(l) ? (l as ImagePos) : ImagePos.MiddleCenter;
58
+ }
59
+
60
+ /** Scale `isz` toward the polygon extent (pw, ph) per `imagescale`. */
61
+ function scaleImage(
62
+ mode: ImageScale, isz: { w: number; h: number }, pw: number, ph: number,
63
+ ): { iw: number; ih: number } {
64
+ let iw = isz.w;
65
+ let ih = isz.h;
66
+ const scalex = pw / iw;
67
+ const scaley = ph / ih;
68
+ switch (mode) {
69
+ case ImageScale.True:
70
+ // keep aspect ratio fixed by just using the smaller scale
71
+ if (scalex < scaley) {
72
+ iw *= scalex;
73
+ ih *= scalex;
74
+ } else {
75
+ iw *= scaley;
76
+ ih *= scaley;
77
+ }
78
+ break;
79
+ case ImageScale.Width:
80
+ iw *= scalex;
81
+ break;
82
+ case ImageScale.Height:
83
+ ih *= scaley;
84
+ break;
85
+ case ImageScale.Both:
86
+ iw *= scalex;
87
+ ih *= scaley;
88
+ break;
89
+ case ImageScale.False:
90
+ break;
91
+ }
92
+ return { iw, ih };
93
+ }
94
+
95
+ /** Apply `imagepos` to the target box when the image is narrower than it. */
96
+ function positionX(b: Box, position: ImagePos, iw: number, pw: number): void {
97
+ if (!(iw < pw)) return;
98
+ switch (position) {
99
+ case ImagePos.TopLeft:
100
+ case ImagePos.MiddleLeft:
101
+ case ImagePos.BottomLeft:
102
+ b.ur.x = b.ll.x + iw;
103
+ break;
104
+ case ImagePos.TopRight:
105
+ case ImagePos.MiddleRight:
106
+ case ImagePos.BottomRight:
107
+ b.ll.x += pw - iw;
108
+ b.ur.x = b.ll.x + iw;
109
+ break;
110
+ default:
111
+ b.ll.x += (pw - iw) / 2.0;
112
+ b.ur.x -= (pw - iw) / 2.0;
113
+ break;
114
+ }
115
+ }
116
+
117
+ /** Apply `imagepos` to the target box when the image is shorter than it. */
118
+ function positionY(b: Box, position: ImagePos, ih: number, ph: number): void {
119
+ if (!(ih < ph)) return;
120
+ switch (position) {
121
+ case ImagePos.TopLeft:
122
+ case ImagePos.TopCenter:
123
+ case ImagePos.TopRight:
124
+ b.ll.y = b.ur.y - ih;
125
+ break;
126
+ case ImagePos.BottomLeft:
127
+ case ImagePos.BottomCenter:
128
+ case ImagePos.BottomRight:
129
+ // Kept as C writes it: ll moves up by ih, ur lands on the old ll; the
130
+ // LL/UR swap below restores order.
131
+ b.ll.y += ih;
132
+ b.ur.y = b.ll.y - ih;
133
+ break;
134
+ default:
135
+ b.ll.y += (ph - ih) / 2.0;
136
+ b.ur.y -= (ph - ih) / 2.0;
137
+ break;
138
+ }
139
+ }
140
+
141
+ /** Bounding box of the polygon `a` (expandbp over every vertex). */
142
+ function polygonBox(a: readonly Point[]): Box {
143
+ const first = a[0]!;
144
+ const b: Box = { ll: { x: first.x, y: first.y }, ur: { x: first.x, y: first.y } };
145
+ for (let i = 1; i < a.length; i++) {
146
+ const p = a[i]!;
147
+ if (p.x < b.ll.x) b.ll.x = p.x;
148
+ if (p.x > b.ur.x) b.ur.x = p.x;
149
+ if (p.y < b.ll.y) b.ll.y = p.y;
150
+ if (p.y > b.ur.y) b.ur.y = p.y;
151
+ }
152
+ return b;
153
+ }
154
+
155
+ /**
156
+ * The rendering context's image sizer (the port's gvusershape dictionary),
157
+ * set on the job by `render` beside `imageResolver`; undefined means the
158
+ * global `setImageSizer`.
159
+ */
160
+ declare module './job.js' {
161
+ interface RenderJob {
162
+ imageSizer?: ImageSizer | undefined;
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Scale the image `name` to the bounding box of polygon `a` per `imagescale`,
168
+ * place it per `imagepos`, convert to device coordinates unless the renderer
169
+ * transforms, and pass the box to the renderer's `usershape` (gvloadimage).
170
+ *
171
+ * `gvusershape_find` is "the caller supplies `name`" (sizer or resolver); the
172
+ * `find_user_shape` / `library_shape` branch is a no-op because no renderer
173
+ * has `library_shape`. `filled` is only read by loadimage plugins that paint a
174
+ * background (none of svg/xdot), so it is not forwarded.
175
+ *
176
+ * @see lib/gvc/gvrender.c:gvrender_usershape
177
+ */
178
+ export function gvrenderUsershape(
179
+ job: RenderJob, name: string, a: readonly Point[], _filled: boolean,
180
+ imagescale: string, imagepos: string,
181
+ ): void {
182
+ const sizer = job.imageSizer;
183
+ if (!imageIsSupplied(name, sizer, job.imageResolver)) return;
184
+
185
+ // gvusershape_size_dpi(us, job->dpi)
186
+ const isz = usershapeSizePts(name, job.dpi.x, sizer);
187
+ if (isz === null || (isz.x <= 0 && isz.y <= 0)) return;
188
+
189
+ const b = polygonBox(a);
190
+ const pw = b.ur.x - b.ll.x;
191
+ const ph = b.ur.y - b.ll.y;
192
+ const { iw, ih } = scaleImage(getImagescale(imagescale), { w: isz.x, h: isz.y }, pw, ph);
193
+
194
+ // if image is smaller in any dimension, apply the specified positioning
195
+ const position = getImagepos(imagepos);
196
+ positionX(b, position, iw, pw);
197
+ positionY(b, position, ih, ph);
198
+
199
+ // C converts graph to device coordinates here (gvrender_ptf) unless the
200
+ // renderer has GVRENDER_DOES_TRANSFORM. The port never sets that flag: its
201
+ // y-flip lives in transformPoint (devscale), applied by the callers of the
202
+ // primitives. Both renderers with a `usershape` (svg, xdot) are
203
+ // DOES_TRANSFORM in C and take graph coordinates (RendererPlugin.usershape
204
+ // contract), so the ptf branch is dead for every registered renderer.
205
+
206
+ if (b.ll.x > b.ur.x) [b.ll.x, b.ur.x] = [b.ur.x, b.ll.x];
207
+ if (b.ll.y > b.ur.y) [b.ll.y, b.ur.y] = [b.ur.y, b.ll.y];
208
+ job.renderer?.usershape?.(name, b, job);
209
+ }
package/src/render/dot.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  import type { Graph } from '../model/graph.js';
14
14
  import type { Node } from '../model/node.js';
15
15
  import type { Edge } from '../model/edge.js';
16
- import type { Point } from '../model/geom.js';
16
+ import type { Box, Point } from '../model/geom.js';
17
17
  import type { TextSpan } from '../common/emit-types.js';
18
18
  import type { ArrowDrawOp } from '../common/arrows-types.js';
19
19
  import type { GVColor } from '../common/color.js';
@@ -361,6 +361,17 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
361
361
  buf.push(this.styleOp(job), this.penOp(job), xdotPoints('L', pts));
362
362
  }
363
363
 
364
+ /**
365
+ * The `I` op: `x y w h` of the box, then the image name as an xdot string.
366
+ * @see plugin/core/gvrender_core_dot.c:core_loadimage_xdot
367
+ */
368
+ usershape(src: string, b: Box, job: RenderJob): void {
369
+ this.getBuf(job).push(
370
+ 'I ', xdotPoint(b.ll), xdotNum(b.ur.x - b.ll.x) + ' ' + xdotNum(b.ur.y - b.ll.y) + ' ',
371
+ xdotStrOp('', src),
372
+ );
373
+ }
374
+
364
375
  // --- graphics-state ops ------------------------------------------------
365
376
 
366
377
  /** Pen color op from the resolved graphics state (default black). */
@@ -482,6 +493,8 @@ export class DotRenderer extends XdotRenderer {
482
493
  override polygon(_pts: Point[], _filled: boolean, _job: RenderJob): void { /* no-op */ }
483
494
  override bezier(_pts: Point[], _filled: boolean, _job: RenderJob): void { /* no-op */ }
484
495
  override polyline(_pts: Point[], _job: RenderJob): void { /* no-op */ }
496
+ /** No loadimage engine for "dot" (only "<type>:xdot"). */
497
+ override usershape(_src: string, _b: Box, _job: RenderJob): void { /* no-op */ }
485
498
  }
486
499
 
487
500
  /** @see plugin/core/gvrender_core_dot.c FORMAT_DOT */