Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add svg-path API to support SVG-like path object #829

Open
liuguangxi opened this issue Mar 3, 2025 · 1 comment
Open

Add svg-path API to support SVG-like path object #829

liuguangxi opened this issue Mar 3, 2025 · 1 comment
Assignees

Comments

@liuguangxi
Copy link

liuguangxi commented Mar 3, 2025

With the introduction of curve in Typst 0.13, it's now possible to construct a path primitive with fully functional.

It would be nice to have a draw function that corresponds to the SVG path.

For example, consider the following SVG path:

<path d="M 10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80 Z" stroke="black" fill="transparent"/>

It could be implemented using svg-path as below:

svg-path(
    stroke: black, fill: none,
    ("M", (10, 80)),
    ("C", (40, 10), (65, 10), (95, 80)),
    ("S", (150, 150), (180, 80)),
    ("Z"),
)

The command in SVG path:

  • M/m = moveto
  • L/l = lineto
  • H/h = horizontal lineto
  • V/v = vertical lineto
  • C/c = curveto
  • S/s = smooth curveto
  • Q/q = quadratic Bézier curve
  • T/t = smooth quadratic Bézier curveto
  • A/a = elliptical arc
  • Z/z = closepath

where uppercase letters indicate absolute positioning, and lowercase letters indicate relative positioning.

Except the command A/a (elliptical arc), other command can be mapped directly to a curve element.

The advantage is that it is easy to construct complex path objects (manually or programmatically) concisely.

In addition, it is convenient to realize the automatic conversion of SVG path to CeTZ code (Maybe there will be a tool like SVG2CeTZ?).

@johannes-wolf johannes-wolf self-assigned this Mar 3, 2025
@johannes-wolf
Copy link
Member

The internal path representation of cetz has to be changed first, but this is a nice feature to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants