mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge branch 'master' of git://github.com/mozilla/pdf.js.git into textlayout-ui
Conflicts: web/viewer.js
This commit is contained in:
commit
877e0f4159
24 changed files with 1648 additions and 131 deletions
2
test/pdfs/.gitignore
vendored
2
test/pdfs/.gitignore
vendored
|
@ -20,3 +20,5 @@
|
|||
!scan-bad.pdf
|
||||
!freeculture.pdf
|
||||
!issue918.pdf
|
||||
!smaskdim.pdf
|
||||
!type4psfunc.pdf
|
||||
|
|
BIN
test/pdfs/smaskdim.pdf
Executable file
BIN
test/pdfs/smaskdim.pdf
Executable file
Binary file not shown.
BIN
test/pdfs/type4psfunc.pdf
Executable file
BIN
test/pdfs/type4psfunc.pdf
Executable file
Binary file not shown.
|
@ -17,12 +17,13 @@
|
|||
"rounds": 1,
|
||||
"type": "load"
|
||||
},
|
||||
{ "id": "intelisa-load",
|
||||
{ "id": "intelisa-eq",
|
||||
"file": "pdfs/intelisa.pdf",
|
||||
"md5": "f5712097d29287a97f1278839814f682",
|
||||
"link": true,
|
||||
"pageLimit": 100,
|
||||
"rounds": 1,
|
||||
"type": "load"
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "pdfspec-load",
|
||||
"file": "pdfs/pdf.pdf",
|
||||
|
@ -361,5 +362,17 @@
|
|||
"rounds": 1,
|
||||
"link": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "smaskdim",
|
||||
"file": "pdfs/smaskdim.pdf",
|
||||
"md5": "de80aeca7cbf79940189fd34d59671ee",
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "type4psfunc",
|
||||
"file": "pdfs/type4psfunc.pdf",
|
||||
"md5": "7e6027a02ff78577f74dccdf84e37189",
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
}
|
||||
]
|
||||
|
|
225
test/unit/function_spec.js
Normal file
225
test/unit/function_spec.js
Normal file
|
@ -0,0 +1,225 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('function', function() {
|
||||
beforeEach(function() {
|
||||
this.addMatchers({
|
||||
toMatchArray: function(expected) {
|
||||
var actual = this.actual;
|
||||
if (actual.length != expected.length)
|
||||
return false;
|
||||
for (var i = 0; i < expected.length; i++) {
|
||||
var a = actual[i], b = expected[i];
|
||||
if (isArray(b)) {
|
||||
if (a.length != b.length)
|
||||
return false;
|
||||
for (var j = 0; j < a.length; j++) {
|
||||
var suba = a[j], subb = b[j];
|
||||
if (suba !== subb)
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (a !== b)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('PostScriptParser', function() {
|
||||
function parse(program) {
|
||||
var stream = new StringStream(program);
|
||||
var parser = new PostScriptParser(new PostScriptLexer(stream));
|
||||
return parser.parse();
|
||||
}
|
||||
it('parses empty programs', function() {
|
||||
var output = parse('{}');
|
||||
expect(output.length).toEqual(0);
|
||||
});
|
||||
it('parses positive numbers', function() {
|
||||
var number = 999;
|
||||
var program = parse('{ ' + number + ' }');
|
||||
var expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses negative numbers', function() {
|
||||
var number = -999;
|
||||
var program = parse('{ ' + number + ' }');
|
||||
var expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses negative floats', function() {
|
||||
var number = 3.3;
|
||||
var program = parse('{ ' + number + ' }');
|
||||
var expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses operators', function() {
|
||||
var program = parse('{ sub }');
|
||||
var expectedProgram = ['sub'];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses if statements', function() {
|
||||
var program = parse('{ { 99 } if }');
|
||||
var expectedProgram = [3, 'jz', 99];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses ifelse statements', function() {
|
||||
var program = parse('{ { 99 } { 44 } ifelse }');
|
||||
var expectedProgram = [5, 'jz', 99, 6, 'j', 44];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('handles missing brackets', function() {
|
||||
expect(function() { parse('{'); }).toThrow(
|
||||
new Error('Unexpected symbol: found undefined expected 1.'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('PostScriptEvaluator', function() {
|
||||
function evaluate(program) {
|
||||
var stream = new StringStream(program);
|
||||
var parser = new PostScriptParser(new PostScriptLexer(stream));
|
||||
var code = parser.parse();
|
||||
var evaluator = new PostScriptEvaluator(code);
|
||||
var output = evaluator.execute();
|
||||
return output;
|
||||
}
|
||||
|
||||
it('pushes stack', function() {
|
||||
var stack = evaluate('{ 99 }');
|
||||
var expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles if with true', function() {
|
||||
var stack = evaluate('{ 1 {99} if }');
|
||||
var expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles if with false', function() {
|
||||
var stack = evaluate('{ 0 {99} if }');
|
||||
var expectedStack = [];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles ifelse with true', function() {
|
||||
var stack = evaluate('{ 1 {99} {77} ifelse }');
|
||||
var expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles ifelse with false', function() {
|
||||
var stack = evaluate('{ 0 {99} {77} ifelse }');
|
||||
var expectedStack = [77];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles nested if', function() {
|
||||
var stack = evaluate('{ 1 {1 {77} if} if }');
|
||||
var expectedStack = [77];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
|
||||
it('abs', function() {
|
||||
var stack = evaluate('{ -2 abs }');
|
||||
var expectedStack = [2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('adds', function() {
|
||||
var stack = evaluate('{ 1 2 add }');
|
||||
var expectedStack = [3];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('boolean ands', function() {
|
||||
var stack = evaluate('{ true false and }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('bitwise ands', function() {
|
||||
var stack = evaluate('{ 254 1 and }');
|
||||
var expectedStack = [254 & 1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
// TODO atan
|
||||
// TODO bitshift
|
||||
// TODO ceiling
|
||||
// TODO copy
|
||||
// TODO cos
|
||||
it('converts to int', function() {
|
||||
var stack = evaluate('{ 9.9 cvi }');
|
||||
var expectedStack = [9];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('converts negatives to int', function() {
|
||||
var stack = evaluate('{ -9.9 cvi }');
|
||||
var expectedStack = [-9];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
// TODO cvr
|
||||
// TODO div
|
||||
it('duplicates', function() {
|
||||
var stack = evaluate('{ 99 dup }');
|
||||
var expectedStack = [99, 99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
// TODO eq
|
||||
it('exchanges', function() {
|
||||
var stack = evaluate('{ 44 99 exch }');
|
||||
var expectedStack = [99, 44];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
// TODO exp
|
||||
// TODO false
|
||||
// TODO floor
|
||||
// TODO ge
|
||||
// TODO gt
|
||||
it('divides to integer', function() {
|
||||
var stack = evaluate('{ 2 3 idiv }');
|
||||
var expectedStack = [0];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('divides to negative integer', function() {
|
||||
var stack = evaluate('{ -2 3 idiv }');
|
||||
var expectedStack = [0];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('duplicates index', function() {
|
||||
var stack = evaluate('{ 4 3 2 1 2 index }');
|
||||
var expectedStack = [4, 3, 2, 1, 3];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
// TODO le
|
||||
// TODO ln
|
||||
// TODO log
|
||||
// TODO lt
|
||||
// TODO mod
|
||||
// TODO mul
|
||||
// TODO ne
|
||||
// TODO neg
|
||||
// TODO not
|
||||
// TODO or
|
||||
it('pops stack', function() {
|
||||
var stack = evaluate('{ 1 2 pop }');
|
||||
var expectedStack = [1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rolls stack right', function() {
|
||||
var stack = evaluate('{ 1 3 2 2 4 1 roll }');
|
||||
var expectedStack = [2, 1, 3, 2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rolls stack left', function() {
|
||||
var stack = evaluate('{ 1 3 2 2 4 -1 roll }');
|
||||
var expectedStack = [3, 2, 2, 1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
// TODO round
|
||||
// TODO sin
|
||||
// TODO sqrt
|
||||
// TODO sub
|
||||
// TODO true
|
||||
// TODO truncate
|
||||
// TODO xor
|
||||
});
|
||||
});
|
||||
|
|
@ -3,14 +3,129 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
describe("obj", function() {
|
||||
describe('obj', function() {
|
||||
|
||||
describe("Name", function() {
|
||||
it("should retain the given name", function() {
|
||||
var givenName = "Font";
|
||||
describe('Name', function() {
|
||||
it('should retain the given name', function() {
|
||||
var givenName = 'Font';
|
||||
var name = new Name(givenName);
|
||||
expect(name.name).toEqual(givenName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Cmd', function() {
|
||||
it('should retain the given cmd name', function() {
|
||||
var givenCmd = 'BT';
|
||||
var cmd = new Cmd(givenCmd);
|
||||
expect(cmd.cmd).toEqual(givenCmd);
|
||||
});
|
||||
|
||||
it('should create only one object for a command and cache it', function() {
|
||||
var firstBT = Cmd.get('BT');
|
||||
var secondBT = Cmd.get('BT');
|
||||
var firstET = Cmd.get('ET');
|
||||
var secondET = Cmd.get('ET');
|
||||
expect(firstBT).toBe(secondBT);
|
||||
expect(firstET).toBe(secondET);
|
||||
expect(firstBT).not.toBe(firstET);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Dict', function() {
|
||||
var checkInvalidHasValues = function(dict) {
|
||||
expect(dict.has()).toBeFalsy();
|
||||
expect(dict.has('Prev')).toBeFalsy();
|
||||
};
|
||||
|
||||
var checkInvalidKeyValues = function(dict) {
|
||||
expect(dict.get()).toBeUndefined();
|
||||
expect(dict.get('Prev')).toBeUndefined();
|
||||
expect(dict.get('Decode', 'D')).toBeUndefined();
|
||||
|
||||
// Note that the getter with three arguments breaks the pattern here.
|
||||
expect(dict.get('FontFile', 'FontFile2', 'FontFile3')).toBeNull();
|
||||
};
|
||||
|
||||
var emptyDict, dictWithSizeKey, dictWithManyKeys;
|
||||
var storedSize = 42;
|
||||
var testFontFile = 'file1';
|
||||
var testFontFile2 = 'file2';
|
||||
var testFontFile3 = 'file3';
|
||||
|
||||
beforeEach(function() {
|
||||
emptyDict = new Dict();
|
||||
|
||||
dictWithSizeKey = new Dict();
|
||||
dictWithSizeKey.set('Size', storedSize);
|
||||
|
||||
dictWithManyKeys = new Dict();
|
||||
dictWithManyKeys.set('FontFile', testFontFile);
|
||||
dictWithManyKeys.set('FontFile2', testFontFile2);
|
||||
dictWithManyKeys.set('FontFile3', testFontFile3);
|
||||
});
|
||||
|
||||
it('should return invalid values for unknown keys', function() {
|
||||
checkInvalidHasValues(emptyDict);
|
||||
checkInvalidKeyValues(emptyDict);
|
||||
});
|
||||
|
||||
it('should return correct value for stored Size key', function() {
|
||||
expect(dictWithSizeKey.has('Size')).toBeTruthy();
|
||||
|
||||
expect(dictWithSizeKey.get('Size')).toEqual(storedSize);
|
||||
expect(dictWithSizeKey.get('Prev', 'Size')).toEqual(storedSize);
|
||||
expect(dictWithSizeKey.get('Prev', 'Root', 'Size')).toEqual(storedSize);
|
||||
});
|
||||
|
||||
it('should return invalid values for unknown keys when Size key is stored',
|
||||
function() {
|
||||
checkInvalidHasValues(dictWithSizeKey);
|
||||
checkInvalidKeyValues(dictWithSizeKey);
|
||||
});
|
||||
|
||||
it('should return correct value for stored Size key with undefined value',
|
||||
function() {
|
||||
var dict = new Dict();
|
||||
dict.set('Size');
|
||||
|
||||
expect(dict.has('Size')).toBeTruthy();
|
||||
|
||||
checkInvalidKeyValues(dict);
|
||||
});
|
||||
|
||||
it('should return correct values for multiple stored keys', function() {
|
||||
expect(dictWithManyKeys.has('FontFile')).toBeTruthy();
|
||||
expect(dictWithManyKeys.has('FontFile2')).toBeTruthy();
|
||||
expect(dictWithManyKeys.has('FontFile3')).toBeTruthy();
|
||||
|
||||
expect(dictWithManyKeys.get('FontFile3')).toEqual(testFontFile3);
|
||||
expect(dictWithManyKeys.get('FontFile2', 'FontFile3'))
|
||||
.toEqual(testFontFile2);
|
||||
expect(dictWithManyKeys.get('FontFile', 'FontFile2', 'FontFile3'))
|
||||
.toEqual(testFontFile);
|
||||
});
|
||||
|
||||
it('should callback for each stored key', function() {
|
||||
var callbackSpy = jasmine.createSpy('spy on callback in dictionary');
|
||||
|
||||
dictWithManyKeys.forEach(callbackSpy);
|
||||
|
||||
expect(callbackSpy).wasCalled();
|
||||
expect(callbackSpy.argsForCall[0]).toEqual(['FontFile', testFontFile]);
|
||||
expect(callbackSpy.argsForCall[1]).toEqual(['FontFile2', testFontFile2]);
|
||||
expect(callbackSpy.argsForCall[2]).toEqual(['FontFile3', testFontFile3]);
|
||||
expect(callbackSpy.callCount).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ref', function() {
|
||||
it('should retain the stored values', function() {
|
||||
var storedNum = 4;
|
||||
var storedGen = 2;
|
||||
var ref = new Ref(storedNum, storedGen);
|
||||
expect(ref.num).toEqual(storedNum);
|
||||
expect(ref.gen).toEqual(storedGen);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -11,9 +11,28 @@
|
|||
|
||||
<!-- include spec files here... -->
|
||||
<script type="text/javascript" src="obj_spec.js"></script>
|
||||
<script type="text/javascript" src="function_spec.js"></script>
|
||||
|
||||
<!-- include source files here... -->
|
||||
<script type="text/javascript" src="../../src/core.js"></script>
|
||||
<script type="text/javascript" src="../../src/util.js"></script>
|
||||
<script type="text/javascript" src="../../src/canvas.js"></script>
|
||||
<script type="text/javascript" src="../../src/obj.js"></script>
|
||||
<script type="text/javascript" src="../../src/function.js"></script>
|
||||
<script type="text/javascript" src="../../src/charsets.js"></script>
|
||||
<script type="text/javascript" src="../../src/cidmaps.js"></script>
|
||||
<script type="text/javascript" src="../../src/colorspace.js"></script>
|
||||
<script type="text/javascript" src="../../src/crypto.js"></script>
|
||||
<script type="text/javascript" src="../../src/evaluator.js"></script>
|
||||
<script type="text/javascript" src="../../src/fonts.js"></script>
|
||||
<script type="text/javascript" src="../../src/glyphlist.js"></script>
|
||||
<script type="text/javascript" src="../../src/image.js"></script>
|
||||
<script type="text/javascript" src="../../src/metrics.js"></script>
|
||||
<script type="text/javascript" src="../../src/parser.js"></script>
|
||||
<script type="text/javascript" src="../../src/pattern.js"></script>
|
||||
<script type="text/javascript" src="../../src/stream.js"></script>
|
||||
<script type="text/javascript" src="../../src/worker.js"></script>
|
||||
<script type="text/javascript" src="../../external/jpgjs/jpg.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
'use strict';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue