Skip to content

Commit

Permalink
feat: remove Buffer dependency from font package (#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura committed Jul 11, 2022
1 parent 7eefc33 commit 27403f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-moles-trade.md
@@ -0,0 +1,5 @@
---
'@react-pdf/font': patch
---

feat: remove Buffer dependency from font package
9 changes: 3 additions & 6 deletions packages/font/src/font.js
Expand Up @@ -24,12 +24,9 @@ const FONT_WEIGHTS = {

const fetchFont = async (src, options) => {
const response = await fetch(src, options);
const data = await response.arrayBuffer();

const buffer = await (response.buffer
? response.buffer()
: response.arrayBuffer());

return buffer.constructor.name === 'Buffer' ? buffer : Buffer.from(buffer);
return new Uint8Array(data);
};

const isDataUrl = dataUrl => {
Expand Down Expand Up @@ -64,7 +61,7 @@ class FontSource {
if (isDataUrl(this.src)) {
const raw = this.src.split(',')[1];
this.data = fontkit.create(toUint8Array(raw), postscriptName);
} else if (BROWSER || isUrl(this.src)) {
} else if (isUrl(this.src)) {
const { headers, body, method = 'GET' } = this.options;
const data = await fetchFont(this.src, { method, body, headers });
this.data = fontkit.create(data, postscriptName);
Expand Down

0 comments on commit 27403f9

Please sign in to comment.