哪个是最好的 SVG 到 NSBezierPath 库/类?

发布于 2024-12-08 04:57:23 字数 564 浏览 1 评论 0原文

我正在寻找最好的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮是我掰弯的 2024-12-15 04:57:23

编写一个程序,使用 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.

十六岁半 2024-12-15 04:57:23

我认为没有类似的东西可用。

但是您应该能够非常轻松地自己解析它,因为命令直接映射到 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:

  • split into array by spaces
  • take first element and map to command
  • take next x elements as parameters (x is known depending on command)
  • call the matching method on NSBezierPath

If the string is very long, you can also do the same by parsing it stream-wise.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文