react-pdf
react-pdf copied to clipboard
Fix for "Cannot read unitsPerEm"
Hi! π
Firstly, thanks for your work on this project! π
Today I used patch-package to patch @react-pdf/[email protected] for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/@react-pdf/textkit/lib/textkit.js b/node_modules/@react-pdf/textkit/lib/textkit.js
index 7ca4f07..4e3f61e 100644
--- a/node_modules/@react-pdf/textkit/lib/textkit.js
+++ b/node_modules/@react-pdf/textkit/lib/textkit.js
@@ -2813,7 +2813,7 @@ const fontSubstitution = () => ({ string, runs }) => {
// If anything that would impact res has changed, update it
if (font !== lastFont ||
fontSize !== lastFontSize ||
- font.unitsPerEm !== lastFont.unitsPerEm) {
+ font?.unitsPerEm !== lastFont?.unitsPerEm && lastFont) {
if (lastFont) {
res.push({
start: lastIndex,
@@ -2831,7 +2831,7 @@ const fontSubstitution = () => ({ string, runs }) => {
index += char.length;
}
}
- if (lastIndex < string.length) {
+ if (lastIndex < string.length && lastFont) {
const fontSize = getFontSize(last(runs));
res.push({
start: lastIndex,
This issue body was partially generated by patch-package.
@Pasquale007 do line breaks (e.g. from text areas or forced in React {"\n"}) still work for you?
@chris-farmact yes {"\n"} still breaks the line as well as normal text breaks