Graphics.Clip irregular Regions

Yesterday in the Xojo Hangout the question came up if there is a way to use Graphics.Clip for example also for RoundRectangles or Oval. What for? The idea is to fill a certain shape with a gradient without having to create pictures with masks, because these result in very large file sizes when creating PDFs, for example, if the PDF document consists of a hundred pages etc. Does anyone have an idea, a way to do this natively with the Xojo framework?
So within a Graphics object I have access to all drawing operations of a certain rectangle. But I would like to use a RoundRectangle or an Oval instead of the rectangle:

Var gArea As Graphics = g.Clip(100, 100, 200, 200) ' looking for something like this Var gArea2 As Graphics = g.ClipRoundRectangle(100, 100, 200, 200, 10, 10) Var gArea3 As Graphics = g.ClipOval(100, 100, 200, 200) ' same for paths
As long as Xojo does not offer brush patterns to fill shapes with images/gradients, this would be my approach. I am looking for a cross-platform variant (macOS - CoreGraphics, Windows - Direct2D Graphics.SetClip(path), Linux - Cairo).

I think you will need to use pictures with masks.


For PDF the DynaPDFMBS class supports real clip masks based on a path which may include curves, circles or arcs.