哪个是最好的 SVG 到 NSBezierPath 库/类?
我正在寻找最好的 SVG 到 NSBezierPath 解析器,如果类/库只接受一串 SVG 命令就可以了,这里是一个例子:
M 435.722 403.542 h -232.44 v -293 h 232.44 c 0 0 0 35.108 0 81.019 c 0.049 2.551 0.079 5.135 0.154 7.748 c -0.208 15.567 12.1 13.618 19.624 28.192 c 2.584 5.005 5.875 30.5 4.875 34.5 c -7 19 -28.707 22.875 -24.653 44.854 c 0 2.667 0 5.31 0 7.923 C 435.722 364.425 435.722 403.542 435.722 403.542 z
类/库不一定必须解析 .svg 文件本身,但它应该能够处理所有 SVG 命令并支持相对和绝对坐标(换句话说,它应该与此处找到的 SVG 1.1 规范完全兼容)。
我在网上找到了一些课程,但它们都受到限制,并且使用上面的 svg 命令失败了。目前哪个是最好的 SVG 到 NSBezierPath 解析器?
I am looking for the best SVG to NSBezierPath parser, it's ok if the class/library only takes a string of SVG commands, here is an example:
M 435.722 403.542 h -232.44 v -293 h 232.44 c 0 0 0 35.108 0 81.019 c 0.049 2.551 0.079 5.135 0.154 7.748 c -0.208 15.567 12.1 13.618 19.624 28.192 c 2.584 5.005 5.875 30.5 4.875 34.5 c -7 19 -28.707 22.875 -24.653 44.854 c 0 2.667 0 5.31 0 7.923 C 435.722 364.425 435.722 403.542 435.722 403.542 z
The class/library doesn't neccessarily have to parse the .svg file itself, but it should be able to handle all SVG commands and support relative as well as absolute coordinates (in other words, it should be fully compatible with the SVG 1.1 specs found here).
I have found some classes on the web, but they were all limited and failed with my svg commands above. Which is the best SVG to NSBezierPath parser around these days?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编写一个程序,使用 XML 解析器解析 SVG 文件。
这将为您提供路径数组,您可以将其一一输入到以下代码中:
https://www.touchnoc .com/one_way_ticket_from_svg_to_nsbezierpath
** 请务必在上面的页面上查找适用于 iOS 的代码。
但是,上面的代码仅适用于绝对路径坐标,不适用于相对路径坐标。 Adobe Illustrator 仅输出相对路径坐标。您可以在名为 sketch (http://www.bohemiancoding.com/sketch/) 的程序中从 illustrator 打开 svg,然后导出 svg 将为您提供绝对路径坐标的文件。
您的路径失败可能是因为它们使用相对坐标 - 小 c,我发现的大多数脚本都可以转换绝对坐标,或大 C。
而且,就这样。整个过程并不容易,但是是可行的!我是根据经验说话的。
Write a program to parse the SVG file using an XML parser.
This will give you your array of paths which you can feed one by one into the following code:
https://www.touchnoc.com/one_way_ticket_from_svg_to_nsbezierpath
** Make sure to look for the code for iOS on the above page.
However, the above code only works for absolute path coordinates not relative path coordinates. Adobe Illustrator outputs only relative path coordinates. You can open your svg from illustrator in a program called sketch (http://www.bohemiancoding.com/sketch/) and export the svg will give you your file in absolute path coordinates.
Your paths are failing probably because they are using relative coordinates - small c, where most of the scripts I found can convert absolute, or big C.
And, there you go. The whole process is not easy but it is doable! I am speaking from experience.
我认为没有类似的东西可用。
但是您应该能够非常轻松地自己解析它,因为命令直接映射到 NSBezierPath 方法。
命令首先出现也很有帮助,因此您可以执行以下操作:
x
元素作为参数 (x
根据命令可知)NSBezierPath
上调用匹配方法如果字符串很长,您也可以通过按流解析它来执行相同的操作。
I don't think something like that is available.
But you should be able to parse that yourself very easily, since the commands map directly to
NSBezierPath
methods.It's also helpful that the command comes first, so you could do the following:
x
elements as parameters (x
is known depending on command)NSBezierPath
If the string is very long, you can also do the same by parsing it stream-wise.