Skip to content

Commit

Permalink
Detect font type before parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Aug 16, 2024
1 parent 22326d4 commit 659d10d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion decktape.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ async function printSlide(pdf, slide, context) {
// Some fonts written in the PDF may be ill-formed. Let's skip font compression in that case,
// until it's fixed in Puppeteer > Chromium > Skia.
// This happens for system fonts like Helvetica Neue for which cmap table is missing.
font = Font.create(Buffer.from(bytes), { type: 'ttf', hinting: true });
font = Font.create(Buffer.from(bytes), { type: fontType(bytes), hinting: true });
} catch (e) {
console.log(chalk.yellow('\nSkipping font compression: %s'), e.message);
return;
Expand Down Expand Up @@ -534,6 +534,16 @@ async function printSlide(pdf, slide, context) {
}
};

function fontType(bytes) {
const buffer = Buffer.from(bytes);
if (buffer.readInt32BE() === 0x10000) {
return 'ttf';
}
if (buffer.toString('utf8', 0, 4) === 'OTTO') {
return 'otf';
}
}

function mergeGlyph(font, index, glyf) {
if (font.data.glyf.length <= index) {
for (let i = font.data.glyf.length; i < index; i++) {
Expand Down

0 comments on commit 659d10d

Please sign in to comment.