mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-31 11:27:21 +02:00
Compare commits
No commits in common. "89ccc3a526b868534df4f621145b31c528c0ccaa" and "5f4d923618df3c47f706e0c0f8215469240c8f1b" have entirely different histories.
89ccc3a526
...
5f4d923618
@ -83,23 +83,14 @@ class AnnotationFactory {
|
||||
// Only necessary to prevent the `Catalog.attachments`-getter, used
|
||||
// with "GoToE" actions, from throwing and thus breaking parsing:
|
||||
pdfManager.ensureCatalog("attachments"),
|
||||
pdfManager.ensureCatalog("globalColorSpaceCache"),
|
||||
]).then(
|
||||
([
|
||||
acroForm,
|
||||
xfaDatasets,
|
||||
structTreeRoot,
|
||||
baseUrl,
|
||||
attachments,
|
||||
globalColorSpaceCache,
|
||||
]) => ({
|
||||
([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => ({
|
||||
pdfManager,
|
||||
acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
|
||||
xfaDatasets,
|
||||
structTreeRoot,
|
||||
baseUrl,
|
||||
attachments,
|
||||
globalColorSpaceCache,
|
||||
}),
|
||||
reason => {
|
||||
warn(`createGlobals: "${reason}".`);
|
||||
@ -3889,7 +3880,7 @@ class FreeTextAnnotation extends MarkupAnnotation {
|
||||
// We want to be able to add mouse listeners to the annotation.
|
||||
this.data.noHTML = false;
|
||||
|
||||
const { annotationGlobals, evaluatorOptions, xref } = params;
|
||||
const { evaluatorOptions, xref } = params;
|
||||
this.data.annotationType = AnnotationType.FREETEXT;
|
||||
this.setDefaultAppearance(params);
|
||||
this._hasAppearance = !!this.appearance;
|
||||
@ -3898,8 +3889,7 @@ class FreeTextAnnotation extends MarkupAnnotation {
|
||||
const { fontColor, fontSize } = parseAppearanceStream(
|
||||
this.appearance,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
annotationGlobals.globalColorSpaceCache
|
||||
xref
|
||||
);
|
||||
this.data.defaultAppearanceData.fontColor = fontColor;
|
||||
this.data.defaultAppearanceData.fontSize = fontSize || 10;
|
||||
|
||||
@ -44,12 +44,12 @@ import {
|
||||
RefSet,
|
||||
RefSetCache,
|
||||
} from "./primitives.js";
|
||||
import { GlobalColorSpaceCache, GlobalImageCache } from "./image_utils.js";
|
||||
import { NameTree, NumberTree } from "./name_number_tree.js";
|
||||
import { BaseStream } from "./base_stream.js";
|
||||
import { clearGlobalCaches } from "./cleanup_helper.js";
|
||||
import { ColorSpace } from "./colorspace.js";
|
||||
import { FileSpec } from "./file_spec.js";
|
||||
import { GlobalImageCache } from "./image_utils.js";
|
||||
import { MetadataParser } from "./metadata_parser.js";
|
||||
import { StructTreeRoot } from "./struct_tree.js";
|
||||
|
||||
@ -140,7 +140,6 @@ class Catalog {
|
||||
this.fontCache = new RefSetCache();
|
||||
this.builtInCMapCache = new Map();
|
||||
this.standardFontDataCache = new Map();
|
||||
this.globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
this.globalImageCache = new GlobalImageCache();
|
||||
this.pageKidsCountCache = new RefSetCache();
|
||||
this.pageIndexCache = new RefSetCache();
|
||||
@ -1172,7 +1171,6 @@ class Catalog {
|
||||
|
||||
async cleanup(manuallyTriggered = false) {
|
||||
clearGlobalCaches();
|
||||
this.globalColorSpaceCache.clear();
|
||||
this.globalImageCache.clear(/* onlyData = */ manuallyTriggered);
|
||||
this.pageKidsCountCache.clear();
|
||||
this.pageIndexCache.clear();
|
||||
|
||||
@ -306,20 +306,19 @@ class ColorSpace {
|
||||
return shadow(this, "usesZeroToOneRange", true);
|
||||
}
|
||||
|
||||
static #cache(
|
||||
cacheKey,
|
||||
xref,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
parsedCS
|
||||
) {
|
||||
if (!globalColorSpaceCache || !localColorSpaceCache) {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
static _cache(cacheKey, xref, localColorSpaceCache, parsedColorSpace) {
|
||||
if (!localColorSpaceCache) {
|
||||
throw new Error(
|
||||
'ColorSpace.#cache - expected "globalColorSpaceCache"/"localColorSpaceCache" argument.'
|
||||
'ColorSpace._cache - expected "localColorSpaceCache" argument.'
|
||||
);
|
||||
}
|
||||
if (!parsedCS) {
|
||||
throw new Error('ColorSpace.#cache - expected "parsedCS" argument.');
|
||||
if (!parsedColorSpace) {
|
||||
throw new Error(
|
||||
'ColorSpace._cache - expected "parsedColorSpace" argument.'
|
||||
);
|
||||
}
|
||||
let csName, csRef;
|
||||
if (cacheKey instanceof Ref) {
|
||||
@ -332,31 +331,20 @@ class ColorSpace {
|
||||
csName = cacheKey.name;
|
||||
}
|
||||
if (csName || csRef) {
|
||||
localColorSpaceCache.set(csName, csRef, parsedCS);
|
||||
|
||||
if (csRef) {
|
||||
globalColorSpaceCache.set(/* name = */ null, csRef, parsedCS);
|
||||
}
|
||||
localColorSpaceCache.set(csName, csRef, parsedColorSpace);
|
||||
}
|
||||
}
|
||||
|
||||
static getCached(
|
||||
cacheKey,
|
||||
xref,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
) {
|
||||
if (!globalColorSpaceCache || !localColorSpaceCache) {
|
||||
static getCached(cacheKey, xref, localColorSpaceCache) {
|
||||
if (!localColorSpaceCache) {
|
||||
throw new Error(
|
||||
'ColorSpace.getCached - expected "globalColorSpaceCache"/"localColorSpaceCache" argument.'
|
||||
'ColorSpace.getCached - expected "localColorSpaceCache" argument.'
|
||||
);
|
||||
}
|
||||
if (cacheKey instanceof Ref) {
|
||||
const cachedCS =
|
||||
globalColorSpaceCache.getByRef(cacheKey) ||
|
||||
localColorSpaceCache.getByRef(cacheKey);
|
||||
if (cachedCS) {
|
||||
return cachedCS;
|
||||
const localColorSpace = localColorSpaceCache.getByRef(cacheKey);
|
||||
if (localColorSpace) {
|
||||
return localColorSpace;
|
||||
}
|
||||
|
||||
try {
|
||||
@ -369,7 +357,10 @@ class ColorSpace {
|
||||
}
|
||||
}
|
||||
if (cacheKey instanceof Name) {
|
||||
return localColorSpaceCache.getByName(cacheKey.name) || null;
|
||||
const localColorSpace = localColorSpaceCache.getByName(cacheKey.name);
|
||||
if (localColorSpace) {
|
||||
return localColorSpace;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -379,28 +370,26 @@ class ColorSpace {
|
||||
xref,
|
||||
resources = null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
}) {
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
assert(
|
||||
!this.getCached(cs, xref, globalColorSpaceCache, localColorSpaceCache),
|
||||
!this.getCached(cs, xref, localColorSpaceCache),
|
||||
"Expected `ColorSpace.getCached` to have been manually checked " +
|
||||
"before calling `ColorSpace.parseAsync`."
|
||||
);
|
||||
}
|
||||
const parsedCS = this.#parse(cs, xref, resources, pdfFunctionFactory);
|
||||
|
||||
// Attempt to cache the parsed ColorSpace, by name and/or reference.
|
||||
this.#cache(
|
||||
const parsedColorSpace = this._parse(
|
||||
cs,
|
||||
xref,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
parsedCS
|
||||
resources,
|
||||
pdfFunctionFactory
|
||||
);
|
||||
|
||||
return parsedCS;
|
||||
// Attempt to cache the parsed ColorSpace, by name and/or reference.
|
||||
this._cache(cs, xref, localColorSpaceCache, parsedColorSpace);
|
||||
|
||||
return parsedColorSpace;
|
||||
}
|
||||
|
||||
static parse({
|
||||
@ -408,33 +397,29 @@ class ColorSpace {
|
||||
xref,
|
||||
resources = null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
}) {
|
||||
const cachedCS = this.getCached(
|
||||
const cachedColorSpace = this.getCached(cs, xref, localColorSpaceCache);
|
||||
if (cachedColorSpace) {
|
||||
return cachedColorSpace;
|
||||
}
|
||||
const parsedColorSpace = this._parse(
|
||||
cs,
|
||||
xref,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
resources,
|
||||
pdfFunctionFactory
|
||||
);
|
||||
if (cachedCS) {
|
||||
return cachedCS;
|
||||
}
|
||||
const parsedCS = this.#parse(cs, xref, resources, pdfFunctionFactory);
|
||||
|
||||
// Attempt to cache the parsed ColorSpace, by name and/or reference.
|
||||
this.#cache(
|
||||
cs,
|
||||
xref,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
parsedCS
|
||||
);
|
||||
this._cache(cs, xref, localColorSpaceCache, parsedColorSpace);
|
||||
|
||||
return parsedCS;
|
||||
return parsedColorSpace;
|
||||
}
|
||||
|
||||
static #parse(cs, xref, resources = null, pdfFunctionFactory) {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
static _parse(cs, xref, resources = null, pdfFunctionFactory) {
|
||||
cs = xref.fetchIfRef(cs);
|
||||
if (cs instanceof Name) {
|
||||
switch (cs.name) {
|
||||
@ -458,7 +443,7 @@ class ColorSpace {
|
||||
const resourcesCS = colorSpaces.get(cs.name);
|
||||
if (resourcesCS) {
|
||||
if (resourcesCS instanceof Name) {
|
||||
return this.#parse(
|
||||
return this._parse(
|
||||
resourcesCS,
|
||||
xref,
|
||||
resources,
|
||||
@ -508,7 +493,7 @@ class ColorSpace {
|
||||
numComps = dict.get("N");
|
||||
const alt = dict.get("Alternate");
|
||||
if (alt) {
|
||||
const altCS = this.#parse(alt, xref, resources, pdfFunctionFactory);
|
||||
const altCS = this._parse(alt, xref, resources, pdfFunctionFactory);
|
||||
// Ensure that the number of components are correct,
|
||||
// and also (indirectly) that it is not a PatternCS.
|
||||
if (altCS.numComps === numComps) {
|
||||
@ -527,12 +512,12 @@ class ColorSpace {
|
||||
case "Pattern":
|
||||
baseCS = cs[1] || null;
|
||||
if (baseCS) {
|
||||
baseCS = this.#parse(baseCS, xref, resources, pdfFunctionFactory);
|
||||
baseCS = this._parse(baseCS, xref, resources, pdfFunctionFactory);
|
||||
}
|
||||
return new PatternCS(baseCS);
|
||||
case "I":
|
||||
case "Indexed":
|
||||
baseCS = this.#parse(cs[1], xref, resources, pdfFunctionFactory);
|
||||
baseCS = this._parse(cs[1], xref, resources, pdfFunctionFactory);
|
||||
const hiVal = Math.max(0, Math.min(xref.fetchIfRef(cs[2]), 255));
|
||||
const lookup = xref.fetchIfRef(cs[3]);
|
||||
return new IndexedCS(baseCS, hiVal, lookup);
|
||||
@ -540,7 +525,7 @@ class ColorSpace {
|
||||
case "DeviceN":
|
||||
const name = xref.fetchIfRef(cs[1]);
|
||||
numComps = Array.isArray(name) ? name.length : 1;
|
||||
baseCS = this.#parse(cs[2], xref, resources, pdfFunctionFactory);
|
||||
baseCS = this._parse(cs[2], xref, resources, pdfFunctionFactory);
|
||||
const tintFn = pdfFunctionFactory.create(cs[3]);
|
||||
return new AlternateCS(numComps, baseCS, tintFn);
|
||||
case "Lab":
|
||||
|
||||
@ -97,12 +97,11 @@ function parseDefaultAppearance(str) {
|
||||
}
|
||||
|
||||
class AppearanceStreamEvaluator extends EvaluatorPreprocessor {
|
||||
constructor(stream, evaluatorOptions, xref, globalColorSpaceCache) {
|
||||
constructor(stream, evaluatorOptions, xref) {
|
||||
super(stream);
|
||||
this.stream = stream;
|
||||
this.evaluatorOptions = evaluatorOptions;
|
||||
this.xref = xref;
|
||||
this.globalColorSpaceCache = globalColorSpaceCache;
|
||||
|
||||
this.resources = stream.dict?.get("Resources");
|
||||
}
|
||||
@ -162,7 +161,6 @@ class AppearanceStreamEvaluator extends EvaluatorPreprocessor {
|
||||
xref: this.xref,
|
||||
resources: this.resources,
|
||||
pdfFunctionFactory: this._pdfFunctionFactory,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
localColorSpaceCache: this._localColorSpaceCache,
|
||||
});
|
||||
break;
|
||||
@ -212,18 +210,8 @@ class AppearanceStreamEvaluator extends EvaluatorPreprocessor {
|
||||
|
||||
// Parse appearance stream to extract font and color information.
|
||||
// It returns the font properties used to render the first text object.
|
||||
function parseAppearanceStream(
|
||||
stream,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
globalColorSpaceCache
|
||||
) {
|
||||
return new AppearanceStreamEvaluator(
|
||||
stream,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
globalColorSpaceCache
|
||||
).parse();
|
||||
function parseAppearanceStream(stream, evaluatorOptions, xref) {
|
||||
return new AppearanceStreamEvaluator(stream, evaluatorOptions, xref).parse();
|
||||
}
|
||||
|
||||
function getPdfColor(color, isFill) {
|
||||
|
||||
@ -87,7 +87,6 @@ class Page {
|
||||
fontCache,
|
||||
builtInCMapCache,
|
||||
standardFontDataCache,
|
||||
globalColorSpaceCache,
|
||||
globalImageCache,
|
||||
systemFontCache,
|
||||
nonBlendModesSet,
|
||||
@ -101,7 +100,6 @@ class Page {
|
||||
this.fontCache = fontCache;
|
||||
this.builtInCMapCache = builtInCMapCache;
|
||||
this.standardFontDataCache = standardFontDataCache;
|
||||
this.globalColorSpaceCache = globalColorSpaceCache;
|
||||
this.globalImageCache = globalImageCache;
|
||||
this.systemFontCache = systemFontCache;
|
||||
this.nonBlendModesSet = nonBlendModesSet;
|
||||
@ -329,7 +327,6 @@ class Page {
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
systemFontCache: this.systemFontCache,
|
||||
options: this.evaluatorOptions,
|
||||
@ -384,7 +381,6 @@ class Page {
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
systemFontCache: this.systemFontCache,
|
||||
options: this.evaluatorOptions,
|
||||
@ -450,7 +446,6 @@ class Page {
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
systemFontCache: this.systemFontCache,
|
||||
options: this.evaluatorOptions,
|
||||
@ -675,7 +670,6 @@ class Page {
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
systemFontCache: this.systemFontCache,
|
||||
options: this.evaluatorOptions,
|
||||
@ -748,7 +742,6 @@ class Page {
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
systemFontCache: this.systemFontCache,
|
||||
options: this.evaluatorOptions,
|
||||
@ -1639,7 +1632,6 @@ class PDFDocument {
|
||||
fontCache: catalog.fontCache,
|
||||
builtInCMapCache: catalog.builtInCMapCache,
|
||||
standardFontDataCache: catalog.standardFontDataCache,
|
||||
globalColorSpaceCache: catalog.globalColorSpaceCache,
|
||||
globalImageCache: catalog.globalImageCache,
|
||||
systemFontCache: catalog.systemFontCache,
|
||||
nonBlendModesSet: catalog.nonBlendModesSet,
|
||||
@ -1739,7 +1731,6 @@ class PDFDocument {
|
||||
fontCache: catalog.fontCache,
|
||||
builtInCMapCache: catalog.builtInCMapCache,
|
||||
standardFontDataCache: catalog.standardFontDataCache,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
globalImageCache: catalog.globalImageCache,
|
||||
systemFontCache: catalog.systemFontCache,
|
||||
nonBlendModesSet: catalog.nonBlendModesSet,
|
||||
|
||||
@ -221,7 +221,6 @@ class PartialEvaluator {
|
||||
fontCache,
|
||||
builtInCMapCache,
|
||||
standardFontDataCache,
|
||||
globalColorSpaceCache,
|
||||
globalImageCache,
|
||||
systemFontCache,
|
||||
options = null,
|
||||
@ -233,7 +232,6 @@ class PartialEvaluator {
|
||||
this.fontCache = fontCache;
|
||||
this.builtInCMapCache = builtInCMapCache;
|
||||
this.standardFontDataCache = standardFontDataCache;
|
||||
this.globalColorSpaceCache = globalColorSpaceCache;
|
||||
this.globalImageCache = globalImageCache;
|
||||
this.systemFontCache = systemFontCache;
|
||||
this.options = options || DefaultPartialEvaluatorOptions;
|
||||
@ -494,7 +492,6 @@ class PartialEvaluator {
|
||||
const cachedColorSpace = ColorSpace.getCached(
|
||||
cs,
|
||||
this.xref,
|
||||
this.globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
);
|
||||
if (cachedColorSpace) {
|
||||
@ -740,7 +737,6 @@ class PartialEvaluator {
|
||||
image,
|
||||
isInline,
|
||||
pdfFunctionFactory: this._pdfFunctionFactory,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
// We force the use of RGBA_32BPP images here, because we can't handle
|
||||
@ -843,7 +839,6 @@ class PartialEvaluator {
|
||||
image,
|
||||
isInline,
|
||||
pdfFunctionFactory: this._pdfFunctionFactory,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
})
|
||||
.then(async imageObj => {
|
||||
@ -1468,7 +1463,6 @@ class PartialEvaluator {
|
||||
xref: this.xref,
|
||||
resources,
|
||||
pdfFunctionFactory: this._pdfFunctionFactory,
|
||||
globalColorSpaceCache: this.globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
}).catch(reason => {
|
||||
if (reason instanceof AbortException) {
|
||||
@ -1502,7 +1496,6 @@ class PartialEvaluator {
|
||||
this.xref,
|
||||
resources,
|
||||
this._pdfFunctionFactory,
|
||||
this.globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
);
|
||||
patternIR = shadingFill.getIR();
|
||||
@ -1984,7 +1977,6 @@ class PartialEvaluator {
|
||||
const cachedColorSpace = ColorSpace.getCached(
|
||||
args[0],
|
||||
xref,
|
||||
self.globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
);
|
||||
if (cachedColorSpace) {
|
||||
@ -2010,7 +2002,6 @@ class PartialEvaluator {
|
||||
const cachedColorSpace = ColorSpace.getCached(
|
||||
args[0],
|
||||
xref,
|
||||
self.globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
);
|
||||
if (cachedColorSpace) {
|
||||
|
||||
@ -100,7 +100,6 @@ class PDFImage {
|
||||
mask = null,
|
||||
isMask = false,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
}) {
|
||||
this.image = image;
|
||||
@ -215,7 +214,6 @@ class PDFImage {
|
||||
xref,
|
||||
resources: isInline ? res : null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
this.numComps = this.colorSpace.numComps;
|
||||
@ -263,7 +261,6 @@ class PDFImage {
|
||||
image: smask,
|
||||
isInline,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
} else if (mask) {
|
||||
@ -280,7 +277,6 @@ class PDFImage {
|
||||
isInline,
|
||||
isMask: true,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
}
|
||||
@ -301,7 +297,6 @@ class PDFImage {
|
||||
image,
|
||||
isInline = false,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
}) {
|
||||
const imageData = image;
|
||||
@ -333,7 +328,6 @@ class PDFImage {
|
||||
smask: smaskData,
|
||||
mask: maskData,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
}
|
||||
|
||||
@ -169,26 +169,6 @@ class RegionalImageCache extends BaseLocalCache {
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalColorSpaceCache extends BaseLocalCache {
|
||||
constructor(options) {
|
||||
super({ onlyRefs: true });
|
||||
}
|
||||
|
||||
set(name = null, ref, data) {
|
||||
if (!ref) {
|
||||
throw new Error('GlobalColorSpaceCache.set - expected "ref" argument.');
|
||||
}
|
||||
if (this._imageCache.has(ref)) {
|
||||
return;
|
||||
}
|
||||
this._imageCache.put(ref, data);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this._imageCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalImageCache {
|
||||
static NUM_PAGES_THRESHOLD = 2;
|
||||
|
||||
@ -310,7 +290,6 @@ class GlobalImageCache {
|
||||
}
|
||||
|
||||
export {
|
||||
GlobalColorSpaceCache,
|
||||
GlobalImageCache,
|
||||
LocalColorSpaceCache,
|
||||
LocalFunctionCache,
|
||||
|
||||
@ -52,7 +52,6 @@ class Pattern {
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
) {
|
||||
const dict = shading instanceof BaseStream ? shading.dict : shading;
|
||||
@ -67,7 +66,6 @@ class Pattern {
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
);
|
||||
case ShadingType.FREE_FORM_MESH:
|
||||
@ -79,7 +77,6 @@ class Pattern {
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
);
|
||||
default:
|
||||
@ -117,14 +114,7 @@ class BaseShading {
|
||||
// Radial and axial shading have very similar implementations
|
||||
// If needed, the implementations can be broken into two classes.
|
||||
class RadialAxialShading extends BaseShading {
|
||||
constructor(
|
||||
dict,
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
) {
|
||||
constructor(dict, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
|
||||
super();
|
||||
this.shadingType = dict.get("ShadingType");
|
||||
let coordsLen = 0;
|
||||
@ -142,7 +132,6 @@ class RadialAxialShading extends BaseShading {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
this.bbox = lookupNormalRect(dict.getArray("BBox"), null);
|
||||
@ -463,7 +452,6 @@ class MeshShading extends BaseShading {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache
|
||||
) {
|
||||
super();
|
||||
@ -478,7 +466,6 @@ class MeshShading extends BaseShading {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
this.background = dict.has("Background")
|
||||
|
||||
@ -14,12 +14,9 @@
|
||||
*/
|
||||
|
||||
import { Dict, Name, Ref } from "../../src/core/primitives.js";
|
||||
import {
|
||||
GlobalColorSpaceCache,
|
||||
LocalColorSpaceCache,
|
||||
} from "../../src/core/image_utils.js";
|
||||
import { Stream, StringStream } from "../../src/core/stream.js";
|
||||
import { ColorSpace } from "../../src/core/colorspace.js";
|
||||
import { LocalColorSpaceCache } from "../../src/core/image_utils.js";
|
||||
import { PDFFunctionFactory } from "../../src/core/function.js";
|
||||
import { XRefMock } from "./test_utils.js";
|
||||
|
||||
@ -53,15 +50,13 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("ColorSpace caching", function () {
|
||||
let globalColorSpaceCache, localColorSpaceCache;
|
||||
let localColorSpaceCache = null;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
localColorSpaceCache = new LocalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
localColorSpaceCache = null;
|
||||
});
|
||||
|
||||
@ -76,7 +71,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources: null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
expect(colorSpace1.name).toEqual("Pattern");
|
||||
@ -86,7 +80,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources: null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
expect(colorSpace2.name).toEqual("Pattern");
|
||||
@ -96,7 +89,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources: null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache: new GlobalColorSpaceCache(),
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
expect(colorSpaceNonCached.name).toEqual("Pattern");
|
||||
@ -106,7 +98,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources: null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
expect(colorSpaceOther.name).toEqual("DeviceRGB");
|
||||
@ -149,7 +140,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources: null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
expect(colorSpace1.name).toEqual("CalGray");
|
||||
@ -159,7 +149,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources: null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
expect(colorSpace2.name).toEqual("CalGray");
|
||||
@ -169,7 +158,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources: null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache: new GlobalColorSpaceCache(),
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
expect(colorSpaceNonCached.name).toEqual("CalGray");
|
||||
@ -179,7 +167,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources: null,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
expect(colorSpaceOther.name).toEqual("CalRGB");
|
||||
@ -193,16 +180,6 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("DeviceGrayCS", function () {
|
||||
let globalColorSpaceCache;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should handle the case when cs is a Name object", function () {
|
||||
const cs = Name.get("DeviceGray");
|
||||
const xref = new XRefMock([
|
||||
@ -221,7 +198,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -273,7 +249,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -303,16 +278,6 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("DeviceRgbCS", function () {
|
||||
let globalColorSpaceCache;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should handle the case when cs is a Name object", function () {
|
||||
const cs = Name.get("DeviceRGB");
|
||||
const xref = new XRefMock([
|
||||
@ -331,7 +296,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -389,7 +353,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -425,16 +388,6 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("DeviceCmykCS", function () {
|
||||
let globalColorSpaceCache;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should handle the case when cs is a Name object", function () {
|
||||
const cs = Name.get("DeviceCMYK");
|
||||
const xref = new XRefMock([
|
||||
@ -453,7 +406,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -511,7 +463,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -547,16 +498,6 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("CalGrayCS", function () {
|
||||
let globalColorSpaceCache;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should handle the case when cs is an array", function () {
|
||||
const params = new Dict();
|
||||
params.set("WhitePoint", [1, 1, 1]);
|
||||
@ -580,7 +521,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -617,16 +557,6 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("CalRGBCS", function () {
|
||||
let globalColorSpaceCache;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should handle the case when cs is an array", function () {
|
||||
const params = new Dict();
|
||||
params.set("WhitePoint", [1, 1, 1]);
|
||||
@ -651,7 +581,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -687,16 +616,6 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("LabCS", function () {
|
||||
let globalColorSpaceCache;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should handle the case when cs is an array", function () {
|
||||
const params = new Dict();
|
||||
params.set("WhitePoint", [1, 1, 1]);
|
||||
@ -720,7 +639,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -757,16 +675,6 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("IndexedCS", function () {
|
||||
let globalColorSpaceCache;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should handle the case when cs is an array", function () {
|
||||
// prettier-ignore
|
||||
const lookup = new Stream(
|
||||
@ -793,7 +701,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
@ -823,16 +730,6 @@ describe("colorspace", function () {
|
||||
});
|
||||
|
||||
describe("AlternateCS", function () {
|
||||
let globalColorSpaceCache;
|
||||
|
||||
beforeAll(function () {
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should handle the case when cs is an array", function () {
|
||||
const fnDict = new Dict();
|
||||
fnDict.set("FunctionType", 4);
|
||||
@ -872,7 +769,6 @@ describe("colorspace", function () {
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
globalColorSpaceCache,
|
||||
localColorSpaceCache: new LocalColorSpaceCache(),
|
||||
});
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ import {
|
||||
} from "../../src/core/default_appearance.js";
|
||||
import { Dict, Name } from "../../src/core/primitives.js";
|
||||
import { NullStream, StringStream } from "../../src/core/stream.js";
|
||||
import { GlobalColorSpaceCache } from "../../src/core/image_utils.js";
|
||||
import { XRefMock } from "./test_utils.js";
|
||||
|
||||
describe("Default appearance", function () {
|
||||
@ -57,7 +56,7 @@ describe("Default appearance", function () {
|
||||
});
|
||||
|
||||
describe("parseAppearanceStream", () => {
|
||||
let evaluatorOptions, xref, globalColorSpaceCache;
|
||||
let evaluatorOptions, xref;
|
||||
|
||||
beforeAll(function () {
|
||||
evaluatorOptions = {
|
||||
@ -65,13 +64,11 @@ describe("Default appearance", function () {
|
||||
isOffscreenCanvasSupported: false,
|
||||
};
|
||||
xref = new XRefMock();
|
||||
globalColorSpaceCache = new GlobalColorSpaceCache();
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
evaluatorOptions = null;
|
||||
xref = null;
|
||||
globalColorSpaceCache = null;
|
||||
});
|
||||
|
||||
it("should parse a FreeText (from Acrobat) appearance", () => {
|
||||
@ -104,14 +101,9 @@ describe("Default appearance", function () {
|
||||
fontName: "Helv",
|
||||
fontColor: new Uint8ClampedArray([107, 217, 41]),
|
||||
};
|
||||
expect(
|
||||
parseAppearanceStream(
|
||||
appearance,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
globalColorSpaceCache
|
||||
)
|
||||
).toEqual(result);
|
||||
expect(parseAppearanceStream(appearance, evaluatorOptions, xref)).toEqual(
|
||||
result
|
||||
);
|
||||
expect(appearance.pos).toEqual(0);
|
||||
});
|
||||
|
||||
@ -130,14 +122,9 @@ describe("Default appearance", function () {
|
||||
fontName: "Helv",
|
||||
fontColor: new Uint8ClampedArray([237, 43, 112]),
|
||||
};
|
||||
expect(
|
||||
parseAppearanceStream(
|
||||
appearance,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
globalColorSpaceCache
|
||||
)
|
||||
).toEqual(result);
|
||||
expect(parseAppearanceStream(appearance, evaluatorOptions, xref)).toEqual(
|
||||
result
|
||||
);
|
||||
expect(appearance.pos).toEqual(0);
|
||||
});
|
||||
|
||||
@ -172,14 +159,9 @@ describe("Default appearance", function () {
|
||||
fontName: "TT1",
|
||||
fontColor: new Uint8ClampedArray([135, 78, 254]),
|
||||
};
|
||||
expect(
|
||||
parseAppearanceStream(
|
||||
appearance,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
globalColorSpaceCache
|
||||
)
|
||||
).toEqual(result);
|
||||
expect(parseAppearanceStream(appearance, evaluatorOptions, xref)).toEqual(
|
||||
result
|
||||
);
|
||||
expect(appearance.pos).toEqual(0);
|
||||
});
|
||||
|
||||
@ -200,14 +182,9 @@ describe("Default appearance", function () {
|
||||
fontName: "Helv",
|
||||
fontColor: new Uint8ClampedArray([16, 124, 16]),
|
||||
};
|
||||
expect(
|
||||
parseAppearanceStream(
|
||||
appearance,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
globalColorSpaceCache
|
||||
)
|
||||
).toEqual(result);
|
||||
expect(parseAppearanceStream(appearance, evaluatorOptions, xref)).toEqual(
|
||||
result
|
||||
);
|
||||
expect(appearance.pos).toEqual(0);
|
||||
});
|
||||
|
||||
@ -231,14 +208,9 @@ describe("Default appearance", function () {
|
||||
fontName: "FXF0",
|
||||
fontColor: new Uint8ClampedArray([149, 63, 60]),
|
||||
};
|
||||
expect(
|
||||
parseAppearanceStream(
|
||||
appearance,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
globalColorSpaceCache
|
||||
)
|
||||
).toEqual(result);
|
||||
expect(parseAppearanceStream(appearance, evaluatorOptions, xref)).toEqual(
|
||||
result
|
||||
);
|
||||
expect(appearance.pos).toEqual(0);
|
||||
});
|
||||
|
||||
@ -260,14 +232,9 @@ describe("Default appearance", function () {
|
||||
fontName: "Invalid_font",
|
||||
fontColor: new Uint8ClampedArray([0, 85, 127]),
|
||||
};
|
||||
expect(
|
||||
parseAppearanceStream(
|
||||
appearance,
|
||||
evaluatorOptions,
|
||||
xref,
|
||||
globalColorSpaceCache
|
||||
)
|
||||
).toEqual(result);
|
||||
expect(parseAppearanceStream(appearance, evaluatorOptions, xref)).toEqual(
|
||||
result
|
||||
);
|
||||
expect(appearance.pos).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user