Skip to content

Add tiny_skia/pixmap backend#23

Merged
KenyC merged 8 commits intoKenyC:mainfrom
lnay:tinyskia
Jul 6, 2025
Merged

Add tiny_skia/pixmap backend#23
KenyC merged 8 commits intoKenyC:mainfrom
lnay:tinyskia

Conversation

@lnay
Copy link

@lnay lnay commented Jul 3, 2025

This is a work in progress for adding an extra rendering backend tiny_skia from the linebender organisation (I'll make sure to implement the traits properly and integrate into the existing tests instead of the temporary one I added).

This is just to make sure you are happy to include this in the crate, or if you think this should live in a separate one.

@KenyC
Copy link
Owner

KenyC commented Jul 3, 2025

Wonderful, thank you so much!

  • This should definitely live in this crate!
  • I will take a thorough look later this week but I think this is correctly implemented. At first glance, the only thing that maybe needs fixing are the #[cfg(...)] configuration checks inside tinyskia.rs ; they should guard on ...-fontparser features not tinyskia-render (which would be redundant with the module configuration check).
  • I am ashamed to say that while there are (regression) rendering tests using the raqote backend, each backend is not tested individually at the moment (because they render to different things, because I don't know how to automatically compare vector images to a ground truth, etc) ! My unfortunate method so far has been to render an image manually and inspect it myself visually. But since tiny-skia renders to a raster image in your code, it could in principle be integrated to the render regression tests. That requires a lot more code! But you don't need to worry about that if you don't want to, I'll try to think of something less ad hoc when I review your code.

@lnay
Copy link
Author

lnay commented Jul 3, 2025

The font-rs test in the file I added only works if the "cff" feature is added to the font crate (it appears to be necessary for all the otf files in this repo).

Here's a little screenshot (firamath+font-rs+debug and xits+ttf-parser):
image

It's basically complete apart from whatever you decide should be done with tests.

@lnay lnay marked this pull request as ready for review July 3, 2025 17:35
Copy link
Owner

@KenyC KenyC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the PR again! There is a couple of things I would change about the backend interface and definition before merging, as commented below.

Let me know if you want to do the changes. If this is too much work, I can take things from here.

I just pushed a commit for stroking bboxes to your branch.

@lnay
Copy link
Author

lnay commented Jul 5, 2025

I'm happy to do these. As an aside to let you know my motivation looking at this project: I've been thinking about LaTeX in markdown rendering in the Zed editor (a currently missing feature). I was originally intending to try rendering to a tiny_skia pixmap (because that's how they render SVGs), but I've also found you can use their 'gpui' backend more directly with this crate.

I've made a demo here: https://github.com/lnay/latex-gpui-experiment in the hopes that the Zed team will have a look at adding this feature.

@lnay
Copy link
Author

lnay commented Jul 5, 2025

The last thing I noticed was that I left some unwraps in non-test code, I'll leave that up to you to decide if they should stay since it looks like there are unwraps in other backends too.

@KenyC
Copy link
Owner

KenyC commented Jul 6, 2025

Ok it looks like it's ready to merge. There is some weird difference between font-rs and ttfparser: the two renders are not the same size but this is something to investigate later.

The last thing I noticed was that I left some unwraps in non-test code, I'll leave that up to you to decide if they should stay since it looks like there are unwraps in other backends too.

Yes, that's not optimal, you're right! The failure of the unwrap would only happen if the font used for the layout and the font used for the render were different. Perhaps, it would be better to simply not draw anything if a glyph is missing. But this is a change we should do across backends.

I did push a change to eliminate one of the unwrap's you had.

I'm happy to do these. As an aside to let you know my motivation looking at this project: I've been thinking about LaTeX in markdown rendering in the Zed editor (a currently missing feature). I was originally intending to try rendering to a tiny_skia pixmap (because that's how they render SVGs), but I've also found you can use their 'gpui' backend more directly with this crate.

I've made a demo here: https://github.com/lnay/latex-gpui-experiment in the hopes that the Zed team will have a look at adding this feature.

That is great! Real-time rendering of LaTeX formulas is indeed what I had in mind for ReX. The main application is maths-preview, which I use as a plugin for LibreOffice Write.
Let me know if you need help with using ReX or encounter any friction points (which you can report as issues).

@KenyC KenyC merged commit c8cf9d6 into KenyC:main Jul 6, 2025
@lnay
Copy link
Author

lnay commented Jul 6, 2025

Real-time rendering of LaTeX formulas is indeed what I had in mind for ReX. The main application is maths-preview, which I use as a plugin for LibreOffice Write.

Didn't know that existed, I had been using the TexMaths extension before. I will try this out at some point!

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.

2 participants