Repository navigation
Add support for cliping content in block and box - #431
Conversation
|
The reason why this doesn't exist yet is because the text and SVG clipping in the renderer doesn't work correctly, yet. |
|
I assume that is the image renderer then? Both text and svg seems to work fine for me in the pdf renderer (where I assume you use native pdf clipping constructs?) |
|
Exactly. |
|
Okay, I am looking at the image rendering code now. It doesn't seem unreasonably difficult (but with a few small challenges) to add clipping there. I will try to see if I am able to implement something during the day. |
|
One Problem is that resvg doesn't take a clip mask and another is that tiny-skia's clip mask data is private and we need it to correctly render clipped glyphs. |
|
Too me it looks like |
|
Rendering normal glyphs onto a pixmap first has a significant performance overhead, unfortunately. It might also cause problems with transformations (which SVG images already have). |
|
So I have implemented what I talked about now. The outline rendering code should have almost identical results to the previous code, except for some (very small) differences in alpha blending. For svg glyphs I had a lot of problems determining a good pixmap size. I ended on a solution where I use the same heuristic as in the outline rendering to see if the transform is very complicated and in that case render to a full sized pixmap. If not then I render to a pixmap with width and height of In order for tests to pass I needed to change the following line to Line 403 in 4d9c6b2 Unfortunately the performance regression was much worse than I would have expected, the following is only rendering outlines to pixmaps (compared to main branch): However on the other hand there are a lot fewer L2 accesses when rendering svg glyphs to pixmaps, probably because it we render to small buffer rather than the whole page. This is just rendering svg glyphs to a pixmap compared to the main branch: This is both changes compared to the main branch: For my case I am more or less only interested in PDF rendering and clipping is very important for me so I would prefer adding this change even if it reduces performance in the image renderer. But of course you decide what tradeoffs you consider more important. In the long term it is of course always possible to try to get a patch into |
|
The problem is that the image renderer is used by our web app. (Long-term we want to build a GPU-accelerated one, but we haven't yet.) As rendering is already relatively slow, a 50% slowdown is just too much. The slowdown mostly comes from rendering normal glyphs, I assume. How about using the old code if there is no clip mask and the new one only if there is one? Or just trying to get a patch into tiny-skia, that would probably be the best option. RazrFalcon is pretty responsive in my experience, also with version bumps. |
|
Checking for a clip mask seems like a good start. Presumably for current documents the clipmask will mostly be unset so you won't really notice any difference. This is when performance when checking for clipmask compared to main, unsurprisingly the numbers look similar as for the version that just clips svg glyphs, probably the clipmask is never set in the benchmark: Could this be an acceptable tradeoff? For now it shouldn't affect performance too much and it is still possible to have a longer-term plan of adding a patch to tiny-skia in order to improve performance for the cases when a clipmask is set. Of course this PR needs a bit more work before it can be considered usable. The svg glyph rendering needs some more scrutiny and we also need to add some tests that include clipping. |
|
This is a good tradeoff, I think. I'm excited to see clipping support! |
|
Generally, it would be nice if strokes weren't always center strokes. Maybe inside would be a better default. But that's a separate issue. This is very nice! |
|
I don't think the stroke issue is blocking. Tell me if you think this is ready to be merged. |
|
I just did a tiny commit, but now I think it should be ready for merging now if you think everything looks good. |


This PR tries to fix #429 by adding a
clipargument toblockandbox. From my very limited it seems to work fine, however I am not entirely updated on the internals of these elements work and also how the frame element works so there might be some cases that are not handled in the best way, like:inset?