Skip to content

Commit cbf4b8d

Browse files
committed
Normalize getPDFInfo output for different OSs
1 parent 5c00d63 commit cbf4b8d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

test/helper.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ export async function getPDFInfo(path) {
4141

4242
// Get metadata
4343

44-
// @ts-expect-error - `contentLength` exists upon testing.
45-
const { contentLength, info } = await document.getMetadata();
44+
const { info } = await document.getMetadata();
4645

4746
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
4847
const metadata = {
4948
// @ts-expect-error - It should exist since it's set in the template
5049
// fixtures using the `lang` property in the `html` element.
5150
language: info.Language,
52-
length: contentLength,
5351
// @ts-expect-error - It should exist since it's set in the template
5452
// fixtures using the `title` element.
5553
title: info.Title,
@@ -85,7 +83,18 @@ export async function getPDFInfo(path) {
8583
}
8684

8785
if (fn === OPS.setFont) {
86+
// On Linux: `AAAAAA+FunnelDisplay-Light`
87+
// On macOS: `AAAAAA+FunnelDisplay-Light_Bold`
88+
// On Windows: `AAAAAA+Funnel-Display-Light-Light`
8889
font = page.commonObjs.get(args[0]).name;
90+
// Normalization for macOS
91+
const underscoreIndex = font.indexOf("_");
92+
if (underscoreIndex > 0) {
93+
font = font.slice(0, underscoreIndex);
94+
}
95+
// Normalization for Windows
96+
font = [...new Set(font.split("-"))].join("");
97+
8998
[, size] = args;
9099
continue;
91100
}

test/test.js.snapshot

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,43 @@ exports[`cli.js > creates PDF with correct info using complex input, default fil
33
"contents": [
44
{
55
"color": "#212529",
6-
"font": "AAAAAA+FunnelDisplay-Light",
6+
"font": "AAAAAA+FunnelDisplayLight",
77
"size": 40,
88
"text": "Document Title",
99
"type": "TEXT"
1010
},
1111
{
1212
"color": "#495057",
13-
"font": "BAAAAA+FunnelDisplay-Light",
13+
"font": "BAAAAA+FunnelDisplayLight",
1414
"size": 24,
1515
"text": "This is a test document for testing PDF Made Easy.",
1616
"type": "TEXT"
1717
},
1818
{
1919
"color": "#212529",
20-
"font": "CAAAAA+FunnelDisplay-Light",
20+
"font": "CAAAAA+FunnelDisplayLight",
2121
"size": 32,
2222
"text": "Photo by ",
2323
"type": "TEXT"
2424
},
2525
{
2626
"color": "#3c096c",
27-
"font": "CAAAAA+FunnelDisplay-Light",
27+
"font": "CAAAAA+FunnelDisplayLight",
2828
"size": 32,
2929
"text": "Sixteen Miles Out",
3030
"type": "LINK",
3131
"url": "https://unsplash.com/@sixteenmilesout"
3232
},
3333
{
3434
"color": "#212529",
35-
"font": "CAAAAA+FunnelDisplay-Light",
35+
"font": "CAAAAA+FunnelDisplayLight",
3636
"size": 32,
3737
"text": " on ",
3838
"type": "TEXT"
3939
},
4040
{
4141
"color": "#3c096c",
42-
"font": "CAAAAA+FunnelDisplay-Light",
42+
"font": "CAAAAA+FunnelDisplayLight",
4343
"size": 32,
4444
"text": "Unsplash",
4545
"type": "LINK",
@@ -55,7 +55,6 @@ exports[`cli.js > creates PDF with correct info using complex input, default fil
5555
],
5656
"metadata": {
5757
"language": "en",
58-
"length": 48152,
5958
"title": "Document Title"
6059
}
6160
}

0 commit comments

Comments
 (0)