Skip to content

Commit f238d1b

Browse files
Bump fontkit and linebreak deps (#1367)
* Bump fontkit and linebreak deps * Bump fontkit to 2.0.0 * Bump * Drop old node versions * Bump testing dependencies * Update pdfjs * fix jest to compatibility with restructure, update fontkit, refresh snapshots * Update CHANGELOG.md --------- Co-authored-by: Libor M. <liborm85@gmail.com>
1 parent 76caaa6 commit f238d1b

41 files changed

Lines changed: 1151 additions & 1474 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## pdfkit changelog
22

3+
### Unreleased
4+
5+
- Update fontkit to 2.0
6+
- Update linebreak to 1.1
7+
38
### [v0.15.2] - 2024-12-15
49

510
- Fix index not counting when rendering ordered lists (#1517)

examples/webpack/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Simple example of using PdfKit with webpack
1414
[`webpack.config.js`](webpack.config.js)
1515

1616
- add alias to map `fs` calls to pdfkit virtual file system [implementation](../../lib/virtual-fs.js)
17-
- ignore iconv-lite and crypto packages to save bundle file size
17+
- ignore crypto package to save bundle file size
1818
- add aliases to native node packages (buffer, stream, zlib, util, assert)
1919
- configure `*.afm` files to be imported as text
2020
- configure all files in `src/static-assets` folder to be imported encoded as base64

examples/webpack/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"util": "^0.12.5"
1212
},
1313
"devDependencies": {
14-
"brfs": "^2.0.2",
1514
"html-webpack-plugin": "^5.6.0",
1615
"transform-loader": "^0.2.4",
1716
"webpack": "^5.91.0",

examples/webpack/webpack.config.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ module.exports = {
1313
})
1414
],
1515
resolve: {
16+
symlinks: false,
1617
alias: {
1718
// maps fs to a virtual one allowing to register file content dynamically
18-
fs: 'pdfkit/js/virtual-fs.js',
19-
// iconv-lite is used to load cid less fonts (not spec compliant)
20-
'iconv-lite': false
19+
fs: __dirname + '/../../js/virtual-fs.js'
2120
},
2221
fallback: {
2322
// crypto module is not necessary at browser
@@ -48,23 +47,6 @@ module.exports = {
4847
{
4948
test: /src[/\\]lazy-assets/,
5049
type: 'asset/resource'
51-
},
52-
// convert to base64 and include inline file system binary files used by fontkit and linebreak
53-
{
54-
enforce: 'post',
55-
test: /fontkit[/\\]index.js$/,
56-
loader: 'transform-loader',
57-
options: {
58-
brfs: {}
59-
}
60-
},
61-
{
62-
enforce: 'post',
63-
test: /linebreak[/\\]src[/\\]linebreaker.js/,
64-
loader: 'transform-loader',
65-
options: {
66-
brfs: {}
67-
}
6850
}
6951
]
7052
}

lib/font/embedded.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ class EmbeddedFont extends PDFFont {
128128
fontFile.data.Subtype = 'CIDFontType0C';
129129
}
130130

131-
this.subset
132-
.encodeStream()
133-
.on('data', data => fontFile.write(data))
134-
.on('end', () => fontFile.end());
131+
fontFile.end(this.subset.encode());
135132

136133
const familyClass =
137134
((this.font['OS/2'] != null

lib/font_factory.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import fontkit from 'fontkit';
2+
import * as fontkit from 'fontkit';
33
import StandardFont from './font/standard';
44
import EmbeddedFont from './font/embedded';
55

@@ -13,12 +13,10 @@ class PDFFontFactory {
1313

1414
src = fs.readFileSync(src);
1515
}
16-
if (Buffer.isBuffer(src)) {
16+
if (src instanceof Uint8Array) {
1717
font = fontkit.create(src, family);
18-
} else if (src instanceof Uint8Array) {
19-
font = fontkit.create(Buffer.from(src), family);
2018
} else if (src instanceof ArrayBuffer) {
21-
font = fontkit.create(Buffer.from(new Uint8Array(src)), family);
19+
font = fontkit.create(new Uint8Array(src), family);
2220
}
2321

2422
if (font == null) {

lib/reference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PDFReference extends PDFAbstractReference {
2020
}
2121

2222
write(chunk) {
23-
if (!Buffer.isBuffer(chunk)) {
23+
if (!(chunk instanceof Uint8Array)) {
2424
chunk = Buffer.from(chunk + '\n', 'binary');
2525
}
2626

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@
3535
"codemirror": "~5.49.2",
3636
"eslint": "^7.8.1",
3737
"gh-pages": "^3.1.0",
38-
"iconv-lite": "^0.5.0",
3938
"jest": "^29.4.3",
4039
"jest-environment-jsdom": "^29.4.3",
4140
"jest-image-snapshot": "^6.1.0",
4241
"markdown": "~0.5.0",
43-
"pdfjs-dist": "^2.4.456",
42+
"pdfjs-dist": "^2.14.305",
4443
"prettier": "1.19.1",
4544
"pug": "^2.0.4",
4645
"rollup": "^1.27.0",
@@ -49,25 +48,25 @@
4948
},
5049
"dependencies": {
5150
"crypto-js": "^4.2.0",
52-
"fontkit": "^1.8.1",
51+
"fontkit": "^2.0.4",
5352
"jpeg-exif": "^1.1.4",
54-
"linebreak": "^1.0.2",
53+
"linebreak": "^1.1.0",
5554
"png-js": "^1.0.0"
5655
},
5756
"scripts": {
5857
"prepublishOnly": "npm run build",
5958
"build": "rollup -c && npm run build-standalone",
60-
"build-standalone": "browserify --standalone PDFDocument --ignore crypto --ignore iconv-lite js/pdfkit.js > js/pdfkit.standalone.js",
59+
"build-standalone": "browserify --standalone PDFDocument --ignore crypto js/pdfkit.js > js/pdfkit.standalone.js",
6160
"browserify-example": "browserify examples/browserify/browser.js > examples/browserify/bundle.js",
6261
"pdf-guide": "node docs/generate.js",
6362
"website": "node docs/generate_website.js",
6463
"publish-website": "node docs/publish_website.js",
6564
"docs": "npm run pdf-guide && npm run website && npm run browserify-example",
6665
"lint": "eslint {lib,tests}/**/*.js",
6766
"prettier": "prettier {lib,tests,examples,docs}/**/*.js",
68-
"test": "jest -i",
69-
"test:visual": "jest visual/ -i",
70-
"test:unit": "jest unit/"
67+
"test": "jest -i --env=node",
68+
"test:visual": "jest visual/ -i --env=node",
69+
"test:unit": "jest unit/ --env=node"
7170
},
7271
"main": "js/pdfkit.js",
7372
"module": "js/pdfkit.es.js",
-136 Bytes
Loading
105 Bytes
Loading

0 commit comments

Comments
 (0)