Clipping

Clipping is limiting fill, stroke a show to a region you have defined with a path. When you start a page, you can fill, stroke and show to the entire page. When you use the operator clip with a current path, this path is becoming the clipping path. If you use clip operator again, the intersection of the current clipping path becomes the new clipping path.

The clipping path is part of the current graphics state. So we have to add the clipping first to the context

Javascript Editor

The operator clip keeps an arrow of paths in the graphics state so it can always provide the current clipping paths.

Javascript Editor

The scanFill algorithm is extended to use a clip region

Javascript Editor

On the raw device, we keep a clipping. Whenever we fill or stroke, we check if the clipping path has changed and if yes, we calculate a transfer layer for the clipping.

Javascript Editor

And add it for the other devices. In Canvas and PDF we wrap the clipping in gsave - restore. We need to do this for every stroke, fill and show operation, which may be expensive depending how it is implemented. We do not know. In SVG, the paths are separate and referenced.

Javascript Editor

We test with the exercice. We add a text at the end to make sure that it is not clipped.

Javascript Editor

A vector drawing inside letters. This one is slower.

Javascript Editor

ps20241119.js 3691 lines 133 KB

My Journey to PostScript