Ref: https://savannah.gnu.org/bugs/index.php?55107
On 01/10/2021 01:10, Deri wrote: > I did try to help Keith with this previously, but I was mildly "told > off" (on list) for sending my help off list. I've learned my lesson. Thanks, Deri. IIRC, the reason for the "mild telling off" was that, by replying off list, you denied us the potential benefit from other list members who may have been willing to review the issue, and so contribute to the debugging effort. I am pleased that, on this occasion, you have kept this on-list; even if the majority of list members aren't sufficiently interested to assist, there may be some who will, and any assistance will be gratefully accepted, and very much appreciated. > I attach a couple of pdfs with which the current code has problems. > > Picture.pdf > > [derij@pip groff-psbb]$ ./psbb ../../Picture.pdf > ../../Picture.pdf: bounding box = (0,0)..(0,0) This is caused by the nested /Group dictionary, within the /Page object; the current groff-psbb lexer is confused by it, and ends up in the wrong state, when it eventually encounters the /MediaBox key. Adding one more rule (for "<<") to the PDF dictionary state scanning model gets us to: $ ./psbb Picture.pdf Picture.pdf: bounding box = (0,0)..(592,842) > [derij@pip groff-psbb]$ pdfbb ../../Picture.pdf > Processing '../../Picture.pdf' > ../../Picture.pdf: CropBox: 162.085,623.346,340.825,716.546 (178.74,93.2) The psbb lexer doesn't handle the /CropBox key. Should it? Should /CropBox override any extant /MediaBox? > croptest.pdf > > [derij@pip groff-psbb]$ ./psbb ../../croptest.pdf > psbb:t-psbb (t-psbb.cpp):193: PDF file '../../croptest.pdf' is > malformed; no trailer found Since croptest.pdf lacks both a trailer dictionary, and a free-standing cross reference table, (both are hidden away within a /XRefStm object, with a compressed cross reference table), croptest.pdf is _incompatible_ with applications which do not support this feature of PDF-1.5 (and later). The groff-psbb prototype implementation (currently) does not offer this level of PDF-1.5 support; thus, this behaviour is expected. > [derij@pip groff-psbb]$ pdfbb ../../croptest.pdf > Processing '../../croptest.pdf' > ../../croptest.pdf: MediaBox: 0,0,595,842 (595,842) Well, this agrees with the result I've shown above, for Picture.pdf, with groff-psbb modified to properly handle nested dictionaries; some further (non-trivial) development effort will be required, to support concealment of trailer dictionaries and cross reference tables within /XRefStm objects. -- Keith