Re: [svgwg] Relax SVG Path grammar with an implicite first MoveTo command (#780)

After re-reading this discussion, I actually changed my mind and like many of the ideas proposed here (just not worded like in the original post).

@JeremiePat makes really good points about formally defining the concept of path fragments, and in fact @tatarize also gives examples of the usefulness of such path fragments. Once we have such concept, we can indeed use it to concatecate/reuse path fragments, either programatically or as allowed path data syntax, which is powerful. There is in fact a precedent: the SuperPath proposal, where Jean-Claude Moissinac proposes the concept of a "chunk", which is exactly what we're naming "path fragment" here. See:

- http://moissinac.github.io/SuperPath/
- https://github.com/moissinac/SuperPath
- https://github.com/moissinac/SuperPath/wiki/In-progress-new-implementation-of-SuperPath
- https://hal.archives-ouvertes.fr/hal-01793944/file/SuperPathSVGOpen.pdf

> ### definition of a chunk:
> in a data-sp-d attribute of a path, where you want in the path (after the begining m or M) starts with ( and ends with ); following the starting ( is an id for the chunk followed by | and then followed by some commands which defines the chunk, then the terminating ); a chunk definition must always be followed by an explicit command; the sequence of command of the chunk is always translated in relative mode
> 
> ```<path d="" data-sp-d="M425,25L225,25 225,225 425,225(p1|L425,225L425,175Q525,125 425,75L425,25)" style="fill:#0000FF" />```
> 
> ### direct usage of a chunk:
> In data-sp-d, a reference to a chunk starts with "#" and ends with "|". Following the starting "#" is the id of the referenced chunk terminated by "|". A chunk reference is replaced by the sequence of commands associated with the id.
> 
> ```<path d="" data-sp-d="M425,225#p1|" style="stroke:#FF0000;fill:none;stroke-width:3" />```
> 
> ### reverse usage of a chunk:
> In a path, a reference to a chunk used in reverse order (from the end to the beginning) starts with "!" and ends with "|". Following the starting "!" is the id of the referenced chunk terminated by "|". The chunk reference is replaced by a sequence of commands that produce the same geometry as the sequence of commands associated with the id, but drawn from the end to the beginning.
> 
> ```<path d="" data-sp-d="M425,25!p1|L425,225 625,225 625,25 425,25" style="fill:#00FFFF" />```

This whole SuperPath proposal is obviously a big change. But as a first step, I agree with @JeremiePat that we could already define the concept of valid path fragment (= same as the current valid path but without the required initial moveto), and then either:
1. Define a valid path as a path fragment starting with a MoveTo, or
2. Define a valid path as any sequence of path fragments. *If the path has at least one command and the first command isn't a MoveTo*, then an implicit `M 0,0` is added.

Note that the implicit initial MoveTo would only apply when rendering full paths or their markers. It does not apply to individual path fragments. This change is backward compatible, since it only affects paths which were invalid before the change.

Note the importance of the wording "if the path has at least one command and the first command isn't a MoveTo". Indeed, we don't want to implicitly convert `d=""` to `d="M 0,0"` (an empty path should stay empty, otherwise a marker would appear), and we don't want  implicitly convert `d="M 1,1 L 2,2"` to `d="M 0,0 M 1,1 L 2,2"` (again, this would add a marker). This wording is what ensures that only paths which were invalid syntax before are now rendered with well-defined behavior, and therefore ensures backward compatibility.

-- 
GitHub Notification of comment by dalboris
Please view or discuss this issue at https://github.com/w3c/svgwg/issues/780#issuecomment-668516051 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 4 August 2020 10:27:16 UTC