Subset of (pdf.js/438e3c8f6d2bd5a: Fixes for subtile bugs).
Merge pull request #16 from yurydelendik/clamp

Subset of (pdf.js/438e3c8f6d2bd5a: Fixes for subtile bugs).