svg - SVG path data format differences
问题描述
I'm working on a project where I need to parse svg path data.
Right now we're loading an svg, looking for the path
tag, and pulling out it's d
attribute.
For some of the artwork we'll get path data that is made up of coordinates which we can translate into the data types we need. E.g.
But other times the d
value is in a more g-code-esq format.
Like in this case I drew a rectangle, converted it to a compound path:
And when I export it and look at the svg I get a d
value like this:
Which we can't easily parse for the project.
My questions are:
- How do I read this second format? It doesn't seem to fit what I'm reading on MDN so I suspect there's some other documentation I need to refer to: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
- For illustrator users, is there a way of changing the format when exporting?
I know that this seems like more of an art question than a programming question, but I'm trying to understand the underlying reasoning behind the svg data structure so I can better parse it.
解决方案
Oh! Oh ok, I was 100% misunderstanding the path data that I was reading. I didn't realize that the delimiting information was based on the letter. My brain wanted some specific character as a delimiter like a comma or pipe.
So reading (and in some cases re-reading :| ) the documentation, when I see:
M753,315H435.27V165H753Z
I can read that as:
M753,315
Move to x,y coordinatesx: 753 y:315
H435.27
Starting at the current location, draw a horizontal line to the absolutex
coordinate of435.27
V165
Starting at the current location, draw a vertical line to the absolutey
coordinate of165
H753
Starting at the current location, draw a horizontal line to the absolutex
coordinate of753
Z
Draw a straight line to the initial point of this path to close the path. This doesn't necessarily mean a horizontal or vertical line, but the coincidence that we're at the samex
coordinate that we started at means that if we draw a straight line we will get a vertical line to complete the rectangle
That seems right. Anything I missed or misunderstood?
Also, thank for all of the links. I appreciate the points :clap: :bows:
推荐阅读
- node.js - Azure 应用服务与节点进程管理器中断,但适用于节点
- css - 输入为带有 -webkit-appearance 的多行 TEXTAREA
- alibaba-cloud - 阿里巴巴 ECS 实例卡在“待启动”状态
- devexpress - 两个摘要结果的差异 null
- go - dynamodbattribute.UnmarshalMap 将我的变量类型转换为 map[string]interface{}
- android - 具有多个清单的 Android 项目
- cassandra - 我有单个集群 2 节点数据中心,在进行复制测试时,我关闭了 1 个节点,然后通过运行 nodetool status 命令出现错误
- sublimetext3 - 如何在 sublime text 3 中打开我们的本地程序(npptfp)?
- r - 自动化 ggplot2 的 qplot
- c# - 将 JSON 匹配到 C# 类,坐标结构