: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
widthCode = this.cMap.lookup(charcode);
if (typeof widthCode === "string") {
widthCode = convertCidString(charcode, widthCode);
width = this.widths[widthCode];
if (typeof width !== "number") {
width = this.defaultWidth;
const vmetric = this.vmetrics?.[widthCode];
let unicode = this.toUnicode.get(charcode) || charcode;
if (typeof unicode === "number") {
unicode = String.fromCharCode(unicode);
let isInFont = this.toFontChar[charcode] !== undefined;
fontCharCode = this.toFontChar[charcode] || charcode;
const glyphName = this.differences[charcode] || this.defaultEncoding[charcode];
if ((glyphName === ".notdef" || glyphName === "") && this.type === "Type1") {
fontCharCode = mapSpecialUnicodeValues(fontCharCode);
operatorListId = fontCharCode;
if (this.seacMap?.[charcode]) {
const seac = this.seacMap[charcode];
fontCharCode = seac.baseFontCharCode;
fontChar: String.fromCodePoint(seac.accentFontCharCode),
offset: seac.accentOffset
if (typeof fontCharCode === "number") {
if (fontCharCode <= 0x10ffff) {
fontChar = String.fromCodePoint(fontCharCode);
warn(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
glyph = new fonts_Glyph(charcode, fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
return this._glyphCache[charcode] = glyph;
let glyphs = this._charsCache[chars];
const c = Object.create(null),
this.cMap.readCharCode(chars, i, c);
const glyph = this._charToGlyph(charcode, length === 1 && chars.charCodeAt(i - 1) === 0x20);
for (let i = 0, ii = chars.length; i < ii; ++i) {
const charcode = chars.charCodeAt(i);
const glyph = this._charToGlyph(charcode, charcode === 0x20);
return this._charsCache[chars] = glyphs;
getCharPositions(chars) {
const c = Object.create(null);
while (i < chars.length) {
this.cMap.readCharCode(chars, i, c);
positions.push([i, i + length]);
for (let i = 0, ii = chars.length; i < ii; ++i) {
positions.push([i, i + 1]);
return Object.values(this._glyphCache);
const hasCurrentBufErrors = () => buffers.length % 2 === 1;
const getCharCode = this.toUnicode instanceof IdentityToUnicodeMap ? unicode => this.toUnicode.charCodeOf(unicode) : unicode => this.toUnicode.charCodeOf(String.fromCodePoint(unicode));
for (let i = 0, ii = str.length; i < ii; i++) {
const unicode = str.codePointAt(i);
if (unicode > 0xd7ff && (unicode < 0xe000 || unicode > 0xfffd)) {
const charCode = getCharCode(unicode);
if (hasCurrentBufErrors()) {
buffers.push(currentBuf.join(""));
const charCodeLength = this.cMap ? this.cMap.getCharCodeLength(charCode) : 1;
for (let j = charCodeLength - 1; j >= 0; j--) {
currentBuf.push(String.fromCharCode(charCode >> 8 * j & 0xff));
if (!hasCurrentBufErrors()) {
buffers.push(currentBuf.join(""));
currentBuf.push(String.fromCodePoint(unicode));
buffers.push(currentBuf.join(""));
this.loadedName = "g_font_error";
exportData(extraProperties = false) {
;// CONCATENATED MODULE: ./src/core/pattern.js
unreachable("Cannot initialize Pattern.");
static parseShading(shading, xref, res, pdfFunctionFactory, localColorSpaceCache) {
const dict = shading instanceof BaseStream ? shading.dict : shading;
const type = dict.get("ShadingType");
return new RadialAxialShading(dict, xref, res, pdfFunctionFactory, localColorSpaceCache);
case ShadingType.FREE_FORM_MESH:
case ShadingType.LATTICE_FORM_MESH:
case ShadingType.COONS_PATCH_MESH:
case ShadingType.TENSOR_PATCH_MESH:
return new MeshShading(shading, xref, res, pdfFunctionFactory, localColorSpaceCache);
throw new FormatError("Unsupported ShadingType: " + type);
if (ex instanceof MissingDataException) {
return new DummyShading();
static SMALL_NUMBER = 1e-6;
if (this.constructor === BaseShading) {
unreachable("Cannot initialize BaseShading.");
unreachable("Abstract method `getIR` called.");
class RadialAxialShading extends BaseShading {
constructor(dict, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
this.shadingType = dict.get("ShadingType");
if (this.shadingType === ShadingType.AXIAL) {
} else if (this.shadingType === ShadingType.RADIAL) {
this.coordsArr = dict.getArray("Coords");
if (!isNumberArray(this.coordsArr, coordsLen)) {
throw new FormatError("RadialAxialShading: Invalid /Coords array.");
const cs = ColorSpace.parse({
cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
this.bbox = lookupNormalRect(dict.getArray("BBox"), null);
const domainArr = dict.getArray("Domain");
if (isNumberArray(domainArr, 2)) {
const extendArr = dict.getArray("Extend");
if (isBooleanArray(extendArr, 2)) {
[extendStart, extendEnd] = extendArr;
if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
const [x1, y1, r1, x2, y2, r2] = this.coordsArr;
const distance = Math.hypot(x1 - x2, y1 - y2);
if (r1 <= r2 + distance && r2 <= r1 + distance) {
warn("Unsupported radial gradient.");
this.extendStart = extendStart;
this.extendEnd = extendEnd;
const fnObj = dict.getRaw("Function");
const fn = pdfFunctionFactory.createFromArray(fnObj);
const NUMBER_OF_SAMPLES = 840;
const step = (t1 - t0) / NUMBER_OF_SAMPLES;
const colorStops = this.colorStops = [];
if (t0 >= t1 || step <= 0) {
info("Bad shading domain.");
const color = new Float32Array(cs.numComps),
ratio = new Float32Array(1);
let rgbBase = cs.getRgb(color, 0);
const cssColorBase = Util.makeHexColor(rgbBase[0], rgbBase[1], rgbBase[2]);
colorStops.push([0, cssColorBase]);
let rgbPrev = cs.getRgb(color, 0);
let maxSlopeR = rgbPrev[0] - rgbBase[0] + 1;
let maxSlopeG = rgbPrev[1] - rgbBase[1] + 1;
let maxSlopeB = rgbPrev[2] - rgbBase[2] + 1;
let minSlopeR = rgbPrev[0] - rgbBase[0] - 1;
let minSlopeG = rgbPrev[1] - rgbBase[1] - 1;
let minSlopeB = rgbPrev[2] - rgbBase[2] - 1;
for (let i = 2; i < NUMBER_OF_SAMPLES; i++) {
ratio[0] = t0 + i * step;
rgbColor = cs.getRgb(color, 0);
maxSlopeR = Math.min(maxSlopeR, (rgbColor[0] - rgbBase[0] + 1) / run);
maxSlopeG = Math.min(maxSlopeG, (rgbColor[1] - rgbBase[1] + 1) / run);
maxSlopeB = Math.min(maxSlopeB, (rgbColor[2] - rgbBase[2] + 1) / run);
minSlopeR = Math.max(minSlopeR, (rgbColor[0] - rgbBase[0] - 1) / run);
minSlopeG = Math.max(minSlopeG, (rgbColor[1] - rgbBase[1] - 1) / run);
minSlopeB = Math.max(minSlopeB, (rgbColor[2] - rgbBase[2] - 1) / run);
const slopesExist = minSlopeR <= maxSlopeR && minSlopeG <= maxSlopeG && minSlopeB <= maxSlopeB;
const cssColor = Util.makeHexColor(rgbPrev[0], rgbPrev[1], rgbPrev[2]);
colorStops.push([iPrev / NUMBER_OF_SAMPLES, cssColor]);
maxSlopeR = rgbColor[0] - rgbPrev[0] + 1;
maxSlopeG = rgbColor[1] - rgbPrev[1] + 1;
maxSlopeB = rgbColor[2] - rgbPrev[2] + 1;
minSlopeR = rgbColor[0] - rgbPrev[0] - 1;
minSlopeG = rgbColor[1] - rgbPrev[1] - 1;
minSlopeB = rgbColor[2] - rgbPrev[2] - 1;
const cssColor = Util.makeHexColor(rgbPrev[0], rgbPrev[1], rgbPrev[2]);
colorStops.push([1, cssColor]);
let background = "transparent";
if (dict.has("Background")) {
rgbColor = cs.getRgb(dict.get("Background"), 0);
background = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
colorStops.unshift([0, background]);
colorStops[1][0] += BaseShading.SMALL_NUMBER;
colorStops.at(-1)[0] -= BaseShading.SMALL_NUMBER;
colorStops.push([1, background]);
this.colorStops = colorStops;
let type, p0, p1, r0, r1;
if (shadingType === ShadingType.AXIAL) {
p0 = [coordsArr[0], coordsArr[1]];
p1 = [coordsArr[2], coordsArr[3]];
} else if (shadingType === ShadingType.RADIAL) {
p0 = [coordsArr[0], coordsArr[1]];
p1 = [coordsArr[3], coordsArr[4]];
unreachable(`getPattern type unknown: ${shadingType}`);
return ["RadialAxial", type, this.bbox, this.colorStops, p0, p1, r0, r1];
constructor(stream, context) {
const numComps = context.numComps;
this.tmpCompsBuf = new Float32Array(numComps);
const csNumComps = context.colorSpace.numComps;
this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
return this.stream.pos < this.stream.end;
if (this.bufferLength > 0) {
const nextByte = this.stream.getByte();
let buffer = this.buffer;
let bufferLength = this.bufferLength;
if (bufferLength === 0) {
return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
const nextByte = this.stream.getByte();
this.buffer = nextByte & (1 << bufferLength) - 1;
return (buffer << 8 - bufferLength | (nextByte & 0xff) >> bufferLength) >>> 0;
if (n === 8 && bufferLength === 0) {
return this.stream.getByte();
while (bufferLength < n) {
buffer = buffer << 8 | this.stream.getByte();
this.bufferLength = bufferLength;
this.buffer = buffer & (1 << bufferLength) - 1;
return buffer >> bufferLength;
return this.readBits(this.context.bitsPerFlag);
const bitsPerCoordinate = this.context.bitsPerCoordinate;
const xi = this.readBits(bitsPerCoordinate);
const yi = this.readBits(bitsPerCoordinate);
const decode = this.context.decode;
const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
return [xi * scale * (decode[1] - decode[0]) + decode[0], yi * scale * (decode[3] - decode[2]) + decode[2]];
const numComps = this.context.numComps;
const bitsPerComponent = this.context.bitsPerComponent;
const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
const decode = this.context.decode;
const components = this.tmpCompsBuf;
for (let i = 0, j = 4; i < numComps; i++, j += 2) {
const ci = this.readBits(bitsPerComponent);
components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
const color = this.tmpCsCompsBuf;
if (this.context.colorFn) {
this.context.colorFn(components, 0, color, 0);
return this.context.colorSpace.getRgb(color, 0);
let bCache = Object.create(null);
for (let i = 0; i <= count; i++) {
lut.push(new Float32Array([t_ ** 3, 3 * t * t_ ** 2, 3 * t ** 2 * t_, t ** 3]));
return bCache[count] ||= buildB(count);
function clearPatternCaches() {
bCache = Object.create(null);
class MeshShading extends BaseShading {
static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
static TRIANGLE_DENSITY = 20;
constructor(stream, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
if (!(stream instanceof BaseStream)) {
throw new FormatError("Mesh data is not a stream");
const dict = stream.dict;
this.shadingType = dict.get("ShadingType");
this.bbox = lookupNormalRect(dict.getArray("BBox"), null);
const cs = ColorSpace.parse({
cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
this.background = dict.has("Background") ? cs.getRgb(dict.get("Background"), 0) : null;
const fnObj = dict.getRaw("Function");
const fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null;
bitsPerCoordinate: dict.get("BitsPerCoordinate"),
bitsPerComponent: dict.get("BitsPerComponent"),
bitsPerFlag: dict.get("BitsPerFlag"),
decode: dict.getArray("Decode"),
numComps: fn ? 1 : cs.numComps
const reader = new MeshStreamReader(stream, decodeContext);
switch (this.shadingType) {
case ShadingType.FREE_FORM_MESH:
this._decodeType4Shading(reader);
case ShadingType.LATTICE_FORM_MESH:
const verticesPerRow = dict.get("VerticesPerRow") | 0;
if (verticesPerRow < 2) {
throw new FormatError("Invalid VerticesPerRow");
this._decodeType5Shading(reader, verticesPerRow);
case ShadingType.COONS_PATCH_MESH:
this._decodeType6Shading(reader);
case ShadingType.TENSOR_PATCH_MESH: