JaggiesAfter a PDF document is rasterized, why do we see jaggies around lines?
The answer starts with a bit of theory on the coordinates: In a PDF document these coordinates denotes a positions on a plane using a X and an Y axis. These positions uses floating point numbers which result in the ability to point to any location, not only at the grid lines but also anywhere in between.
So how exactly are the floating point coordinates mapped to the pixels then?
If we forget about the transformations for a moment, the definition is as follows: "Pixel boundaries always fall on integer coordinates in device space. A pixel is a square region identified by the location of its corner with minimum horizontal and vertical coordinates. The region is half-open, meaning that it includes its lower but not its upper boundaries " In other words: it looks like this:
What happens if we draw a black vertical line with a width of 1 pixel wide positioned exactly at the PDF coordinates (2, 1) to (2,6)?
The jaggiesThe jaggies will become visible if the PDF is rendered to a black and white bitmap, e.g. for a printed page. It is not possible to use gray values then so dithering has to be used instead like:
Why do this dithering instead of moving the line half a pixel?The question is: Is this dithering really what we want or can we do something better here? it is clear that there is a decision to be made here on what is most important:
- Either the rasterizer tries to approach the exact position of the lines by means of dithering,
- or it rounds the position of the line to the nearest pixel.
The answer:The reason that we have chosen in our implementation for these jaggies (is dithering) is that we believe that it results in better readability because:
- we think that unintended variations in location and thickness are more noticeable than jaggies.
- the dithering is supposed to be performed at such resolution that the individual pixels are indistinguishable, so you would not see it in normal situations.
Therefore the answer is: we do dithering as it gives the appearance of sub-pixel precision at the cost of strange pixels, which you will only see if you zoom in too much.