Open Bug 1617039 Opened 5 years ago Updated 2 years ago

Implement conic-gradient for Cairo graphics backend (printing support)

Categories

(Core :: Graphics, enhancement, P5)

enhancement

Tracking

()

People

(Reporter: ntim, Unassigned)

References

Details

Attachments

(1 file, 2 obsolete files)

Cairo is used exclusively for printing.

According to jrmuizel, the easiest way to do this is to paint the gradient using a different backend then send the image over to Cairo for printing.

Priority: -- → P5

Markus, do you think you could provide a bit of guidance ? I'm not sure this is on the right path. Thanks!

Flags: needinfo?(mstange)

The approach is looking pretty good to me! The hard part is going to be the computation of the surface bounds, I think. Unless there's some "get current clip extents" helper around.

Flags: needinfo?(mstange)

Oh, actually, I think it would be best to handle the transform in Skia. For example, let's say you have a 50x50 DrawTargetCairo, set a scale(5) transform on it, and then draw a 10x10 user space conic gradient that should fill the entire DrawTarget. In that case, you'll get blurry rendering if you let Skia render the conic gradient into a 10x10 surface and then scale that surface up to 50x50. It's better if you make a surface of the device space bounds (50x50), pass the current transform to Skia, let Skia fill the 50x50 surface with the correct transform, turn that into a SurfacePattern with the inverse transform set on it, and then draw that SurfacePattern into the DrawTargetCairo so that it's drawn without any transform.

Type: task → enhancement
Assignee: nobody → mohamed
Attachment #9136219 - Attachment is obsolete: true
Assignee: mohamed → nobody
Summary: Implement conic-gradient for Cairo graphics backend → Implement conic-gradient for Cairo graphics backend (printing support)
Assignee: nobody → mohamed
Status: NEW → ASSIGNED
Attachment #9190463 - Attachment is obsolete: true
Assignee: mohamed → nobody
Status: ASSIGNED → NEW

Cairo can draw conic gradients using the mesh gradient API. See this test case for an example.

https://gitlab.freedesktop.org/cairo/cairo/-/blob/master/test/mesh-pattern-conical.c

This is preferable to embedding an image as it uses vector output on the PS/PDF output.

You just need to ensure there is at least one patch every 90 degrees to maintain a good approximation of a circle as described here.

https://stackoverflow.com/questions/1734745/how-to-create-circle-with-b%C3%A9zier-curves

FWIW, the WebKitGTK/WPE WebKit ports feature an implementation of conic gradients using Cairo as graphics backend. Perhaps that could be useful.

https://webkit-search.igalia.com/webkit/source/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: