Socket
Socket
Sign inDemoInstall

pdfkit

Package Overview
Dependencies
1
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.7 to 0.1.8

6

js/font/directory.js

@@ -68,5 +68,5 @@ (function() {

checksum = function(_arg) {
var data, i, sum, tmp, _ref;
data = 1 <= _arg.length ? __slice.call(_arg, 0) : [];
checksum = function(data) {
var i, sum, tmp, _ref;
data = __slice.call(data);
while (data.length % 4) {

@@ -73,0 +73,0 @@ data.push(0);

(function() {
var Data, PNG, fs, zlib;
var PNG, PNGImage, zlib;
fs = require('fs');
zlib = require('zlib');
Data = '../data';
PNG = require('png-js');
zlib = require('zlib');
PNGImage = (function() {
PNG = (function() {
function PNG(data) {
var chunkSize, colors, i, section, short, _ref;
this.data = data;
data.pos = 8;
this.palette = [];
this.imgData = [];
this.transparency = {};
while (true) {
chunkSize = data.readUInt32();
section = data.readString(4);
switch (section) {
case 'IHDR':
this.width = data.readUInt32();
this.height = data.readUInt32();
this.bits = data.readByte();
this.colorType = data.readByte();
this.compressionMethod = data.readByte();
this.filterMethod = data.readByte();
this.interlaceMethod = data.readByte();
break;
case 'PLTE':
this.palette = data.read(chunkSize);
break;
case 'IDAT':
for (i = 0; 0 <= chunkSize ? i < chunkSize : i > chunkSize; 0 <= chunkSize ? i++ : i--) {
this.imgData.push(data.readByte());
}
break;
case 'tRNS':
this.transparency = {};
switch (this.colorType) {
case 3:
this.transparency.indexed = data.read(chunkSize);
short = 255 - this.transparency.indexed.length;
if (short > 0) {
for (i = 0; 0 <= short ? i < short : i > short; 0 <= short ? i++ : i--) {
this.transparency.indexed.push(255);
}
}
break;
case 0:
this.transparency.grayscale = data.read(chunkSize)[0];
break;
case 2:
this.transparency.rgb = data.read(chunkSize);
}
break;
case 'IEND':
this.colors = (function() {
switch (this.colorType) {
case 0:
case 3:
case 4:
return 1;
case 2:
case 6:
return 3;
}
}).call(this);
this.hasAlphaChannel = (_ref = this.colorType) === 4 || _ref === 6;
colors = this.colors + (this.hasAlphaChannel ? 1 : 0);
this.pixelBitlength = this.bits * colors;
this.colorSpace = (function() {
switch (this.colors) {
case 1:
return 'DeviceGray';
case 3:
return 'DeviceRGB';
}
}).call(this);
this.imgData = new Buffer(this.imgData);
return;
default:
data.pos += chunkSize;
}
data.pos += 4;
}
return;
function PNGImage(data) {
this.image = new PNG(data.data);
this.width = this.image.width;
this.height = this.image.height;
this.imgData = this.image.imgData;
}
PNG.prototype.object = function(document, fn) {
PNGImage.prototype.object = function(document, fn) {
var mask, obj, palette, rgb, sMask, val, x, _i, _len;
var _this = this;
if (!this.alphaChannel) {
if (this.transparency.indexed) {
if (this.image.transparency.indexed) {
this.loadIndexedAlphaChannel(function() {

@@ -101,3 +26,3 @@ return _this.object(document, fn);

return;
} else if (this.hasAlphaChannel) {
} else if (this.image.hasAlphaChannel) {
this.splitAlphaChannel(function() {

@@ -112,3 +37,3 @@ return _this.object(document, fn);

Subtype: 'Image',
BitsPerComponent: this.bits,
BitsPerComponent: this.image.bits,
Width: this.width,

@@ -119,24 +44,24 @@ Height: this.height,

});
if (!this.hasAlphaChannel) {
obj.data['DecodeParms'] = {
if (!this.image.hasAlphaChannel) {
obj.data['DecodeParms'] = document.ref({
Predictor: 15,
Colors: this.colors,
BitsPerComponent: this.bits,
Colors: this.image.colors,
BitsPerComponent: this.image.bits,
Columns: this.width
};
});
}
if (this.palette.length === 0) {
obj.data['ColorSpace'] = this.colorSpace;
if (this.image.palette.length === 0) {
obj.data['ColorSpace'] = this.image.colorSpace;
} else {
palette = document.ref({
Length: this.palette.length
Length: this.image.palette.length
});
palette.add(new Buffer(this.palette));
obj.data['ColorSpace'] = ['Indexed', 'DeviceRGB', (this.palette.length / 3) - 1, palette];
palette.add(new Buffer(this.image.palette));
obj.data['ColorSpace'] = ['Indexed', 'DeviceRGB', (this.image.palette.length / 3) - 1, palette];
}
if (this.transparency.grayscale) {
val = this.transparency.greyscale;
if (this.image.transparency.grayscale) {
val = this.image.transparency.greyscale;
obj.data['Mask'] = [val, val];
} else if (this.transparency.rgb) {
rgb = this.transparency.rgb;
} else if (this.image.transparency.rgb) {
rgb = this.image.transparency.rgb;
mask = [];

@@ -168,105 +93,17 @@ for (_i = 0, _len = rgb.length; _i < _len; _i++) {

PNG.prototype.decodePixels = function(fn) {
PNGImage.prototype.splitAlphaChannel = function(fn) {
var _this = this;
return zlib.inflate(this.imgData, function(err, data) {
var byte, col, filter, i, left, length, p, pa, paeth, pb, pc, pixelBytes, pixels, pos, row, rowData, s, scanlineLength, upper, upperLeft, _ref;
if (err) throw err;
pixelBytes = _this.pixelBitlength / 8;
scanlineLength = pixelBytes * _this.width;
row = 0;
pixels = [];
length = data.length;
pos = 0;
while (pos < length) {
filter = data[pos++];
i = 0;
rowData = [];
switch (filter) {
case 0:
while (i < scanlineLength) {
rowData[i++] = data[pos++];
}
break;
case 1:
while (i < scanlineLength) {
byte = data[pos++];
left = i < pixelBytes ? 0 : rowData[i - pixelBytes];
rowData[i++] = (byte + left) % 256;
}
break;
case 2:
while (i < scanlineLength) {
byte = data[pos++];
col = (i - (i % pixelBytes)) / pixelBytes;
upper = row === 0 ? 0 : pixels[row - 1][col][i % pixelBytes];
rowData[i++] = (upper + byte) % 256;
}
break;
case 3:
while (i < scanlineLength) {
byte = data[pos++];
col = (i - (i % pixelBytes)) / pixelBytes;
left = i < pixelBytes ? 0 : rowData[i - pixelBytes];
upper = row === 0 ? 0 : pixels[row - 1][col][i % pixelBytes];
rowData[i++] = (byte + Math.floor((left + upper) / 2)) % 256;
}
break;
case 4:
while (i < scanlineLength) {
byte = data[pos++];
col = (i - (i % pixelBytes)) / pixelBytes;
left = i < pixelBytes ? 0 : rowData[i - pixelBytes];
if (row === 0) {
upper = upperLeft = 0;
} else {
upper = pixels[row - 1][col][i % pixelBytes];
upperLeft = col === 0 ? 0 : pixels[row - 1][col - 1][i % pixelBytes];
}
p = left + upper - upperLeft;
pa = Math.abs(p - left);
pb = Math.abs(p - upper);
pc = Math.abs(p - upperLeft);
if (pa <= pb && pa <= pc) {
paeth = left;
} else if (pb <= pc) {
paeth = upper;
} else {
paeth = upperLeft;
}
rowData[i++] = (byte + paeth) % 256;
}
break;
default:
throw new Error("Invalid filter algorithm: " + filter);
}
s = [];
for (i = 0, _ref = rowData.length; 0 <= _ref ? i < _ref : i > _ref; i += pixelBytes) {
s.push(rowData.slice(i, i + pixelBytes));
}
pixels.push(s);
row += 1;
}
return fn(pixels);
});
};
PNG.prototype.splitAlphaChannel = function(fn) {
var _this = this;
return this.decodePixels(function(pixels) {
var a, alphaByteSize, alphaChannel, colorByteSize, done, i, imgData, p, pixel, pixelCount, row, _i, _j, _len, _len2;
colorByteSize = _this.colors * _this.bits / 8;
alphaByteSize = 1;
return this.image.decodePixels(function(pixels) {
var a, alphaChannel, colorByteSize, done, i, imgData, len, p, pixelCount;
colorByteSize = _this.image.colors * _this.image.bits / 8;
pixelCount = _this.width * _this.height;
imgData = new Buffer(pixelCount * colorByteSize);
alphaChannel = new Buffer(pixelCount);
p = a = 0;
for (_i = 0, _len = pixels.length; _i < _len; _i++) {
row = pixels[_i];
for (_j = 0, _len2 = row.length; _j < _len2; _j++) {
pixel = row[_j];
for (i = 0; 0 <= colorByteSize ? i < colorByteSize : i > colorByteSize; 0 <= colorByteSize ? i++ : i--) {
imgData[p++] = pixel[i];
}
alphaChannel[a++] = pixel[colorByteSize];
}
i = p = a = 0;
len = pixels.length;
while (i < len) {
imgData[p++] = pixels[i++];
imgData[p++] = pixels[i++];
imgData[p++] = pixels[i++];
alphaChannel[a++] = pixels[i++];
}

@@ -287,32 +124,12 @@ done = 0;

PNG.prototype.decodePalette = function() {
var alpha, decodingMap, i, index, palette, pixel, transparency, _ref, _ref2, _ref3;
palette = this.palette;
transparency = (_ref = this.transparency.indexed) != null ? _ref : [];
decodingMap = [];
index = 0;
for (i = 0, _ref2 = palette.length; i < _ref2; i += 3) {
alpha = (_ref3 = transparency[index++]) != null ? _ref3 : 255;
pixel = palette.slice(i, i + 3).concat(alpha);
decodingMap.push(pixel);
}
return decodingMap;
};
PNG.prototype.loadIndexedAlphaChannel = function(fn) {
var palette;
PNGImage.prototype.loadIndexedAlphaChannel = function(fn) {
var transparency;
var _this = this;
palette = this.decodePalette();
return this.decodePixels(function(pixels) {
var alphaChannel, i, pixel, pixelCount, row, _i, _j, _len, _len2;
pixelCount = _this.width * _this.height;
alphaChannel = new Buffer(pixelCount);
transparency = this.image.transparency.indexed;
return this.image.decodePixels(function(pixels) {
var alphaChannel, i, j, _ref;
alphaChannel = new Buffer(_this.width * _this.height);
i = 0;
for (_i = 0, _len = pixels.length; _i < _len; _i++) {
row = pixels[_i];
for (_j = 0, _len2 = row.length; _j < _len2; _j++) {
pixel = row[_j];
pixel = pixel[0];
alphaChannel[i++] = palette[pixel][3];
}
for (j = 0, _ref = pixels.length; j < _ref; j += 1) {
alphaChannel[i++] = transparency[pixels[j]];
}

@@ -327,8 +144,8 @@ return zlib.deflate(alphaChannel, function(err, alphaChannel) {

return PNG;
return PNGImage;
})();
module.exports = PNG;
module.exports = PNGImage;
}).call(this);

@@ -5,3 +5,3 @@ {

"keywords": ["pdf", "pdf writer", "pdf generator", "graphics", "document", "vector"],
"version": "0.1.7",
"version": "0.1.8",
"homepage": "http://pdfkit.org/",

@@ -25,2 +25,5 @@ "author": {

},
"dependencies": {
"png-js": ">=0.1.0"
},
"scripts": {

@@ -27,0 +30,0 @@ "prepublish": "coffee -o js -c lib/ && cp -r lib/font/data js/font/data",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc