Commit 78840bb7 authored by Thomas Fischer's avatar Thomas Fischer Committed by Albert Astals Cid

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.
parent 36bc1703
......@@ -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");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment