Oversampling

The rendering of the fonts is very difficult in low resolution we are working. The screen is 72 pixels per inch or 96 pixels per inch, this is less than the quality of a fax. Printers are 300 or 600 DPI (dots per inch), photo setting is even 1500 DPI. Adobe uses some hints to display fonts properly with low resolutions, but must problems go away with more resolution.

What we can do here, is oversampling. For each pixel of the canvas, we calculate multiple pixels and then reduce the size of the result.

To enable oversampling, we need to adapt our code. First we create an operator setpagedevice. This operator gives information on the output device in form of a dictionary. It will pass many values to the output device in later chapters, for now it's just the key /oversampling. Note that setpagedevice is a standard PostScript operator but the content of the dictionary is not.

To apply the oversampling, we need to adapt rpnContext, scannFill and postScriptEditor. There is a new device dictonary in rpnContext with the oversampling value with default 1. Scannfill will scale the x, y, width and height values. And postScriptEditor will provide a larger ImageData object and we need also an offscreen Canvas to scale the image (two steps).

Javascript Editor

This is the text without oversampling.

Javascript Editor

This one is with oversampling 2.

Javascript Editor

And this one is with oversampling 4.

Javascript Editor

The device has to be set before any drawing operators. Here is our justified text.

Javascript Editor

We have now 2115 lines ps20240829.js

My Journey to PostScript