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 6 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v2
Expand Down
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.4"
},
"devDependencies": {
"brfs": "^2.0.2",
"html-webpack-plugin": "^5.3.2",
"transform-loader": "^0.2.4",
"webpack": "^5.44.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 @@ -31,15 +31,14 @@
"brace": "^0.11.1",
"brfs": "~2.0.2",
"browserify": "^16.5.0",
"canvas": "^2.6.1",
"canvas": "^2.9.1",
"codemirror": "~5.49.2",
"eslint": "^7.8.1",
"gh-pages": "^3.1.0",
"iconv-lite": "^0.5.0",
"jest": "^26.4.2",
"jest-screenshot": "^0.3.1",
"jest": "^28.1.1",
"jest-screenshot": "^0.3.5",
"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 @@ -48,13 +47,13 @@
},
"dependencies": {
"crypto-js": "^4.0.0",
"fontkit": "^1.8.1",
"linebreak": "^1.0.2",
"fontkit": "^2.0.2",
"linebreak": "^1.1.0",
"png-js": "^1.0.0"
},
"scripts": {
"prepublishOnly": "npm run build",
"build": "rollup -c && browserify --standalone PDFDocument --ignore crypto --ignore iconv-lite js/pdfkit.js > js/pdfkit.standalone.js",
"build": "rollup -c && 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",
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.