mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Split the existing PDFFunction
in two classes, a private PDFFunction
and a public PDFFunctionFactory
, and utilize the latter in
PDFDocument to allow various code to access the methods of
PDFFunction`
*Follow-up to PR 8909.* This requires us to pass around `pdfFunctionFactory` to quite a lot of existing code, however I don't see another way of handling this while still guaranteeing that we can access `PDFFunction` as freely as in the old code. Please note that the patch passes all tests locally (unit, font, reference), and I *very* much hope that we have sufficient test-coverage for the code in question to catch any typos/mistakes in the re-factoring.
This commit is contained in:
parent
5c961c76bb
commit
b8ec518a1e
8 changed files with 226 additions and 124 deletions
|
@ -16,6 +16,7 @@
|
|||
import { Dict, Name, Ref } from '../../src/core/primitives';
|
||||
import { Stream, StringStream } from '../../src/core/stream';
|
||||
import { ColorSpace } from '../../src/core/colorspace';
|
||||
import { PDFFunctionFactory } from '../../src/core/function';
|
||||
import { XRefMock } from './test_utils';
|
||||
|
||||
describe('colorspace', function () {
|
||||
|
@ -54,7 +55,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([27, 125, 250, 131]);
|
||||
let testDest = new Uint8Array(4 * 4 * 3);
|
||||
|
@ -92,7 +96,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([27, 125, 250, 131]);
|
||||
let testDest = new Uint8Array(3 * 3 * 3);
|
||||
|
@ -126,7 +133,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([
|
||||
27, 125, 250,
|
||||
|
@ -169,7 +179,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([
|
||||
27, 125, 250,
|
||||
|
@ -208,7 +221,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([
|
||||
27, 125, 250, 128,
|
||||
|
@ -251,7 +267,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([
|
||||
27, 125, 250, 128,
|
||||
|
@ -298,7 +317,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([27, 125, 250, 131]);
|
||||
let testDest = new Uint8Array(4 * 4 * 3);
|
||||
|
@ -348,7 +370,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([
|
||||
27, 125, 250,
|
||||
|
@ -395,7 +420,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([
|
||||
27, 25, 50,
|
||||
|
@ -445,7 +473,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([2, 2, 0, 1]);
|
||||
let testDest = new Uint8Array(3 * 3 * 3);
|
||||
|
@ -497,7 +528,10 @@ describe('colorspace', function () {
|
|||
}]);
|
||||
let res = new Dict();
|
||||
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res);
|
||||
let pdfFunctionFactory = new PDFFunctionFactory({
|
||||
xref,
|
||||
});
|
||||
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
|
||||
let testSrc = new Uint8Array([27, 25, 50, 31]);
|
||||
let testDest = new Uint8Array(3 * 3 * 3);
|
||||
|
|
|
@ -18,16 +18,14 @@ import { Page } from '../../src/core/document';
|
|||
describe('document', function () {
|
||||
describe('Page', function () {
|
||||
it('should create correct objId using the idFactory', function () {
|
||||
var page1 = new Page(/* pdfManager = */ { }, /* xref = */ null,
|
||||
/* pageIndex = */ 0,
|
||||
/* pageDict = */ null, /* ref = */ null,
|
||||
/* fontCache = */ null,
|
||||
/* builtInCMapCache = */ null);
|
||||
var page2 = new Page(/* pdfManager = */ { }, /* xref = */ null,
|
||||
/* pageIndex = */ 1,
|
||||
/* pageDict = */ null, /* ref = */ null,
|
||||
/* fontCache = */ null,
|
||||
/* builtInCMapCache = */ null);
|
||||
var page1 = new Page({
|
||||
pdfManager: { },
|
||||
pageIndex: 0,
|
||||
});
|
||||
var page2 = new Page({
|
||||
pdfManager: { },
|
||||
pageIndex: 1,
|
||||
});
|
||||
|
||||
var idFactory1 = page1.idFactory, idFactory2 = page2.idFactory;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue