oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.53k stars 2.79k forks source link

custom font loading fails using pdfkit #3100

Open r4wand opened 1 year ago

r4wand commented 1 year ago

What version of Bun is running?

0.6.3

What platform is your computer?

Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

add npm package pdfkit then add a custom font. here is an example.

const PDFDocument = require("pdfkit");
const fs = require("fs");

const doc = new PDFDocument({ size: "A4", layout: "landscape" });
doc.pipe(fs.createWriteStream("output.pdf"));

// Add some text, and point to the .ttf font
doc
  .font("fonts/font.ttf")
  .fontSize(20)
  .fillColor("black")
  .text("some text", 25, 35, { align: "right" });

doc.end();

then run it using bun

What is the expected behavior?

you should be able to successfully generate a pdf file called output.pdf

What do you see instead?

[1] 37876 trace trap bun src/index.js

Additional information

it works fine using node v18.16.0 and it works fine when you don't use custom font. so the bellow example works

const PDFDocument = require("pdfkit");
const fs = require("fs");

const doc = new PDFDocument({ size: "A4", layout: "landscape" });
doc.pipe(fs.createWriteStream("output.pdf"));

// Add some text, and point to the .ttf font
doc
  .fontSize(20)
  .fillColor("black")
  .text("some text", 25, 35, { align: "right" });

doc.end();
trnxdev commented 1 year ago

I experience the same issue, after some debugging i found out that the code stop's executing after this line: https://github.com/foliojs/pdfkit/blob/c1d7700421a9f8c8f9f78c31e9979bd9157f39b3/lib/document.js#L305 (font.finalize();) Which means somewhere around here: https://github.com/foliojs/pdfkit/blob/c1d7700421a9f8c8f9f78c31e9979bd9157f39b3/lib/reference.js#L66