Bug 707822 - Link destinations incorrectly created upon missing coordinate
Summary: Link destinations incorrectly created upon missing coordinate
Status: RESOLVED FIXED
Alias: None
Product: MuPDF
Classification: Unclassified
Component: mupdf (show other bugs)
Version: master
Hardware: PC Linux
: P2 normal
Assignee: Sebastian Rasmussen
URL: https://github.com/ArtifexSoftware/mu...
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-10 21:28 UTC by Sebastian Rasmussen
Modified: 2024-06-11 20:58 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Rasmussen 2024-06-10 21:28:31 UTC
mupdf.js has reported an issue where Link Destinations are not correctly created when one coordinate is left out.

let outlineItem = {
  title: 'demo',
  uri: doc.formatLinkURI({ page: 0, type: 'XYZ', y: 200, }),
  open: false,
}

console.log(outlineItem)
// { title: 'demo', uri: '#page=1&zoom=nan,nan,200', open: false }
// this looks ok

doc.outlineIterator().insert(outlineItem)
console.log(doc.outlineIterator().item())
// { title: 'demo', uri: '#page=1', open: false }
// x,y coordinates are lost unless both are set
Comment 1 Sebastian Rasmussen 2024-06-10 21:30:22 UTC
I have reproduce this in mutool run using a script:

var doc = Document.openDocument("doc.pdf");
print(doc);

var iter = doc.outlineIterator();
print(iter);


var dest = {
        page: 10,
        type: 'XYZ',
        y: 200,
};
print(dest);
var ourrll = doc.formatLinkURI(dest);
print(ourrll);
var item = {
        title: 'demo',
        uri: ourrll,
        open: false,
};
print(item);
var res = iter.insert(item);
print(res);

doc.save("out.pdf", "incremental");

res = null;
item = null;
ourrll = null;
dest = null;
iter = null;
doc = null;
gc();

After executing the script and looking at out.pdf:

$ mutool show out.pdf trailer.Root.Outlines.First
87 0 obj
<<
  /Parent 3 0 R
  /Title (demo)
  /Dest [ 71 0 R /XYZ null null null ]
>>
endobj
Comment 2 Sebastian Rasmussen 2024-06-10 21:56:25 UTC
Alright this clusters and pymupdfs well. Off to review, during which there are bound to be a few comments as my proposed code is not really nice. Maybe the fix should be _inside_ fz_transform_point_xy()?
Comment 3 Sebastian Rasmussen 2024-06-11 20:58:41 UTC
Indeed there was comments during review, thus this was fixed by

commit 352234290008fdf093b3c396f375fdef6de91121
Author: Robin Watts <Robin.Watts@artifex.com>
Date:   Tue Jun 11 09:15:49 2024 +0100

    Bug 707822: Take missing coordinates into account when creating link dest.
    
    Previously if either coordinate was NaN, then after transformation
    both coordinates would be NaN. But it is desired for given coordinates
    to be transformed while missing coordinates are kept at NaN.
    
    From an original patch by Sebastian.