Skip to content

Path stroke gradients do not work as expected #5647

Closed

Description

@johannes-wolf

Description

Tested with typst 0.12.0 (dhb06dbf9). On current master, drawing gradient strokes with path got fixed (with the new curve API): it is possible to stroke straight lines (angle 0deg) with a gradient now. But drawing the line flipped, does not flip the gradient (in contrast to line).

With line, the gradient gets reversed, if the end: is left of start:. Not sure if this is really a bug, or expected behaviour.

The following code:

#let red-blue = gradient.linear(red, blue, relative: "self")

// Ok
#path((0cm, 0cm), (5cm, 0cm), stroke: red-blue + 5pt)

// Expected blue to red gradient, got red to blue
#path((5cm, 0cm), (0cm, 0cm), stroke: red-blue + 5pt)

Results in this rendering:
grafik

Reproduction URL

No response

Operating system

Web app, Linux

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Jan 2, 2025
  2. added
    visualize
    on Jan 6, 2025
  3. gregzanch commented on Jan 10, 2025

    @gregzanch

    I'd like to take a stab at this!

    I think the a potential issue here is that the gradient is defined (which includes the angle of the gradient) and then the paths use the absolute angle of the gradient rather than relative to path definition.

    This may be a non issue but I'll still look into it.

  4. Dherse commented on Jan 10, 2025

    @Dherse
    Contributor

    Gradient along a path are likely among the hardest to support. In theory, you could create (in PDF) a function that goes from 0 to 1 and then interpolate at several points along the path to get it working nicely, but it's tricky.

  5. gregzanch commented on Jan 11, 2025

    @gregzanch

    Gradient along a path are likely among the hardest to support. In theory, you could create (in PDF) a function that goes from 0 to 1 and then interpolate at several points along the path to get it working nicely, but it's tricky.

    Could it be a worth while feature to consider? I'm not fully versed on the architecture, but maybe there could be a parameter/stroke type that enables a gradient as described above.

    The gradient could be called something of the sort "perpendicular-path-gradient". This gradient would interpolate the full path length from 0-1, and then add sub gradients at each path vertex which aligns to the users specification.

    This is something way out of scope here, but maybe could be a feature in the future?

    For a solution here, we could write documentation that shows how gradients behave relative to path "orientation".

  6. Dherse commented on Jan 11, 2025

    @Dherse
    Contributor

    I think it would be a worthwhile feature to have. Just a fairly difficult one to implement. The problem is that doing "per-vertex" gradients would be a huge nono (file size) so you'd need to re-use one gradient (which is definitely doable of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugvisualize

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions