mozilla/pdf.js — pull request #4533 by Snuffleupagus (2014-03-29 21:41:22+00:00)
Title: [WIP] Enforce minimum line widths and rectangle sizes

This PR contains experimental patches that enforce lower bounds on both line widths and rectangle sizes. I don't think this should be merged as is, but I wanted to submit the PR to get feedback. My apologies for the very long post!

Given that PDF.js currently renders some files with lines that are way to thin, in some cases becoming almost invisible, I think that we should replace too narrow line widths with more reasonable ones.
Comparing PDF.js with Adobe Reader, it seems that they enforce minimum line widths. This would explain why there are a number of bugs filed about missing lines PDF.js. (See below for an incomplete list.)

The obvious candidate to use when establishing a minimum line width should be [`getSinglePixelWidth`](https://github.com/mozilla/pdf.js/blob/master/src/display/canvas.js#L2191). Unfortunately, in my testing, using that value causes many lines to become *way* too thick.
Through some trial and error, I found that reducing the value returned by `getSinglePixelWidth` to `0.75 * getSinglePixelWidth` seemed to yield *much* better results. Obviously, this seems like a ugly hack, but I don't really understand why `getSinglePixelWidth` isn't returning more reasonable values.
It then occurred to me that `0.75 = 1 / CSS_UNITS`, where `CSS_UNITS = 96.0 /72.0` (see [viewer.js#L31](https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L31)). Is this just a coincidence, or could it explain the issues I had with the values returned by `getSinglePixelWidth`?

As this PR currently stands, it would fix issues like: #4314, #3316 and #2722, and it would also prevent any future issues with lines getting drawn too thin.

Please note that if we, as suggested in this PR, start to enforce minimum line widths (and rectangle sizes) this obviously means that a fair number of the test PDFs would change. These changes would fall in two general categories:
* Changes that are so small that they are virtually indistinguishable to the naked eye.

* Changes that are easily noticeable. In most of these cases, the slightly thicker lines looks a lot better (to me, at least) and the rendering in PDF.js is now very close to the one in Adobe Reader.
In a number of the test files, it's also possible to see details (in figures) that currently are almost invisible.