@knowvah/dot-engine 2.8.0 → 2.9.0

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.
Files changed (344) hide show
  1. package/dist/common/graph-init.d.ts.map +1 -1
  2. package/dist/common/htmltable-emit.d.ts +6 -11
  3. package/dist/common/htmltable-emit.d.ts.map +1 -1
  4. package/dist/common/nodeinit.d.ts.map +1 -1
  5. package/dist/common/poly-gencode.d.ts.map +1 -1
  6. package/dist/common/poly-init.d.ts +13 -2
  7. package/dist/common/poly-init.d.ts.map +1 -1
  8. package/dist/common/safefile.d.ts +23 -0
  9. package/dist/common/safefile.d.ts.map +1 -0
  10. package/dist/common/shapes.d.ts +6 -6
  11. package/dist/common/shapes.d.ts.map +1 -1
  12. package/dist/gvc/device.d.ts.map +1 -1
  13. package/dist/gvc/image-type.d.ts +41 -0
  14. package/dist/gvc/image-type.d.ts.map +1 -0
  15. package/dist/gvc/render-usershape.d.ts +68 -0
  16. package/dist/gvc/render-usershape.d.ts.map +1 -0
  17. package/dist/gvc/usershape.d.ts +23 -1
  18. package/dist/gvc/usershape.d.ts.map +1 -1
  19. package/dist/index.js +46393 -44890
  20. package/dist/index.js.map +4 -4
  21. package/dist/layout/neato/__fixtures__/quad-prog-vpsc.d.ts +118 -0
  22. package/dist/layout/neato/__fixtures__/quad-prog-vpsc.d.ts.map +1 -0
  23. package/dist/layout/neato/__fixtures__/stress-models.d.ts +39 -0
  24. package/dist/layout/neato/__fixtures__/stress-models.d.ts.map +1 -0
  25. package/dist/layout/neato/circuit.d.ts +10 -0
  26. package/dist/layout/neato/circuit.d.ts.map +1 -0
  27. package/dist/layout/neato/init.d.ts +3 -2
  28. package/dist/layout/neato/init.d.ts.map +1 -1
  29. package/dist/layout/neato/ipsep-opts.d.ts +19 -0
  30. package/dist/layout/neato/ipsep-opts.d.ts.map +1 -0
  31. package/dist/layout/neato/lu.d.ts +35 -0
  32. package/dist/layout/neato/lu.d.ts.map +1 -0
  33. package/dist/layout/neato/matinv.d.ts +8 -0
  34. package/dist/layout/neato/matinv.d.ts.map +1 -0
  35. package/dist/layout/neato/quad-prog-vpsc-overlap.d.ts +35 -0
  36. package/dist/layout/neato/quad-prog-vpsc-overlap.d.ts.map +1 -0
  37. package/dist/layout/neato/quad-prog-vpsc.d.ts +110 -0
  38. package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -0
  39. package/dist/layout/neato/start.d.ts +5 -4
  40. package/dist/layout/neato/start.d.ts.map +1 -1
  41. package/dist/layout/neato/stress-cola.d.ts +65 -0
  42. package/dist/layout/neato/stress-cola.d.ts.map +1 -0
  43. package/dist/layout/neato/stress-kernel.d.ts +0 -2
  44. package/dist/layout/neato/stress-kernel.d.ts.map +1 -1
  45. package/dist/layout/neato/stress-models.d.ts +48 -0
  46. package/dist/layout/neato/stress-models.d.ts.map +1 -0
  47. package/dist/layout/neato/vpsc-adjust.d.ts +7 -8
  48. package/dist/layout/neato/vpsc-adjust.d.ts.map +1 -1
  49. package/dist/render/color-resolve.d.ts +14 -0
  50. package/dist/render/color-resolve.d.ts.map +1 -1
  51. package/dist/render/dot/edge-draw.d.ts.map +1 -1
  52. package/dist/render/dot.d.ts +8 -1
  53. package/dist/render/dot.d.ts.map +1 -1
  54. package/dist/render/svg-arrow-ops.d.ts +21 -4
  55. package/dist/render/svg-arrow-ops.d.ts.map +1 -1
  56. package/dist/render/svg-edge-arrows.d.ts +3 -3
  57. package/dist/render/svg-edge-arrows.d.ts.map +1 -1
  58. package/dist/render/svg-helpers.d.ts +1 -1
  59. package/dist/render/svg-helpers.d.ts.map +1 -1
  60. package/dist/render/svg.d.ts.map +1 -1
  61. package/dist/render.js +8505 -7002
  62. package/dist/render.js.map +4 -4
  63. package/package.json +1 -1
  64. package/src/common/graph-init.ts +4 -2
  65. package/src/common/htmltable-emit.ts +11 -46
  66. package/src/common/nodeinit.ts +3 -1
  67. package/src/common/poly-gencode.ts +53 -3
  68. package/src/common/poly-init.ts +30 -17
  69. package/src/common/safefile.ts +74 -0
  70. package/src/common/shapes.ts +43 -22
  71. package/src/gvc/__fixtures__/p7/colors/98-point.gv +1 -0
  72. package/src/gvc/__fixtures__/p7/colors/98-point.json +54 -0
  73. package/src/gvc/__fixtures__/p7/colors/98-point.json.stderr +1 -0
  74. package/src/gvc/__fixtures__/p7/colors/98-point.svg +17 -0
  75. package/src/gvc/__fixtures__/p7/colors/98-point.svg.stderr +1 -0
  76. package/src/gvc/__fixtures__/p7/colors/98-point.xdot +13 -0
  77. package/src/gvc/__fixtures__/p7/colors/98-point.xdot.stderr +1 -0
  78. package/src/gvc/__fixtures__/p7/colors/99-edge-color.gv +1 -0
  79. package/src/gvc/__fixtures__/p7/colors/99-edge-color.json +150 -0
  80. package/src/gvc/__fixtures__/p7/colors/99-edge-color.json.stderr +1 -0
  81. package/src/gvc/__fixtures__/p7/colors/99-edge-color.svg +30 -0
  82. package/src/gvc/__fixtures__/p7/colors/99-edge-color.svg.stderr +1 -0
  83. package/src/gvc/__fixtures__/p7/colors/99-edge-color.xdot +22 -0
  84. package/src/gvc/__fixtures__/p7/colors/99-edge-color.xdot.stderr +1 -0
  85. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.gv +1 -0
  86. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.json +149 -0
  87. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.json.stderr +0 -0
  88. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.svg +30 -0
  89. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.svg.stderr +0 -0
  90. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.xdot +21 -0
  91. package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.xdot.stderr +0 -0
  92. package/src/gvc/__fixtures__/p7/colors/99-edge.gv +1 -0
  93. package/src/gvc/__fixtures__/p7/colors/99-edge.json +149 -0
  94. package/src/gvc/__fixtures__/p7/colors/99-edge.json.stderr +1 -0
  95. package/src/gvc/__fixtures__/p7/colors/99-edge.svg +30 -0
  96. package/src/gvc/__fixtures__/p7/colors/99-edge.svg.stderr +1 -0
  97. package/src/gvc/__fixtures__/p7/colors/99-edge.xdot +21 -0
  98. package/src/gvc/__fixtures__/p7/colors/99-edge.xdot.stderr +1 -0
  99. package/src/gvc/__fixtures__/p7/images/100-rotate.gv +1 -0
  100. package/src/gvc/__fixtures__/p7/images/100-rotate.svg +19 -0
  101. package/src/gvc/__fixtures__/p7/images/100-rotate.svg.stderr +0 -0
  102. package/src/gvc/__fixtures__/p7/images/101-bad.cmapx +2 -0
  103. package/src/gvc/__fixtures__/p7/images/101-bad.cmapx.stderr +2 -0
  104. package/src/gvc/__fixtures__/p7/images/101-bad.dot +8 -0
  105. package/src/gvc/__fixtures__/p7/images/101-bad.dot.stderr +2 -0
  106. package/src/gvc/__fixtures__/p7/images/101-bad.gv +1 -0
  107. package/src/gvc/__fixtures__/p7/images/101-bad.json +68 -0
  108. package/src/gvc/__fixtures__/p7/images/101-bad.json.stderr +2 -0
  109. package/src/gvc/__fixtures__/p7/images/101-bad.plain +3 -0
  110. package/src/gvc/__fixtures__/p7/images/101-bad.plain.stderr +2 -0
  111. package/src/gvc/__fixtures__/p7/images/101-bad.svg +18 -0
  112. package/src/gvc/__fixtures__/p7/images/101-bad.svg.stderr +2 -0
  113. package/src/gvc/__fixtures__/p7/images/101-bad.xdot +13 -0
  114. package/src/gvc/__fixtures__/p7/images/101-bad.xdot.stderr +2 -0
  115. package/src/gvc/__fixtures__/p7/images/101-gif.cmapx +2 -0
  116. package/src/gvc/__fixtures__/p7/images/101-gif.cmapx.stderr +0 -0
  117. package/src/gvc/__fixtures__/p7/images/101-gif.dot +8 -0
  118. package/src/gvc/__fixtures__/p7/images/101-gif.dot.stderr +0 -0
  119. package/src/gvc/__fixtures__/p7/images/101-gif.gv +1 -0
  120. package/src/gvc/__fixtures__/p7/images/101-gif.json +70 -0
  121. package/src/gvc/__fixtures__/p7/images/101-gif.json.stderr +1 -0
  122. package/src/gvc/__fixtures__/p7/images/101-gif.plain +3 -0
  123. package/src/gvc/__fixtures__/p7/images/101-gif.plain.stderr +0 -0
  124. package/src/gvc/__fixtures__/p7/images/101-gif.svg +19 -0
  125. package/src/gvc/__fixtures__/p7/images/101-gif.svg.stderr +0 -0
  126. package/src/gvc/__fixtures__/p7/images/101-gif.xdot +13 -0
  127. package/src/gvc/__fixtures__/p7/images/101-gif.xdot.stderr +0 -0
  128. package/src/gvc/__fixtures__/p7/images/101-jpg.cmapx +2 -0
  129. package/src/gvc/__fixtures__/p7/images/101-jpg.cmapx.stderr +0 -0
  130. package/src/gvc/__fixtures__/p7/images/101-jpg.dot +8 -0
  131. package/src/gvc/__fixtures__/p7/images/101-jpg.dot.stderr +0 -0
  132. package/src/gvc/__fixtures__/p7/images/101-jpg.gv +1 -0
  133. package/src/gvc/__fixtures__/p7/images/101-jpg.json +70 -0
  134. package/src/gvc/__fixtures__/p7/images/101-jpg.json.stderr +1 -0
  135. package/src/gvc/__fixtures__/p7/images/101-jpg.plain +3 -0
  136. package/src/gvc/__fixtures__/p7/images/101-jpg.plain.stderr +0 -0
  137. package/src/gvc/__fixtures__/p7/images/101-jpg.svg +19 -0
  138. package/src/gvc/__fixtures__/p7/images/101-jpg.svg.stderr +0 -0
  139. package/src/gvc/__fixtures__/p7/images/101-jpg.xdot +13 -0
  140. package/src/gvc/__fixtures__/p7/images/101-jpg.xdot.stderr +0 -0
  141. package/src/gvc/__fixtures__/p7/images/101-png.cmapx +2 -0
  142. package/src/gvc/__fixtures__/p7/images/101-png.cmapx.stderr +0 -0
  143. package/src/gvc/__fixtures__/p7/images/101-png.dot +8 -0
  144. package/src/gvc/__fixtures__/p7/images/101-png.dot.stderr +0 -0
  145. package/src/gvc/__fixtures__/p7/images/101-png.gv +1 -0
  146. package/src/gvc/__fixtures__/p7/images/101-png.json +70 -0
  147. package/src/gvc/__fixtures__/p7/images/101-png.json.stderr +1 -0
  148. package/src/gvc/__fixtures__/p7/images/101-png.plain +3 -0
  149. package/src/gvc/__fixtures__/p7/images/101-png.plain.stderr +0 -0
  150. package/src/gvc/__fixtures__/p7/images/101-png.svg +19 -0
  151. package/src/gvc/__fixtures__/p7/images/101-png.svg.stderr +0 -0
  152. package/src/gvc/__fixtures__/p7/images/101-png.xdot +13 -0
  153. package/src/gvc/__fixtures__/p7/images/101-png.xdot.stderr +0 -0
  154. package/src/gvc/__fixtures__/p7/images/101-svg.cmapx +2 -0
  155. package/src/gvc/__fixtures__/p7/images/101-svg.cmapx.stderr +0 -0
  156. package/src/gvc/__fixtures__/p7/images/101-svg.dot +8 -0
  157. package/src/gvc/__fixtures__/p7/images/101-svg.dot.stderr +0 -0
  158. package/src/gvc/__fixtures__/p7/images/101-svg.gv +1 -0
  159. package/src/gvc/__fixtures__/p7/images/101-svg.json +70 -0
  160. package/src/gvc/__fixtures__/p7/images/101-svg.json.stderr +1 -0
  161. package/src/gvc/__fixtures__/p7/images/101-svg.plain +3 -0
  162. package/src/gvc/__fixtures__/p7/images/101-svg.plain.stderr +0 -0
  163. package/src/gvc/__fixtures__/p7/images/101-svg.svg +19 -0
  164. package/src/gvc/__fixtures__/p7/images/101-svg.svg.stderr +0 -0
  165. package/src/gvc/__fixtures__/p7/images/101-svg.xdot +13 -0
  166. package/src/gvc/__fixtures__/p7/images/101-svg.xdot.stderr +0 -0
  167. package/src/gvc/__fixtures__/p7/images/101-svgbare.cmapx +2 -0
  168. package/src/gvc/__fixtures__/p7/images/101-svgbare.cmapx.stderr +2 -0
  169. package/src/gvc/__fixtures__/p7/images/101-svgbare.dot +8 -0
  170. package/src/gvc/__fixtures__/p7/images/101-svgbare.dot.stderr +2 -0
  171. package/src/gvc/__fixtures__/p7/images/101-svgbare.gv +1 -0
  172. package/src/gvc/__fixtures__/p7/images/101-svgbare.json +68 -0
  173. package/src/gvc/__fixtures__/p7/images/101-svgbare.json.stderr +2 -0
  174. package/src/gvc/__fixtures__/p7/images/101-svgbare.plain +3 -0
  175. package/src/gvc/__fixtures__/p7/images/101-svgbare.plain.stderr +2 -0
  176. package/src/gvc/__fixtures__/p7/images/101-svgbare.svg +18 -0
  177. package/src/gvc/__fixtures__/p7/images/101-svgbare.svg.stderr +2 -0
  178. package/src/gvc/__fixtures__/p7/images/101-svgbare.xdot +13 -0
  179. package/src/gvc/__fixtures__/p7/images/101-svgbare.xdot.stderr +2 -0
  180. package/src/gvc/__fixtures__/p7/images/102-ip-abs.gv +1 -0
  181. package/src/gvc/__fixtures__/p7/images/102-ip-abs.svg +18 -0
  182. package/src/gvc/__fixtures__/p7/images/102-ip-abs.svg.stderr +2 -0
  183. package/src/gvc/__fixtures__/p7/images/102-ip-abs.xdot +14 -0
  184. package/src/gvc/__fixtures__/p7/images/102-ip-abs.xdot.stderr +2 -0
  185. package/src/gvc/__fixtures__/p7/images/102-ip-found.gv +1 -0
  186. package/src/gvc/__fixtures__/p7/images/102-ip-found.svg +19 -0
  187. package/src/gvc/__fixtures__/p7/images/102-ip-found.svg.stderr +0 -0
  188. package/src/gvc/__fixtures__/p7/images/102-ip-found.xdot +14 -0
  189. package/src/gvc/__fixtures__/p7/images/102-ip-found.xdot.stderr +0 -0
  190. package/src/gvc/__fixtures__/p7/images/102-ip-missing.gv +1 -0
  191. package/src/gvc/__fixtures__/p7/images/102-ip-missing.svg +18 -0
  192. package/src/gvc/__fixtures__/p7/images/102-ip-missing.svg.stderr +2 -0
  193. package/src/gvc/__fixtures__/p7/images/102-ip-missing.xdot +14 -0
  194. package/src/gvc/__fixtures__/p7/images/102-ip-missing.xdot.stderr +2 -0
  195. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.gv +1 -0
  196. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.svg +18 -0
  197. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.svg.stderr +2 -0
  198. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.xdot +15 -0
  199. package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.xdot.stderr +2 -0
  200. package/src/gvc/__fixtures__/p7/images/102-ip-two.gv +1 -0
  201. package/src/gvc/__fixtures__/p7/images/102-ip-two.svg +19 -0
  202. package/src/gvc/__fixtures__/p7/images/102-ip-two.svg.stderr +0 -0
  203. package/src/gvc/__fixtures__/p7/images/102-ip-two.xdot +14 -0
  204. package/src/gvc/__fixtures__/p7/images/102-ip-two.xdot.stderr +0 -0
  205. package/src/gvc/__fixtures__/p7/images/97-custom.gv +1 -0
  206. package/src/gvc/__fixtures__/p7/images/97-custom.svg +18 -0
  207. package/src/gvc/__fixtures__/p7/images/97-custom.svg.stderr +1 -0
  208. package/src/gvc/__fixtures__/p7/images/97-custom.xdot +13 -0
  209. package/src/gvc/__fixtures__/p7/images/97-custom.xdot.stderr +1 -0
  210. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.gv +1 -0
  211. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.svg +19 -0
  212. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.svg.stderr +1 -0
  213. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.xdot +14 -0
  214. package/src/gvc/__fixtures__/p7/images/97-nosuch-image.xdot.stderr +1 -0
  215. package/src/gvc/__fixtures__/p7/images/bad.png +1 -0
  216. package/src/gvc/__fixtures__/p7/images/d/r.png +0 -0
  217. package/src/gvc/__fixtures__/p7/images/d2/r.png +0 -0
  218. package/src/gvc/__fixtures__/p7/images/g.gif +0 -0
  219. package/src/gvc/__fixtures__/p7/images/graphs-val_val.gv +10 -0
  220. package/src/gvc/__fixtures__/p7/images/graphs-val_val.svg +25 -0
  221. package/src/gvc/__fixtures__/p7/images/graphs-val_val.svg.stderr +3 -0
  222. package/src/gvc/__fixtures__/p7/images/graphs-val_val.xdot +30 -0
  223. package/src/gvc/__fixtures__/p7/images/graphs-val_val.xdot.stderr +3 -0
  224. package/src/gvc/__fixtures__/p7/images/j.jpg +0 -0
  225. package/src/gvc/__fixtures__/p7/images/r.png +0 -0
  226. package/src/gvc/__fixtures__/p7/images/s.svg +2 -0
  227. package/src/gvc/__fixtures__/p7/images/sb.svg +1 -0
  228. package/src/gvc/__fixtures__/p7/images/t.png +0 -0
  229. package/src/gvc/__fixtures__/p7/regen.sh +23 -0
  230. package/src/gvc/device-cluster.ts +3 -2
  231. package/src/gvc/device.ts +12 -4
  232. package/src/gvc/image-type.ts +122 -0
  233. package/src/gvc/render-usershape.ts +260 -0
  234. package/src/gvc/usershape.ts +40 -1
  235. package/src/layout/neato/__fixtures__/ipsep/big-dired.gv +243 -0
  236. package/src/layout/neato/__fixtures__/ipsep/big-dired.trace +55 -0
  237. package/src/layout/neato/__fixtures__/ipsep/big-dired.xdot +1832 -0
  238. package/src/layout/neato/__fixtures__/ipsep/big-dired.xdot.stderr +0 -0
  239. package/src/layout/neato/__fixtures__/ipsep/cluster.gv +1 -0
  240. package/src/layout/neato/__fixtures__/ipsep/cluster.trace +95 -0
  241. package/src/layout/neato/__fixtures__/ipsep/cluster.xdot +58 -0
  242. package/src/layout/neato/__fixtures__/ipsep/cluster.xdot.stderr +0 -0
  243. package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.gv +1 -0
  244. package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.trace +40 -0
  245. package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.xdot +72 -0
  246. package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.xdot.stderr +0 -0
  247. package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.gv +1 -0
  248. package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.trace +43 -0
  249. package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.xdot +72 -0
  250. package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.xdot.stderr +0 -0
  251. package/src/layout/neato/__fixtures__/ipsep/dired-hier.gv +1 -0
  252. package/src/layout/neato/__fixtures__/ipsep/dired-hier.trace +43 -0
  253. package/src/layout/neato/__fixtures__/ipsep/dired-hier.xdot +71 -0
  254. package/src/layout/neato/__fixtures__/ipsep/dired-hier.xdot.stderr +0 -0
  255. package/src/layout/neato/__fixtures__/ipsep/dired-true.gv +1 -0
  256. package/src/layout/neato/__fixtures__/ipsep/dired-true.trace +51 -0
  257. package/src/layout/neato/__fixtures__/ipsep/dired-true.xdot +71 -0
  258. package/src/layout/neato/__fixtures__/ipsep/dired-true.xdot.stderr +0 -0
  259. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.gv +1 -0
  260. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.trace +41 -0
  261. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +77 -0
  262. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot.stderr +0 -0
  263. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.gv +1 -0
  264. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.trace +41 -0
  265. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +68 -0
  266. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot.stderr +0 -0
  267. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.gv +1 -0
  268. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.trace +42 -0
  269. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +110 -0
  270. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot.stderr +0 -0
  271. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.gv +1 -0
  272. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.trace +49 -0
  273. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +108 -0
  274. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot.stderr +0 -0
  275. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.gv +1 -0
  276. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.trace +43 -0
  277. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +83 -0
  278. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot.stderr +0 -0
  279. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.gv +1 -0
  280. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.trace +49 -0
  281. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +48 -0
  282. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot.stderr +0 -0
  283. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.gv +1 -0
  284. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.trace +45 -0
  285. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +47 -0
  286. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot.stderr +0 -0
  287. package/src/layout/neato/__fixtures__/ipsep/len-dired.gv +1 -0
  288. package/src/layout/neato/__fixtures__/ipsep/len-dired.trace +44 -0
  289. package/src/layout/neato/__fixtures__/ipsep/len-dired.xdot +66 -0
  290. package/src/layout/neato/__fixtures__/ipsep/len-dired.xdot.stderr +0 -0
  291. package/src/layout/neato/__fixtures__/ipsep/model-circuit.gv +1 -0
  292. package/src/layout/neato/__fixtures__/ipsep/model-circuit.trace +46 -0
  293. package/src/layout/neato/__fixtures__/ipsep/model-circuit.xdot +83 -0
  294. package/src/layout/neato/__fixtures__/ipsep/model-circuit.xdot.stderr +0 -0
  295. package/src/layout/neato/__fixtures__/ipsep/model-mds-len.gv +1 -0
  296. package/src/layout/neato/__fixtures__/ipsep/model-mds-len.trace +52 -0
  297. package/src/layout/neato/__fixtures__/ipsep/model-mds-len.xdot +72 -0
  298. package/src/layout/neato/__fixtures__/ipsep/model-mds-len.xdot.stderr +0 -0
  299. package/src/layout/neato/__fixtures__/ipsep/model-mds.gv +1 -0
  300. package/src/layout/neato/__fixtures__/ipsep/model-mds.trace +52 -0
  301. package/src/layout/neato/__fixtures__/ipsep/model-mds.xdot +83 -0
  302. package/src/layout/neato/__fixtures__/ipsep/model-mds.xdot.stderr +2 -0
  303. package/src/layout/neato/__fixtures__/ipsep/model-subset.gv +1 -0
  304. package/src/layout/neato/__fixtures__/ipsep/model-subset.trace +49 -0
  305. package/src/layout/neato/__fixtures__/ipsep/model-subset.xdot +83 -0
  306. package/src/layout/neato/__fixtures__/ipsep/model-subset.xdot.stderr +0 -0
  307. package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.gv +1 -0
  308. package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.trace +211 -0
  309. package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.xdot +60 -0
  310. package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.xdot.stderr +0 -0
  311. package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.gv +1 -0
  312. package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.trace +50 -0
  313. package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.xdot +60 -0
  314. package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.xdot.stderr +0 -0
  315. package/src/layout/neato/__fixtures__/ipsep/start-self-dired.gv +1 -0
  316. package/src/layout/neato/__fixtures__/ipsep/start-self-dired.trace +51 -0
  317. package/src/layout/neato/__fixtures__/ipsep/start-self-dired.xdot +72 -0
  318. package/src/layout/neato/__fixtures__/ipsep/start-self-dired.xdot.stderr +0 -0
  319. package/src/layout/neato/__fixtures__/ipsep/start-self.gv +1 -0
  320. package/src/layout/neato/__fixtures__/ipsep/start-self.trace +43 -0
  321. package/src/layout/neato/__fixtures__/ipsep/start-self.xdot +84 -0
  322. package/src/layout/neato/__fixtures__/ipsep/start-self.xdot.stderr +0 -0
  323. package/src/layout/neato/__fixtures__/quad-prog-vpsc.ts +109 -0
  324. package/src/layout/neato/__fixtures__/stress-models.ts +64 -0
  325. package/src/layout/neato/circuit.ts +31 -0
  326. package/src/layout/neato/index.ts +2 -2
  327. package/src/layout/neato/init.ts +25 -34
  328. package/src/layout/neato/ipsep-opts.ts +158 -0
  329. package/src/layout/neato/lu.ts +189 -0
  330. package/src/layout/neato/matinv.ts +37 -0
  331. package/src/layout/neato/quad-prog-vpsc-overlap.ts +365 -0
  332. package/src/layout/neato/quad-prog-vpsc.ts +416 -0
  333. package/src/layout/neato/start.ts +9 -24
  334. package/src/layout/neato/stress-cola.ts +497 -0
  335. package/src/layout/neato/stress-kernel.ts +1 -17
  336. package/src/layout/neato/stress-models.ts +212 -0
  337. package/src/layout/neato/vpsc-adjust.ts +35 -66
  338. package/src/render/color-resolve.ts +25 -2
  339. package/src/render/dot/edge-draw.ts +7 -4
  340. package/src/render/dot.ts +14 -1
  341. package/src/render/svg-arrow-ops.ts +35 -19
  342. package/src/render/svg-edge-arrows.ts +7 -6
  343. package/src/render/svg-helpers.ts +19 -11
  344. package/src/render/svg.ts +15 -3
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <!-- Generated by graphviz version 16.1.0 (20261012.1431)
5
+ -->
6
+ <!-- Title: G Pages: 1 -->
7
+ <svg width="1314pt" height="109pt"
8
+ viewBox="0.00 0.00 1314.00 109.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
+ <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 105)">
10
+ <title>G</title>
11
+ <polygon fill="white" stroke="none" points="-4,4 -4,-105 1310.21,-105 1310.21,4 -4,4"/>
12
+ <!-- a -->
13
+ <g id="node1" class="node">
14
+ <title>a</title>
15
+ <text xml:space="preserve" text-anchor="start" x="16" y="-59" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="30.00">image attribute (valid absolute pathname)</text>
16
+ <text xml:space="preserve" text-anchor="start" x="16" y="-18" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="30.00">imagepath attribute (valid absolute pathname)</text>
17
+ </g>
18
+ <!-- b -->
19
+ <g id="node2" class="node">
20
+ <title>b</title>
21
+ <polygon fill="none" stroke="black" points="1306.21,-72.5 601.25,-72.5 601.25,-28.5 1306.21,-28.5 1306.21,-72.5"/>
22
+ <text xml:space="preserve" text-anchor="middle" x="953.73" y="-37.5" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="30.00">image from image attribute directory should be displayed</text>
23
+ </g>
24
+ </g>
25
+ </svg>
@@ -0,0 +1,3 @@
1
+ Warning: Warning: no hard-coded metrics for 'Helvetica-Bold'. Falling back to 'Times' metrics
2
+ Warning: Filename "imagepath_test/image_dir/image.jpg" is unsafe
3
+ Warning: No or improper image="imagepath_test/image_dir/image.jpg" for node "b"
@@ -0,0 +1,30 @@
1
+ graph G {
2
+ graph [_draw_="c 9 -#fffffe00 C 7 -#ffffff P 4 0 0 0 101 1306.21 101 1306.21 0 ",
3
+ bb="0,0,1306.2,101",
4
+ imagepath="imagepath_test/imagepath_dir/",
5
+ xdotversion=1.7
6
+ ];
7
+ node [label="\N"];
8
+ a [_ldraw_="F 30 14 -Helvetica-Bold c 7 -#000000 T 16 59 -1 499.82 41 -image attribute (valid absolute pathname) F 30 14 -Helvetica-Bold c 7 \
9
+ -#000000 T 16 18 -1 551.47 45 -imagepath attribute (valid absolute pathname) ",
10
+ height=1.4028,
11
+ label=<<TABLE CELLSPACING="2" CELLPADDING="2" BORDER="0"
12
+ CELLBORDER="0"><TR><TD><TABLE CELLSPACING="3" CELLPADDING="1" BORDER="0"
13
+ CELLBORDER="0">
14
+ <TR><TD ALIGN="left"><FONT POINT-SIZE="30.0" FACE="Helvetica-Bold">image attribute (valid absolute pathname)</FONT></TD></TR><TR><TD ALIGN="left"><FONT POINT-SIZE="30.0" FACE="Helvetica-Bold">imagepath attribute (valid absolute pathname)</FONT></TD></TR>
15
+ </TABLE></TD></TR></TABLE>>,
16
+ pos="291.73,50.5",
17
+ shape=plaintext,
18
+ width=8.1037];
19
+ b [_draw_="c 7 -#000000 p 4 1306.21 72.5 601.25 72.5 601.25 28.5 1306.21 28.5 ",
20
+ _ldraw_="F 30 14 -Helvetica-Bold c 7 -#000000 T 953.73 37.5 0 688.96 56 -image from image attribute directory should be displayed ",
21
+ fontname="Helvetica-Bold",
22
+ fontsize=30,
23
+ height=0.61111,
24
+ image="imagepath_test/image_dir/image.jpg",
25
+ label="image from image attribute directory should be displayed",
26
+ labelloc=b,
27
+ pos="953.73,50.5",
28
+ shape=box,
29
+ width=9.7911];
30
+ }
@@ -0,0 +1,3 @@
1
+ Warning: Warning: no hard-coded metrics for 'Helvetica-Bold'. Falling back to 'Times' metrics
2
+ Warning: Filename "imagepath_test/image_dir/image.jpg" is unsafe
3
+ Warning: No or improper image="imagepath_test/image_dir/image.jpg" for node "b"
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="30pt" height="20pt" viewBox="0 0 30 20"><rect width="30" height="20"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="30pt" height="20pt" viewBox="0 0 30 20"><rect width="30" height="20"/></svg>
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+ # SPDX-License-Identifier: EPL-2.0
3
+ # Regenerates the part-7 native fixtures: graphviz 16.1.0 (oracle/16.1.0),
4
+ # run from each fixture dir so relative image names resolve.
5
+ # Usage: GVBINDIR=<full plugin dir> bash regen.sh
6
+ set -u
7
+ DOT=${DOT:-$HOME/git/graphviz/build/cmd/dot/dot}
8
+ HERE=$(cd "$(dirname "$0")" && pwd)
9
+ run() { # dir case fmt...
10
+ local dir=$1 c=$2; shift 2
11
+ for fmt in "$@"; do
12
+ (cd "$HERE/$dir" && "$DOT" -T"$fmt" "$c.gv" > "$c.$fmt" 2> "$c.$fmt.stderr")
13
+ done
14
+ }
15
+ for c in 97-custom 97-nosuch-image 102-ip-found 102-ip-missing 102-ip-abs \
16
+ 102-ip-two 102-ip-shapefile graphs-val_val; do run images "$c" svg xdot; done
17
+ run images 100-rotate svg
18
+ for c in 101-png 101-gif 101-jpg 101-svg 101-svgbare 101-bad; do
19
+ run images "$c" svg xdot json dot plain cmapx
20
+ done
21
+ for c in 98-point 99-edge 99-edge-color 99-edge-red-colon; do
22
+ run colors "$c" svg xdot json
23
+ done
@@ -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
@@ -44,7 +44,7 @@ import {
44
44
  } from '../common/style-resolve.js';
45
45
  import { isPointNode } from '../common/poly-gencode.js';
46
46
  import {
47
- resolveRenderColor, withColorScheme, reportEdgeColors, reportColorNames, backgroundColors,
47
+ resolveRenderColor, resolveFillColorName, edgeFillName, withColorScheme, reportEdgeColors, reportColorNames, backgroundColors,
48
48
  setRendererKnownColors,
49
49
  } from '../render/color-resolve.js';
50
50
  import { emitRoundedBezier } from '../common/poly-shapes.js';
@@ -167,9 +167,16 @@ function setEdgePen(e: Edge, job: RenderJob, styles: readonly string[]): void {
167
167
  // Raw style tokens for xdot's `S` ops (e.g. explicit style="solid"); SVG
168
168
  // reads only obj.pen, so this is xdot-only. @see gvrender_core_dot.c xdot_style
169
169
  obj.rawStyle = [...styles];
170
- // emit_begin_edge: `if (styles && ED_spl(e)) gvrender_set_style(job, styles)`
171
- // @see lib/common/emit.c:2726
172
- if (e.info.spl !== undefined) gvrenderSetStyle(obj.rawStyle);
170
+ // emit_begin_edge: `if (styles && ED_spl(e)) gvrender_set_style` (emit.c:2726);
171
+ // emit_edge_graphics resolves colours only with a spline too (emit.c:2366).
172
+ if (e.info.spl === undefined) return;
173
+ gvrenderSetStyle(obj.rawStyle);
174
+ // After the style warnings: gvrender_set_fillcolor; arrowheads fill with it.
175
+ const fill = edgeFillName(e.attrs.get('color') ?? '', e.attrs.get('fillcolor'));
176
+ if (fill !== undefined) {
177
+ obj.fillColor = withColorScheme(e.attrs.get('colorscheme'),
178
+ () => resolveFillColorName(fill.name, fill.report));
179
+ }
173
180
  }
174
181
 
175
182
  export function renderEdge(e: Edge, renderer: RendererPlugin, job: RenderJob): void {
@@ -426,6 +433,7 @@ export function render(ctx: GvcContext, g: Graph, format: string, inlineImages =
426
433
  const job = new RenderJob(format, ctx.textMeasurer);
427
434
  job.inlineImages = inlineImages;
428
435
  if (ctx.imageResolver !== undefined) job.imageResolver = ctx.imageResolver;
436
+ if (ctx.imageSizer !== undefined) job.imageSizer = ctx.imageSizer;
429
437
  // gvc->bb = GD_bb(g) verbatim -- no recompute fallback. Every layout engine
430
438
  // sets g.info.bb itself before render() runs (set_aspect for dot,
431
439
  // compute_bb-equivalent computeSubgraphBB calls in neato/circo/sfdp/fdp/
@@ -0,0 +1,122 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * Image type sniffing: the magic-byte table and `imagetype` of gvusershape.c,
5
+ * run over the bytes the caller's image resolver supplies (AD-5) instead of a
6
+ * `FILE *`.
7
+ *
8
+ * `ImageType` is an as-const object rather than C's enum / a `const enum`
9
+ * (TS6-forward: `const enum` does not survive declaration boundaries); its
10
+ * members and order are `imagetype_t`.
11
+ *
12
+ * @see lib/common/usershape.h:imagetype_t, lib/gvc/gvusershape.c:55-175
13
+ */
14
+
15
+ /** @see lib/common/usershape.h:24-27 */
16
+ export const ImageType = {
17
+ FT_NULL: 0,
18
+ FT_BMP: 1,
19
+ FT_GIF: 2,
20
+ FT_PNG: 3,
21
+ FT_JPEG: 4,
22
+ FT_PDF: 5,
23
+ FT_PS: 6,
24
+ FT_EPS: 7,
25
+ FT_SVG: 8,
26
+ FT_XML: 9,
27
+ FT_RIFF: 10,
28
+ FT_WEBP: 11,
29
+ FT_ICO: 12,
30
+ FT_TIFF: 13,
31
+ } as const;
32
+ export type ImageType = (typeof ImageType)[keyof typeof ImageType];
33
+
34
+ /** @see lib/gvc/gvusershape.c:HDRLEN */
35
+ const HDRLEN = 20;
36
+
37
+ /** @see lib/gvc/gvusershape.c:knowntype_t */
38
+ interface KnownType {
39
+ readonly template: readonly number[];
40
+ readonly type: ImageType;
41
+ readonly stringtype: string;
42
+ }
43
+
44
+ const bytesOf = (s: string): number[] => Array.from(s, c => c.charCodeAt(0));
45
+
46
+ /** @see lib/gvc/gvusershape.c:XML_MAGIC */
47
+ const XML_MAGIC = bytesOf('<?xml');
48
+ /** @see lib/gvc/gvusershape.c:SVG_MAGIC */
49
+ const SVG_MAGIC = bytesOf('<svg');
50
+ /** @see lib/gvc/gvusershape.c:WEBP_MAGIC */
51
+ const WEBP_MAGIC = bytesOf('WEBP');
52
+ const GT = 0x3e; // '>'
53
+
54
+ /** @see lib/gvc/gvusershape.c:knowntypes (PNG_MAGIC .. ICO_MAGIC) */
55
+ const KNOWN_TYPES: readonly KnownType[] = [
56
+ { template: [0x89, ...bytesOf('PNG'), 0x0d, 0x0a, 0x1a, 0x0a], type: ImageType.FT_PNG, stringtype: 'png' },
57
+ { template: bytesOf('%!PS-Adobe-'), type: ImageType.FT_PS, stringtype: 'ps' },
58
+ { template: bytesOf('BM'), type: ImageType.FT_BMP, stringtype: 'bmp' },
59
+ { template: bytesOf('GIF8'), type: ImageType.FT_GIF, stringtype: 'gif' },
60
+ { template: [0xff, 0xd8, 0xff], type: ImageType.FT_JPEG, stringtype: 'jpeg' },
61
+ { template: bytesOf('%PDF-'), type: ImageType.FT_PDF, stringtype: 'pdf' },
62
+ { template: [0xc5, 0xd0, 0xd3, 0xc6], type: ImageType.FT_EPS, stringtype: 'eps' },
63
+ { template: XML_MAGIC, type: ImageType.FT_XML, stringtype: 'xml' },
64
+ { template: bytesOf('RIFF'), type: ImageType.FT_RIFF, stringtype: 'riff' },
65
+ { template: [0x00, 0x00, 0x01, 0x00], type: ImageType.FT_ICO, stringtype: 'ico' },
66
+ ];
67
+
68
+ /** Result of `imagetype`: `us->type` and `us->stringtype`. */
69
+ export interface ImageTypeResult {
70
+ type: ImageType;
71
+ stringtype: string;
72
+ }
73
+
74
+ const matchesAt = (bytes: Uint8Array, at: number, template: readonly number[]): boolean =>
75
+ template.every((b, i) => bytes[at + i] === b);
76
+
77
+ /**
78
+ * The FT_XML tail of `imagetype`: skip to the end of the XML declaration when
79
+ * the header did not hold its `>`, then slide a 4-byte window looking for
80
+ * `<svg`. Exhausting the bytes leaves the type FT_XML. The window starts at
81
+ * the file position after the header (or after the `>` found by the scan), as
82
+ * C's `fread` does.
83
+ * @see lib/gvc/gvusershape.c:imagetype (the FT_XML branch)
84
+ */
85
+ function scanXmlForSvg(bytes: Uint8Array): ImageTypeResult {
86
+ const xml: ImageTypeResult = { type: ImageType.FT_XML, stringtype: 'xml' };
87
+ let pos = HDRLEN;
88
+ if (!bytes.subarray(0, HDRLEN).includes(GT)) {
89
+ for (;;) {
90
+ if (pos >= bytes.length) return xml;
91
+ if (bytes[pos++] === GT) break;
92
+ }
93
+ }
94
+ if (bytes.length - pos < SVG_MAGIC.length) return xml;
95
+ let tag = pos;
96
+ pos += SVG_MAGIC.length;
97
+ for (;;) {
98
+ if (matchesAt(bytes, tag, SVG_MAGIC)) return { type: ImageType.FT_SVG, stringtype: 'svg' };
99
+ if (pos >= bytes.length) return xml;
100
+ tag++;
101
+ pos++;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Sniff the image type from its leading bytes. Fewer than HDRLEN bytes, or no
107
+ * matching template, is FT_NULL with stringtype "(lib)".
108
+ * @see lib/gvc/gvusershape.c:imagetype
109
+ */
110
+ export function imagetype(bytes: Uint8Array): ImageTypeResult {
111
+ if (bytes.length >= HDRLEN) {
112
+ for (const known of KNOWN_TYPES) {
113
+ if (!matchesAt(bytes, 0, known.template)) continue;
114
+ if (known.type === ImageType.FT_XML) return scanXmlForSvg(bytes);
115
+ if (known.type === ImageType.FT_RIFF && matchesAt(bytes, 8, WEBP_MAGIC)) {
116
+ return { type: ImageType.FT_WEBP, stringtype: 'webp' };
117
+ }
118
+ return { type: known.type, stringtype: known.stringtype };
119
+ }
120
+ }
121
+ return { type: ImageType.FT_NULL, stringtype: '(lib)' };
122
+ }
@@ -0,0 +1,260 @@
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, usershapeType, type ImageSizer } from './usershape.js';
14
+ import { ImageType } from './image-type.js';
15
+ import { agwarningf } from '../common/agerr.js';
16
+ import { mapbool } from '../layout/dot/rank.js';
17
+
18
+ /** @see lib/gvc/gvcjob.h:imagescale_t */
19
+ export const ImageScale = {
20
+ False: 'false',
21
+ True: 'true',
22
+ Width: 'width',
23
+ Height: 'height',
24
+ Both: 'both',
25
+ } as const;
26
+ export type ImageScale = (typeof ImageScale)[keyof typeof ImageScale];
27
+
28
+ /** @see lib/gvc/gvcjob.h:imagepos_t */
29
+ export const ImagePos = {
30
+ TopLeft: 'tl',
31
+ TopCenter: 'tc',
32
+ TopRight: 'tr',
33
+ MiddleLeft: 'ml',
34
+ MiddleCenter: 'mc',
35
+ MiddleRight: 'mr',
36
+ BottomLeft: 'bl',
37
+ BottomCenter: 'bc',
38
+ BottomRight: 'br',
39
+ } as const;
40
+ export type ImagePos = (typeof ImagePos)[keyof typeof ImagePos];
41
+
42
+ const IMAGE_POSITIONS: ReadonlySet<string> = new Set(Object.values(ImagePos));
43
+
44
+ /** @see lib/gvc/gvrender.c:get_imagescale */
45
+ export function getImagescale(s: string): ImageScale {
46
+ if (s === '') return ImageScale.False;
47
+ const l = s.toLowerCase();
48
+ if (l === 'width') return ImageScale.Width;
49
+ if (l === 'height') return ImageScale.Height;
50
+ if (l === 'both') return ImageScale.Both;
51
+ if (mapbool(s)) return ImageScale.True;
52
+ return ImageScale.False;
53
+ }
54
+
55
+ /** @see lib/gvc/gvrender.c:get_imagepos */
56
+ export function getImagepos(s: string): ImagePos {
57
+ if (s === '') return ImagePos.MiddleCenter;
58
+ const l = s.toLowerCase();
59
+ return IMAGE_POSITIONS.has(l) ? (l as ImagePos) : ImagePos.MiddleCenter;
60
+ }
61
+
62
+ /** Scale `isz` toward the polygon extent (pw, ph) per `imagescale`. */
63
+ function scaleImage(
64
+ mode: ImageScale, isz: { w: number; h: number }, pw: number, ph: number,
65
+ ): { iw: number; ih: number } {
66
+ let iw = isz.w;
67
+ let ih = isz.h;
68
+ const scalex = pw / iw;
69
+ const scaley = ph / ih;
70
+ switch (mode) {
71
+ case ImageScale.True:
72
+ // keep aspect ratio fixed by just using the smaller scale
73
+ if (scalex < scaley) {
74
+ iw *= scalex;
75
+ ih *= scalex;
76
+ } else {
77
+ iw *= scaley;
78
+ ih *= scaley;
79
+ }
80
+ break;
81
+ case ImageScale.Width:
82
+ iw *= scalex;
83
+ break;
84
+ case ImageScale.Height:
85
+ ih *= scaley;
86
+ break;
87
+ case ImageScale.Both:
88
+ iw *= scalex;
89
+ ih *= scaley;
90
+ break;
91
+ case ImageScale.False:
92
+ break;
93
+ }
94
+ return { iw, ih };
95
+ }
96
+
97
+ /** Apply `imagepos` to the target box when the image is narrower than it. */
98
+ function positionX(b: Box, position: ImagePos, iw: number, pw: number): void {
99
+ if (!(iw < pw)) return;
100
+ switch (position) {
101
+ case ImagePos.TopLeft:
102
+ case ImagePos.MiddleLeft:
103
+ case ImagePos.BottomLeft:
104
+ b.ur.x = b.ll.x + iw;
105
+ break;
106
+ case ImagePos.TopRight:
107
+ case ImagePos.MiddleRight:
108
+ case ImagePos.BottomRight:
109
+ b.ll.x += pw - iw;
110
+ b.ur.x = b.ll.x + iw;
111
+ break;
112
+ default:
113
+ b.ll.x += (pw - iw) / 2.0;
114
+ b.ur.x -= (pw - iw) / 2.0;
115
+ break;
116
+ }
117
+ }
118
+
119
+ /** Apply `imagepos` to the target box when the image is shorter than it. */
120
+ function positionY(b: Box, position: ImagePos, ih: number, ph: number): void {
121
+ if (!(ih < ph)) return;
122
+ switch (position) {
123
+ case ImagePos.TopLeft:
124
+ case ImagePos.TopCenter:
125
+ case ImagePos.TopRight:
126
+ b.ll.y = b.ur.y - ih;
127
+ break;
128
+ case ImagePos.BottomLeft:
129
+ case ImagePos.BottomCenter:
130
+ case ImagePos.BottomRight:
131
+ // Kept as C writes it: ll moves up by ih, ur lands on the old ll; the
132
+ // LL/UR swap below restores order.
133
+ b.ll.y += ih;
134
+ b.ur.y = b.ll.y - ih;
135
+ break;
136
+ default:
137
+ b.ll.y += (ph - ih) / 2.0;
138
+ b.ur.y -= (ph - ih) / 2.0;
139
+ break;
140
+ }
141
+ }
142
+
143
+ /** Bounding box of the polygon `a` (expandbp over every vertex). */
144
+ function polygonBox(a: readonly Point[]): Box {
145
+ const first = a[0]!;
146
+ const b: Box = { ll: { x: first.x, y: first.y }, ur: { x: first.x, y: first.y } };
147
+ for (let i = 1; i < a.length; i++) {
148
+ const p = a[i]!;
149
+ if (p.x < b.ll.x) b.ll.x = p.x;
150
+ if (p.x > b.ur.x) b.ur.x = p.x;
151
+ if (p.y < b.ll.y) b.ll.y = p.y;
152
+ if (p.y > b.ur.y) b.ur.y = p.y;
153
+ }
154
+ return b;
155
+ }
156
+
157
+ /**
158
+ * The rendering context's image sizer (the port's gvusershape dictionary),
159
+ * set on the job by `render` beside `imageResolver`; undefined means the
160
+ * global `setImageSizer`.
161
+ */
162
+ declare module './job.js' {
163
+ interface RenderJob {
164
+ imageSizer?: ImageSizer | undefined;
165
+ /** `job->loadimage.engine` is set (a `gvloadimage_select` succeeded). */
166
+ loadimageEngineSet?: boolean;
167
+ }
168
+ }
169
+
170
+ /**
171
+ * The `type` strings `gvloadimage_core.c:gvloadimage_core_types` serves
172
+ * (`<stringtype>:<target>`); the plugin set lacks e.g. `png:json`.
173
+ * @see plugin/core/gvloadimage_core.c:280-335
174
+ */
175
+ export const CORE_LOADIMAGE_TYPES: ReadonlySet<string> = new Set([
176
+ 'png:svg', 'gif:svg', 'jpeg:svg', 'jpe:svg', 'jpg:svg',
177
+ 'png:fig', 'gif:fig', 'jpeg:fig', 'jpe:fig', 'jpg:fig',
178
+ 'png:vrml', 'gif:vrml', 'jpeg:vrml', 'jpe:vrml', 'jpg:vrml',
179
+ 'eps:ps', 'ps:ps', '(lib):ps',
180
+ 'png:map', 'gif:map', 'jpeg:map', 'jpe:map', 'jpg:map', 'ps:map', 'eps:map', 'svg:map',
181
+ 'png:dot', 'gif:dot', 'jpeg:dot', 'jpe:dot', 'jpg:dot', 'ps:dot', 'eps:dot', 'svg:dot',
182
+ 'png:xdot', 'gif:xdot', 'jpeg:xdot', 'jpe:xdot', 'jpg:xdot', 'ps:xdot', 'eps:xdot', 'svg:xdot',
183
+ 'svg:svg',
184
+ 'gif:tk',
185
+ ]);
186
+
187
+ /**
188
+ * `job->render.type` for a port renderer type: the device name maps to the
189
+ * renderer it runs on (`plain:dot`, `cmapx:map`, ...), not to itself.
190
+ * @see plugin/core/gvrender_core_dot.c:775, gvrender_core_map.c:273-276
191
+ */
192
+ const RENDER_TYPE_OF_DEVICE: Readonly<Record<string, string>> = {
193
+ plain: 'dot', 'plain-ext': 'dot',
194
+ imap: 'map', 'imap-np': 'map', cmapx: 'map', 'cmapx-np': 'map',
195
+ };
196
+
197
+ /**
198
+ * `gvloadimage`: build `"<stringtype>:<target>"`, warn when no loadimage
199
+ * plugin serves it. Returns whether the renderer's loadimage hook runs: C runs
200
+ * `job->loadimage.engine`, which stays set from an earlier successful select.
201
+ * @see lib/gvc/gvloadimage.c:gvloadimage (44-64), gvloadimage_select
202
+ */
203
+ function gvloadimageSelect(job: RenderJob, stringtype: string, target: string): boolean {
204
+ const type = `${stringtype}:${target}`;
205
+ if (CORE_LOADIMAGE_TYPES.has(type)) job.loadimageEngineSet = true;
206
+ else agwarningf(`No loadimage plugin for "${type}"`);
207
+ return job.loadimageEngineSet === true;
208
+ }
209
+
210
+ /**
211
+ * Scale the image `name` to the bounding box of polygon `a` per `imagescale`,
212
+ * place it per `imagepos`, convert to device coordinates unless the renderer
213
+ * transforms, and pass the box to the renderer's `usershape` (gvloadimage).
214
+ *
215
+ * `gvusershape_find` is "the caller supplies `name`" (sizer or resolver); the
216
+ * `find_user_shape` / `library_shape` branch is a no-op because no renderer
217
+ * has `library_shape`. `filled` is only read by loadimage plugins that paint a
218
+ * background (none of svg/xdot), so it is not forwarded.
219
+ *
220
+ * @see lib/gvc/gvrender.c:gvrender_usershape
221
+ */
222
+ export function gvrenderUsershape(
223
+ job: RenderJob, name: string, a: readonly Point[], _filled: boolean,
224
+ imagescale: string, imagepos: string,
225
+ ): void {
226
+ const sizer = job.imageSizer;
227
+ // gvusershape_find misses an image whose gvusershape_open failed (FT_NULL)
228
+ const utype = usershapeType(name, job.imageResolver);
229
+ if (utype?.type === ImageType.FT_NULL) return;
230
+ if (!imageIsSupplied(name, sizer, job.imageResolver)) return;
231
+
232
+ // gvusershape_size_dpi(us, job->dpi)
233
+ const isz = usershapeSizePts(name, job.dpi.x, sizer);
234
+ if (isz === null || (isz.x <= 0 && isz.y <= 0)) return;
235
+
236
+ const b = polygonBox(a);
237
+ const pw = b.ur.x - b.ll.x;
238
+ const ph = b.ur.y - b.ll.y;
239
+ const { iw, ih } = scaleImage(getImagescale(imagescale), { w: isz.x, h: isz.y }, pw, ph);
240
+
241
+ // if image is smaller in any dimension, apply the specified positioning
242
+ const position = getImagepos(imagepos);
243
+ positionX(b, position, iw, pw);
244
+ positionY(b, position, ih, ph);
245
+
246
+ // C converts graph to device coordinates here (gvrender_ptf) unless the
247
+ // renderer has GVRENDER_DOES_TRANSFORM. The port never sets that flag: its
248
+ // y-flip lives in transformPoint (devscale), applied by the callers of the
249
+ // primitives. Both renderers with a `usershape` (svg, xdot) are
250
+ // DOES_TRANSFORM in C and take graph coordinates (RendererPlugin.usershape
251
+ // contract), so the ptf branch is dead for every registered renderer.
252
+
253
+ if (b.ll.x > b.ur.x) [b.ll.x, b.ur.x] = [b.ur.x, b.ll.x];
254
+ if (b.ll.y > b.ur.y) [b.ll.y, b.ur.y] = [b.ur.y, b.ll.y];
255
+ // gvloadimage; a sizer-only image has no bytes and so no type (AD-5)
256
+ const device = job.renderer?.type ?? job.format;
257
+ const target = RENDER_TYPE_OF_DEVICE[device] ?? device;
258
+ if (utype !== null && !gvloadimageSelect(job, utype.stringtype, target)) return;
259
+ job.renderer?.usershape?.(name, b, job);
260
+ }
@@ -16,6 +16,8 @@
16
16
  import { invalidArgType } from '../errors.js';
17
17
  import type { ImageSizer } from '../common/htmltable-types.js';
18
18
  import { findImageBytes, type ImageResolver } from './image-resolver.js';
19
+ import { safefile } from '../common/safefile.js';
20
+ import { ImageType, imagetype, type ImageTypeResult } from './image-type.js';
19
21
 
20
22
  export type { ImageSizer } from '../common/htmltable-types.js';
21
23
 
@@ -55,12 +57,43 @@ export function imageIsSupplied(name: string, sizer?: ImageSizer, resolver?: Ima
55
57
  return size !== null || findImageBytes(name, resolver) !== null;
56
58
  }
57
59
 
60
+ /**
61
+ * The type `gvusershape_open` sniffs from the bytes the resolver supplies for
62
+ * `name`; null when there are none (a sizer-only image has no type, AD-5).
63
+ * @see lib/gvc/gvusershape.c:gvusershape_open (imagetype)
64
+ */
65
+ export function usershapeType(name: string, resolver?: ImageResolver): ImageTypeResult | null {
66
+ const found = findImageBytes(name, resolver);
67
+ return found === null ? null : imagetype(found.bytes);
68
+ }
69
+
70
+ /**
71
+ * The `agwarningf` text for bytes whose magic matches nothing and that name no
72
+ * shape-library member (the port has none).
73
+ * @see lib/gvc/gvusershape.c:gvusershape_open (FT_NULL case)
74
+ */
75
+ export function imageNotFoundWarning(name: string): string {
76
+ return `"${name}" was not found as a file or as a shape library member`;
77
+ }
78
+
79
+ /**
80
+ * The first warning `gvusershape_open` prints when it fails for `name`, or
81
+ * null when it succeeds: nothing supplied (the open failure) or resolver
82
+ * bytes of unknown type (FT_NULL).
83
+ * @see lib/gvc/gvusershape.c:gvusershape_open
84
+ */
85
+ export function imageOpenFailure(name: string, sizer?: ImageSizer, resolver?: ImageResolver): string | null {
86
+ if (!imageIsSupplied(name, sizer, resolver)) return imageOpenWarning(name);
87
+ return usershapeType(name, resolver)?.type === ImageType.FT_NULL ? imageNotFoundWarning(name) : null;
88
+ }
89
+
58
90
  /**
59
91
  * The `agwarningf` text `gvusershape_file_access` prints when it cannot open
60
92
  * `name`. C does not cache a failed open, so every sizing request repeats it.
61
93
  * @see lib/gvc/gvusershape.c:gvusershape_file_access
62
94
  */
63
95
  export function imageOpenWarning(name: string): string {
96
+ if (safefile(name) === null) return `Filename "${name}" is unsafe`;
64
97
  return `${STRERROR_ENOENT} while opening ${name}`;
65
98
  }
66
99
 
@@ -90,12 +123,18 @@ export function usershapeDpi(attrs: ReadonlyMap<string, string>): number {
90
123
  * the result is `(int)(px * 72 / dpi)` (the file's own dpi is unknown to a
91
124
  * sizer, so `us->dpi` is 0 as for most formats). Null stands for C's (-1,-1):
92
125
  * empty name or an image nobody supplies.
126
+ * @param resolver - the caller's resolver, when it has one; bytes it supplies
127
+ * with unknown magic make the open fail (no size).
93
128
  * @see lib/gvc/gvusershape.c:gvusershape_size, gvusershape_size_dpi
94
129
  */
95
130
  export function usershapeSizePts(
96
- name: string | undefined, dpi: number, sizer?: ImageSizer,
131
+ name: string | undefined, dpi: number, sizer?: ImageSizer, resolver?: ImageResolver,
97
132
  ): { x: number; y: number } | null {
98
133
  if (name === undefined || name === '') return null;
134
+ // gvusershape_open fails on bytes of unknown type: no size. Only a resolver
135
+ // the caller names is consulted: an omitted one must not reach the global
136
+ // resolver behind a per-context one (ADR-2).
137
+ if (resolver !== undefined && usershapeType(name, resolver)?.type === ImageType.FT_NULL) return null;
99
138
  const px = sizer !== undefined ? sizer(name) : findImageSize(name);
100
139
  if (px === null) return null;
101
140
  return {