Skip to content

Add support for more complex strokes - #505

Merged
laurmaedje merged 7 commits into
typst:mainfrom
birktj:new-stroke
Apr 13, 2023
Merged

laurmaedje merged 7 commits into
typst:mainfrom
birktj:new-stroke

Conversation

@birktj

@birktj birktj commented Apr 1, 2023 •

Copy link
Copy Markdown
Contributor

This patch adds more complex stroking, specifically it adds:

  • Line caps (butt, round, square)
  • Line joins (miter, round, bevel)
  • Dash patterns

A couple of questions that needs answering before this is ready:

  • I couldn't find a way to compile the documentation so I don't really know if the extra text on the stroke parameter of line and rect looks ok.
  • Since stroke can be a dictionary now, I had to modify the Cast impl of Sides in a way that results in not so good error messages. That is, you won't get any error about the valid fields of Sides, only it's internal type: in this case stroke.
  • Currently there are some dash patterns that will give different results when rendering to image and pdf (dash arrays with only one element)

Related to #260

@laurmaedje

Copy link
Copy Markdown
Member

Awesome, I'll take a closer look later, but I like it!

@ollelogdahl

Copy link
Copy Markdown
Contributor

Coolio! I am currently working on gradients/filling patterns on ALL paint objects. Stuff is starting to come together!

@birktj

birktj commented Apr 1, 2023

Copy link
Copy Markdown
Contributor Author

Hmm, maybe I should rename color to paint then

Comment thread library/src/visualize/line.rs Resolved
Comment thread library/src/visualize/shape.rs Resolved
Comment thread src/export/pdf/page.rs Resolved
Comment thread src/export/pdf/page.rs Resolved
Comment thread src/export/render.rs Resolved
Comment thread src/geom/stroke.rs Resolved
Comment thread src/geom/stroke.rs Resolved
Comment thread src/geom/stroke.rs Resolved
Comment thread src/geom/stroke.rs Resolved
Comment thread src/geom/stroke.rs Resolved
@birktj

birktj commented Apr 1, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for your feedback! I will be away for a couple of days now, but when I get back I will go through your suggestions.

@birktj

birktj commented Apr 7, 2023

Copy link
Copy Markdown
Contributor Author

I have incorporated your suggestions now and also updated the Debug impl for PartialStroke. I also rebased ontop of latest main in order to fix a failing test and update the stroke documentation for polygon.

@ollelogdahl

Copy link
Copy Markdown
Contributor

Hey, would you mind having a bit of a discussion over at discord? (my handle is Gaffa#4308). I have communicated with reiknh, and have partially implemented gradients for filling. I think line caps and line joins are great as a separate commit, but i think dash-patterns is a special case of a pattern applied along a line. The issue is here #443, but I think most can be discussed over discord if you have the time.

Right now there is no implementation of patterns, but when that comes I think the dash-patterns will be made using that.

@laurmaedje

Copy link
Copy Markdown
Member

Did you two discuss on Discord and, if so, what was the result?

@birktj

birktj commented Apr 11, 2023

Copy link
Copy Markdown
Contributor Author

Just a little bit. My understanding is that patterns along paths is quite far away atm so I don't think there is too much point in waiting for this. I also think that anyways it is nice to utilize PDF's native support for dash patterns which would probably be more efficient (in document size terms). Finally I think that having simple support for dash patterns in the public API is important even if they are implemented in a different way, and there should be nothing in the way of changing the underlying implementation in the future.

Comment thread src/geom/stroke.rs Resolved
Comment thread src/geom/stroke.rs Resolved
@laurmaedje
laurmaedje merged commit d1cd814 into typst:main Apr 13, 2023
@laurmaedje

Copy link
Copy Markdown
Member

Thanks!

Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
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

Successfully merging this pull request may close these issues.

3 participants