Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump fontkit and linebreak deps #1367

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Simple example of using PdfKit with webpack
[`webpack.config.js`](webpack.config.js)

- add alias to map `fs` calls to pdfkit virtual file system [implementation](../../lib/virtual-fs.js)
- ignore iconv-lite and crypto packages to save bundle file size
- ignore crypto package to save bundle file size
- add aliases to native node packages (buffer, stream, zlib, util, assert)
- configure `*.afm` files to be imported as text
- configure all files in `src/static-assets` folder to be imported encoded as base64
Expand Down
1 change: 0 additions & 1 deletion examples/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"util": "^0.12.5"
},
"devDependencies": {
"brfs": "^2.0.2",
"html-webpack-plugin": "^5.6.0",
"transform-loader": "^0.2.4",
"webpack": "^5.91.0",
Expand Down
22 changes: 2 additions & 20 deletions examples/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ module.exports = {
})
],
resolve: {
symlinks: false,
alias: {
// maps fs to a virtual one allowing to register file content dynamically
fs: 'pdfkit/js/virtual-fs.js',
// iconv-lite is used to load cid less fonts (not spec compliant)
'iconv-lite': false
fs: __dirname + '/../../js/virtual-fs.js'
},
fallback: {
// crypto module is not necessary at browser
Expand Down Expand Up @@ -48,23 +47,6 @@ module.exports = {
{
test: /src[/\\]lazy-assets/,
type: 'asset/resource'
},
// convert to base64 and include inline file system binary files used by fontkit and linebreak
{
enforce: 'post',
test: /fontkit[/\\]index.js$/,
loader: 'transform-loader',
options: {
brfs: {}
}
},
{
enforce: 'post',
test: /linebreak[/\\]src[/\\]linebreaker.js/,
loader: 'transform-loader',
options: {
brfs: {}
}
}
]
}
Expand Down
5 changes: 1 addition & 4 deletions lib/font/embedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ class EmbeddedFont extends PDFFont {
fontFile.data.Subtype = 'CIDFontType0C';
}

this.subset
.encodeStream()
.on('data', data => fontFile.write(data))
.on('end', () => fontFile.end());
fontFile.end(this.subset.encode());

const familyClass =
((this.font['OS/2'] != null
Expand Down
8 changes: 3 additions & 5 deletions lib/font_factory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import fontkit from 'fontkit';
import * as fontkit from 'fontkit';
import StandardFont from './font/standard';
import EmbeddedFont from './font/embedded';

Expand All @@ -13,12 +13,10 @@ class PDFFontFactory {

src = fs.readFileSync(src);
}
if (Buffer.isBuffer(src)) {
if (src instanceof Uint8Array) {
font = fontkit.create(src, family);
} else if (src instanceof Uint8Array) {
font = fontkit.create(Buffer.from(src), family);
} else if (src instanceof ArrayBuffer) {
font = fontkit.create(Buffer.from(new Uint8Array(src)), family);
font = fontkit.create(new Uint8Array(src), family);
}

if (font == null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PDFReference extends PDFAbstractReference {
}

write(chunk) {
if (!Buffer.isBuffer(chunk)) {
if (!(chunk instanceof Uint8Array)) {
chunk = Buffer.from(chunk + '\n', 'binary');
}

Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
"codemirror": "~5.49.2",
"eslint": "^7.8.1",
"gh-pages": "^3.1.0",
"iconv-lite": "^0.5.0",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.4.3",
"jest-image-snapshot": "^6.1.0",
"markdown": "~0.5.0",
"pdfjs-dist": "^2.4.456",
"pdfjs-dist": "^2.14.305",
"prettier": "1.19.1",
"pug": "^2.0.4",
"rollup": "^1.27.0",
Expand All @@ -49,25 +48,25 @@
},
"dependencies": {
"crypto-js": "^4.2.0",
"fontkit": "^1.8.1",
"fontkit": "^2.0.4",
"jpeg-exif": "^1.1.4",
"linebreak": "^1.0.2",
"linebreak": "^1.1.0",
"png-js": "^1.0.0"
},
"scripts": {
"prepublishOnly": "npm run build",
"build": "rollup -c && npm run build-standalone",
"build-standalone": "browserify --standalone PDFDocument --ignore crypto --ignore iconv-lite js/pdfkit.js > js/pdfkit.standalone.js",
"build-standalone": "browserify --standalone PDFDocument --ignore crypto js/pdfkit.js > js/pdfkit.standalone.js",
"browserify-example": "browserify examples/browserify/browser.js > examples/browserify/bundle.js",
"pdf-guide": "node docs/generate.js",
"website": "node docs/generate_website.js",
"publish-website": "node docs/publish_website.js",
"docs": "npm run pdf-guide && npm run website && npm run browserify-example",
"lint": "eslint {lib,tests}/**/*.js",
"prettier": "prettier {lib,tests,examples,docs}/**/*.js",
"test": "jest -i",
"test:visual": "jest visual/ -i",
"test:unit": "jest unit/"
"test": "jest -i --env=node",
"test:visual": "jest visual/ -i --env=node",
"test:unit": "jest unit/ --env=node"
},
"main": "js/pdfkit.js",
"module": "js/pdfkit.es.js",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 11 additions & 7 deletions tests/visual/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@ function runDocTest(options, fn) {
options.info = {};
}

return new Promise(resolve => {
return new Promise((resolve, reject) => {
const doc = new PDFDocument(options);
const buffers = [];

fn(doc);

doc.on('data', buffers.push.bind(buffers));
doc.on('end', async () => {
const pdfData = Buffer.concat(buffers);
const { systemFonts = false } = options;
const images = await pdf2png(pdfData, { systemFonts });
for (let image of images) {
expect(image).toMatchImageSnapshot();
try {
const pdfData = Buffer.concat(buffers);
const { systemFonts = false } = options;
const images = await pdf2png(pdfData, { systemFonts });
for (let image of images) {
expect(image).toMatchImageSnapshot();
}
resolve();
} catch (err) {
reject(err)
}
resolve();
});
doc.end();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/visual/pdf2png.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Canvas from 'canvas';
import { strict as assert } from 'assert';
import * as pdfjsLib from 'pdfjs-dist/es5/build/pdf';
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf';

// adapted from https://github.com/mozilla/pdf.js/tree/master/examples/node/pdf2png

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading