summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Fischer <fischer@unix-ag.uni-kl.de>2019-11-21 21:19:44 +0100
committerAlbert Astals Cid <tsdgeos@yahoo.es>2019-12-04 10:23:55 +0000
commit78840bb796384942a21f1d99de80cdaaafcd7f58 (patch)
tree215eba73c17e7a8f2b52ee4f705b198fdb65508e
parent36bc1703a7252f3c6f0a6059cd99419152b60a6f (diff)
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.
-rw-r--r--utils/pdfinfo.cc13
1 files changed, 8 insertions, 5 deletions
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 <erigas@rnd2.org>
// Copyright (C) 2019 Christian Persch <chpe@src.gnome.org>
// Copyright (C) 2019 Oliver Sander <oliver.sander@tu-dresden.de>
+// Copyright (C) 2019 Thomas Fischer <fischer@unix-ag.uni-kl.de>
//
// 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");