Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destination with index #133

Merged
merged 10 commits into from
Sep 12, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class Destination extends Dictionary {
// Reference object for destination
private Reference ref;

// type, /XYZ, /Fit, /FitH...
// type, /XYZ, /Fit, /FitH...
private Name type;

// Specified by /XYZ in the core, /(left)(top)(zoom)
Expand Down Expand Up @@ -236,6 +236,13 @@ private void parse(List v) {
Object ob = getDestValue(0, v);
if (ob instanceof Reference) {
ref = (Reference) ob;
} else if (ob instanceof Integer) {
Copy link
Owner

@pcorless pcorless Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably suggest somthing like, not point keeping the pageTree reference around:

// Dest could be a page number instead of a reference
final int idx = (int) ob;
PageTree pageTree = library.getCatalog().getPageTree();
if (idx >= 0 && idx < pageTree.getNumberOfPages()) {
ref = pageTree.getPageReference(idx);
}

Interstingly this is one of those special corners cases were the notion isn't in the specification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I was tired, I was assuming we didn't have access to library in this object for some reason...
Thanks for pointing that out.
Yeah I found that quite strange, I don't know how that pdf got created.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries and thank you for providing the fix!

//Dest could be a page number instead of a reference
final PageTree pt = library.getCatalog().getPageTree();
final int idx = (int) ob;
if (idx >= 0 && idx < pt.getNumberOfPages()) {
ref = pt.getPageReference(idx);
}
}
// store type.
ob = getDestValue(1, v);
Expand Down