1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 23:28:06 +02:00

Merge pull request #7341 from Snuffleupagus/getDestinationHash-Array

[api-minor] Improve handling of links that are using explicit destination arrays
This commit is contained in:
Tim van der Meij 2016-06-09 00:29:10 +02:00
commit f97d52182a
10 changed files with 201 additions and 44 deletions

View file

@ -268,8 +268,9 @@ describe('Annotation layer', function() {
var actionDict = new Dict();
actionDict.set('Type', Name.get('Action'));
actionDict.set('S', Name.get('GoToR'));
actionDict.set('F', '../../0021/002156/215675E.pdf');
actionDict.set('D', '15');
actionDict.set('F', '../../0013/001346/134685E.pdf');
actionDict.set('D', '4.3');
actionDict.set('NewWindow', true);
var annotationDict = new Dict();
annotationDict.set('Type', Name.get('Annot'));
@ -283,7 +284,58 @@ describe('Annotation layer', function() {
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
expect(data.url).toBeUndefined();
expect(data.url).toBeUndefined(); // ../../0013/001346/134685E.pdf#4.3
expect(data.dest).toBeUndefined();
expect(data.newWindow).toEqual(true);
});
it('should correctly parse a GoToR action, with named destination',
function() {
var actionDict = new Dict();
actionDict.set('Type', Name.get('Action'));
actionDict.set('S', Name.get('GoToR'));
actionDict.set('F', 'http://www.example.com/test.pdf');
actionDict.set('D', '15');
var annotationDict = new Dict();
annotationDict.set('Type', Name.get('Annot'));
annotationDict.set('Subtype', Name.get('Link'));
annotationDict.set('A', actionDict);
var xrefMock = new XrefMock([annotationDict]);
var annotationRef = new Ref(495, 0);
var annotation = annotationFactory.create(xrefMock, annotationRef);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
expect(data.url).toEqual('http://www.example.com/test.pdf#nameddest=15');
expect(data.dest).toBeUndefined();
expect(data.newWindow).toBeFalsy();
});
it('should correctly parse a GoToR action, with explicit destination array',
function() {
var actionDict = new Dict();
actionDict.set('Type', Name.get('Action'));
actionDict.set('S', Name.get('GoToR'));
actionDict.set('F', 'http://www.example.com/test.pdf');
actionDict.set('D', [14, Name.get('XYZ'), null, 298.043, null]);
var annotationDict = new Dict();
annotationDict.set('Type', Name.get('Annot'));
annotationDict.set('Subtype', Name.get('Link'));
annotationDict.set('A', actionDict);
var xrefMock = new XrefMock([annotationDict]);
var annotationRef = new Ref(489, 0);
var annotation = annotationFactory.create(xrefMock, annotationRef);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
expect(data.url).toEqual('http://www.example.com/test.pdf#' +
'[14,{"name":"XYZ"},null,298.043,null]');
expect(data.dest).toBeUndefined();
expect(data.newWindow).toBeFalsy();
});

View file

@ -360,6 +360,16 @@ describe('api', function() {
done.fail(reason);
});
});
it('gets invalid page index', function (done) {
var ref = { num: 3, gen: 0 }; // Reference to a font dictionary.
var promise = doc.getPageIndex(ref);
promise.then(function () {
done.fail('shall fail for invalid page reference.');
}, function (data) {
expect(data instanceof Error).toEqual(true);
done();
});
});
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();

View file

@ -1,5 +1,5 @@
/* globals expect, it, describe, beforeEach, Name, Dict, Ref, RefSet, Cmd,
jasmine, isDict */
jasmine, isDict, isRefsEqual */
'use strict';
@ -158,4 +158,18 @@ describe('primitives', function() {
expect(isDict(dict, 'Page')).toEqual(true);
});
});
describe('isRefsEqual', function () {
it('should handle different Refs pointing to the same object', function () {
var ref1 = new Ref(1, 0);
var ref2 = new Ref(1, 0);
expect(isRefsEqual(ref1, ref2)).toEqual(true);
});
it('should handle Refs pointing to different objects', function () {
var ref1 = new Ref(1, 0);
var ref2 = new Ref(2, 0);
expect(isRefsEqual(ref1, ref2)).toEqual(false);
});
});
});