ssimms / pdfapi2

Create, modify, and examine PDF files in Perl
Other
15 stars 20 forks source link

Dimensions are rounded to two decimal points #67

Closed sasozivanovic closed 1 year ago

sasozivanovic commented 1 year ago

I'm using PDF::API2 in a script accompanying a TeX package I have developed (Memoize, currently in the process of submission to CTAN). The purpose of the script is to extract selected pages from the PDF generated by TeX. As a paranoid measure, I'm comparing the expected page size to the size of MediaBox. (I know that TeX (pt) and PDF (bp) points are not the same, and I'm performing the conversion.) Some TeX engines (pdfTeX, LuaTeX) can set the number of decimal points used in PDF dimensions (using \pdfdecimaldigits or \pdfvariable decimaldigits). However, when PDF::API2 reads the dimensions with more than two decimal digits, it rounds them down to two. Could this be remedied, or is there a deeper reason for this behaviour?

ssimms commented 1 year ago

PDF::API2 limits the number of decimal places so that its tests work properly across multiple architectures. Before it did this, one architecture might stop after ten decimals while another would include sixteen, resulting in different PDFs being generated during tests.

The rounding that PDF::API2 should be close enough for real-world usage (e.g. 0.01pt = 0.0035mm, and most of the rounding is to four or more decimal places rather than two).