toPath static method

Map<String, dynamic> toPath(
  1. String? str
)

Implementation

static Map<String, dynamic> toPath(String? str) {
  Map<String, dynamic> pth = {"cmds": [], "crds": []};
  if (str == null) return pth;
  var doc = XmlDocument.parse(str);

  XmlElement svg = doc.firstChild! as XmlElement;
  while (svg.name.local != "svg") svg = svg.nextElementSibling!;
  var vbs = svg.getAttribute("viewBox");
  var vb;
  if (vbs != null) {
    vb = vbs.trim().split(" ").map((n) => num.parse(n));
  } else {
    vb = [0, 0, 1000, 1000];
  }
  _toPath(svg.children, pth, null);
  for (var i = 0; i < pth["crds"].length; i += 2) {
    var x = pth["crds"][i], y = pth["crds"][i + 1];
    x -= vb[0];
    y -= vb[1];
    y = -y;
    pth["crds"][i] = x;
    pth["crds"][i + 1] = y;
  }
  return pth;
}