: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
class LocalImageCache extends BaseLocalCache {
set(name, ref = null, data) {
if (typeof name !== "string") {
throw new Error('LocalImageCache.set - expected "name" argument.');
if (this._imageCache.has(ref)) {
this._nameRefMap.set(name, ref);
this._imageCache.put(ref, data);
if (this._imageMap.has(name)) {
this._imageMap.set(name, data);
class LocalColorSpaceCache extends BaseLocalCache {
set(name = null, ref = null, data) {
if (typeof name !== "string" && !ref) {
throw new Error('LocalColorSpaceCache.set - expected "name" and/or "ref" argument.');
if (this._imageCache.has(ref)) {
this._nameRefMap.set(name, ref);
this._imageCache.put(ref, data);
if (this._imageMap.has(name)) {
this._imageMap.set(name, data);
class LocalFunctionCache extends BaseLocalCache {
set(name = null, ref, data) {
throw new Error('LocalFunctionCache.set - expected "ref" argument.');
if (this._imageCache.has(ref)) {
this._imageCache.put(ref, data);
class LocalGStateCache extends BaseLocalCache {
set(name, ref = null, data) {
if (typeof name !== "string") {
throw new Error('LocalGStateCache.set - expected "name" argument.');
if (this._imageCache.has(ref)) {
this._nameRefMap.set(name, ref);
this._imageCache.put(ref, data);
if (this._imageMap.has(name)) {
this._imageMap.set(name, data);
class LocalTilingPatternCache extends BaseLocalCache {
set(name = null, ref, data) {
throw new Error('LocalTilingPatternCache.set - expected "ref" argument.');
if (this._imageCache.has(ref)) {
this._imageCache.put(ref, data);
class RegionalImageCache extends BaseLocalCache {
set(name = null, ref, data) {
throw new Error('RegionalImageCache.set - expected "ref" argument.');
if (this._imageCache.has(ref)) {
this._imageCache.put(ref, data);
static NUM_PAGES_THRESHOLD = 2;
static MIN_IMAGES_TO_CACHE = 10;
static MAX_BYTE_SIZE = 5 * MAX_IMAGE_SIZE_TO_CACHE;
#decodeFailedSet = new RefSet();
this._refCache = new RefSetCache();
this._imageCache = new RefSetCache();
for (const imageData of this._imageCache) {
byteSize += imageData.byteSize;
get #cacheLimitReached() {
if (this._imageCache.size < GlobalImageCache.MIN_IMAGES_TO_CACHE) {
if (this.#byteSize < GlobalImageCache.MAX_BYTE_SIZE) {
shouldCache(ref, pageIndex) {
let pageIndexSet = this._refCache.get(ref);
pageIndexSet = new Set();
this._refCache.put(ref, pageIndexSet);
pageIndexSet.add(pageIndex);
if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
if (!this._imageCache.has(ref) && this.#cacheLimitReached) {
this.#decodeFailedSet.put(ref);
return this.#decodeFailedSet.has(ref);
addByteSize(ref, byteSize) {
const imageData = this._imageCache.get(ref);
if (imageData.byteSize) {
imageData.byteSize = byteSize;
getData(ref, pageIndex) {
const pageIndexSet = this._refCache.get(ref);
if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
const imageData = this._imageCache.get(ref);
pageIndexSet.add(pageIndex);
if (!this._refCache.has(ref)) {
throw new Error('GlobalImageCache.setData - expected "shouldCache" to have been called.');
if (this._imageCache.has(ref)) {
if (this.#cacheLimitReached) {
warn("GlobalImageCache.setData - cache limit reached.");
this._imageCache.put(ref, data);
clear(onlyData = false) {
this.#decodeFailedSet.clear();
this._imageCache.clear();
;// CONCATENATED MODULE: ./src/core/function.js
class PDFFunctionFactory {
this.isEvalSupported = isEvalSupported !== false;
const cachedFunction = this.getCached(fn);
const parsedFunction = PDFFunction.parse({
isEvalSupported: this.isEvalSupported,
fn: fn instanceof Ref ? this.xref.fetch(fn) : fn
this._cache(fn, parsedFunction);
const cachedFunction = this.getCached(fnObj);
const parsedFunction = PDFFunction.parseArray({
isEvalSupported: this.isEvalSupported,
fnObj: fnObj instanceof Ref ? this.xref.fetch(fnObj) : fnObj
this._cache(fnObj, parsedFunction);
if (cacheKey instanceof Ref) {
} else if (cacheKey instanceof Dict) {
} else if (cacheKey instanceof BaseStream) {
fnRef = cacheKey.dict?.objId;
const localFunction = this._localFunctionCache.getByRef(fnRef);
_cache(cacheKey, parsedFunction) {
throw new Error('PDFFunctionFactory._cache - expected "parsedFunction" argument.');
if (cacheKey instanceof Ref) {
} else if (cacheKey instanceof Dict) {
} else if (cacheKey instanceof BaseStream) {
fnRef = cacheKey.dict?.objId;
this._localFunctionCache.set(null, fnRef, parsedFunction);
get _localFunctionCache() {
return shadow(this, "_localFunctionCache", new LocalFunctionCache());
function toNumberArray(arr) {
if (!Array.isArray(arr)) {
if (!isNumberArray(arr, null)) {
static getSampleArray(size, outputSize, bps, stream) {
for (i = 0, ii = size.length; i < ii; i++) {
const array = new Array(length);
const sampleMul = 1.0 / (2.0 ** bps - 1);
const strBytes = stream.getBytes((length * bps + 7) / 8);
for (i = 0; i < length; i++) {
codeBuf |= strBytes[strIdx++];
array[i] = (codeBuf >> codeSize) * sampleMul;
codeBuf &= (1 << codeSize) - 1;
const dict = fn.dict || fn;
const typeNum = dict.get("FunctionType");
return this.constructSampled({
return this.constructInterpolated({
return this.constructStiched({
return this.constructPostScript({
throw new FormatError("Unknown type of function");
if (!Array.isArray(fnObj)) {
for (const fn of fnObj) {
fnArray.push(this.parse({
return function (src, srcOffset, dest, destOffset) {
for (let i = 0, ii = fnArray.length; i < ii; i++) {
fnArray[i](src, srcOffset, dest, destOffset + i);
static constructSampled({
function toMultiArray(arr) {
const inputLength = arr.length;
for (let i = 0; i < inputLength; i += 2) {
out[index++] = [arr[i], arr[i + 1]];
function interpolate(x, xmin, xmax, ymin, ymax) {
return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
let domain = toNumberArray(dict.getArray("Domain"));
let range = toNumberArray(dict.getArray("Range"));
throw new FormatError("No domain or range");
const inputSize = domain.length / 2;
const outputSize = range.length / 2;
domain = toMultiArray(domain);
range = toMultiArray(range);
const size = toNumberArray(dict.getArray("Size"));
const bps = dict.get("BitsPerSample");
const order = dict.get("Order") || 1;
info("No support for cubic spline interpolation: " + order);
let encode = toNumberArray(dict.getArray("Encode"));
for (let i = 0; i < inputSize; ++i) {
encode.push([0, size[i] - 1]);
encode = toMultiArray(encode);
let decode = toNumberArray(dict.getArray("Decode"));
decode = !decode ? range : toMultiArray(decode);
const samples = this.getSampleArray(size, outputSize, bps, fn);
return function constructSampledFn(src, srcOffset, dest, destOffset) {
const cubeVertices = 1 << inputSize;
const cubeN = new Float64Array(cubeVertices);
const cubeVertex = new Uint32Array(cubeVertices);
for (j = 0; j < cubeVertices; j++) {
for (i = 0; i < inputSize; ++i) {
const domain_2i = domain[i][0];
const domain_2i_1 = domain[i][1];
const xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
let e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
e = Math.min(Math.max(e, 0), size_i - 1);
const e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
const offset1 = offset0 + k;
for (j = 0; j < cubeVertices; j++) {
cubeVertex[j] += offset1;
cubeVertex[j] += offset0;
for (j = 0; j < outputSize; ++j) {
for (i = 0; i < cubeVertices; i++) {
rj += samples[cubeVertex[i] + j] * cubeN[i];
rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
static constructInterpolated({
const c0 = toNumberArray(dict.getArray("C0")) || [0];
const c1 = toNumberArray(dict.getArray("C1")) || [1];
for (let i = 0, ii = c0.length; i < ii; ++i) {
diff.push(c1[i] - c0[i]);
const length = diff.length;
return function constructInterpolatedFn(src, srcOffset, dest, destOffset) {
const x = n === 1 ? src[srcOffset] : src[srcOffset] ** n;
for (let j = 0; j < length; ++j) {
dest[destOffset + j] = c0[j] + x * diff[j];
static constructStiched({