Skip to content

SVG to IShape2 #498

Answered by jffaust
jffaust asked this question in Q&A
Apr 6, 2025 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Thanks for the response! I just found the pathFromSvg() and I was able to use it successfully. I understand things could get complex quite quickly if one would try to support SVG completely. For my use case I'm able to make it work by avoiding nested shapes and keeping things simple.

So far I have something like this:

/**
 * @param {any} shape 
 * @returns {import("@thi.ng/geom").IHiccupShape2}
 */
export function hiccupSvgToShape(shape) {
  const att = shape[1] || {};
  switch (shape[0]) {
    case "rect":
      return rect([att.x, att.y], [att.width, att.height], att.style);
    case "ellipse":
      return ellipse([att.cx, att.cy], [att.rx, att.ry], att.style);
    case "path":
      r…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@bsnbsn
Comment options

Answer selected by jffaust
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants