解析 SVG 路径元素中的 d 属性
我正在尝试解析SVG Path元素中的d属性,到目前为止我发现fabric.js可以解析SVG,但到目前为止我仍然不知道如何解析。
我需要解析路径以获得其中的形状(线条弧)并在它们上面绘制正方形,最重要的是返回这些正方形的属性。
知道如何使用 Fabric.js 做到这一点吗?或任何其他图书馆?或者有人有不同的方法吗?
下图有一个矩形和一条线,它们都有我在其边界上绘制的正方形,并且我尝试在路径元素上执行相同的操作
I'm trying to parse the d attribute in SVG Path element, and so far I found that fabric.js can parse SVG, but till now I still don't know how.
I need to parse the path in order to get the shapes in it (lines arcs) and draw squares over them, and most importantly return the attributes of these squares.
any idea how to do this using fabric.js?? or any other library?? or does anyone have a different approach?
the following image has a rectangle and a line both have squares that I drew on their boundaries, and I'm trying to do the same on the path element
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现它
可以获取每个命令及其参数,但是您需要从空格中修剪每个命令
I found this
which can get each command with its parameters, but you need to trim each command from spaces
根据 zeacuss 的回答和 Mark K Cowan 的建议,我正在使用:
Based on zeacuss answer and Mark K Cowan suggestion, I'm using:
陷入同样的问题。您可以使用 regep /-?\d+/ig 来生成数字,去掉字母和空格。和逗号。
Stamped into the same problem. You can use the regep /-?\d+/ig which produces just the numbers, striped from letters, white spaces. and commas.
Python 的 svgpathtools 库可能会满足您的需求。这是其功能列表(来自文档):
Python's svgpathtools library might be useful for your needs. This is a list of its features (from the documentation):