utils/pdfinfo.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
New commits: commit 78840bb796384942a21f1d99de80cdaaafcd7f58 Author: Thomas Fischer <[email protected]> Date: Thu Nov 21 21:19:44 2019 +0100 pdfinfo: improved paper size recognition Paper sizes of ISO 216, A Series were originally defined in millimeters. For example, A3 is defined to be 297mm x 420mm. However, depending on source, the corresponding size in pts may vary between 1190pt and 1191pt for the longer edge. pdfinfo's formula to compute the length of the longer edge of an A3 paper determines this length to be 1191.82pt. As the error margin so far was set to 1pt, A3 papers with edge length of 1190.8pt were not recognized as A3. This patch makes the error margin depending on the paper size, setting it at 0.3% of the longer edge's length. For A3 paper, the error marging (variable 'isoThreshold') thus becomes 3.58pt. Accordingly, the threshold for 'letter' paper has been raised from 0.1pt to 1pt. diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc index 7890a75b..59e812a4 100644 --- a/utils/pdfinfo.cc +++ b/utils/pdfinfo.cc @@ -27,6 +27,7 @@ // Copyright (C) 2018 Evangelos Rigas <[email protected]> // Copyright (C) 2019 Christian Persch <[email protected]> // Copyright (C) 2019 Oliver Sander <[email protected]> +// Copyright (C) 2019 Thomas Fischer <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -665,7 +666,7 @@ static void printPdfSubtype(PDFDoc *doc, UnicodeMap *uMap) { static void printInfo(PDFDoc *doc, UnicodeMap *uMap, long long filesize, bool multiPage) { Page *page; char buf[256]; - double w, h, wISO, hISO; + double w, h, wISO, hISO, isoThreshold; int pg, i; int r; @@ -767,20 +768,22 @@ static void printInfo(PDFDoc *doc, UnicodeMap *uMap, long long filesize, bool mu } else { printf("Page size: %g x %g pts", w, h); } - if ((fabs(w - 612) < 0.1 && fabs(h - 792) < 0.1) || - (fabs(w - 792) < 0.1 && fabs(h - 612) < 0.1)) { + if ((fabs(w - 612) < 1 && fabs(h - 792) < 1) || + (fabs(w - 792) < 1 && fabs(h - 612) < 1)) { printf(" (letter)"); } else { hISO = sqrt(sqrt(2.0)) * 7200 / 2.54; wISO = hISO / sqrt(2.0); + isoThreshold = hISO * 0.003; ///< allow for 0.3% error when guessing conformance to ISO 216, A series for (i = 0; i <= 6; ++i) { - if ((fabs(w - wISO) < 1 && fabs(h - hISO) < 1) || - (fabs(w - hISO) < 1 && fabs(h - wISO) < 1)) { + if ((fabs(w - wISO) < isoThreshold && fabs(h - hISO) < isoThreshold) || + (fabs(w - hISO) < isoThreshold && fabs(h - wISO) < isoThreshold)) { printf(" (A%d)", i); break; } hISO = wISO; wISO /= sqrt(2.0); + isoThreshold /= sqrt(2.0); } } printf("\n"); _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
