From ba08e477fb418acc8985345f90d0bd9b03bcebec Mon Sep 17 00:00:00 2001
From: "Sven M. Hallberg" <pesco@khjk.org>
Date: Wed, 27 Jul 2022 18:41:09 +0200
Subject: [PATCH] crudely avoid segfaulting from missing Tf

---
 pdf.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/pdf.c b/pdf.c
index e6ef7d0..e55b182 100644
--- a/pdf.c
+++ b/pdf.c
@@ -1997,12 +1997,14 @@ act_txtobj(const HParseResult *p, void *u)
             textlen += 1;
         case TW_Tj:
             textlen += txte->tstr.nchars;
-            *px += txte->tstr.nchars * node->ts.font->fref.fontsize; // TODO:: handle character width from font description
+            if (node->ts.font != NULL)
+                *px += txte->tstr.nchars * node->ts.font->fref.fontsize; // TODO:: handle character width from font description
             break;
 
 		case TW_TJ:
 			textlen += txte->tarray.flattened.nchars;
-            *px += txte->tarray.flattened.nchars * node->ts.font->fref.fontsize; // TODO:: handle character width from font description
+            if (node->ts.font != NULL)
+                *px += txte->tarray.flattened.nchars * node->ts.font->fref.fontsize; // TODO:: handle character width from font description
 			break;
 
 		default:
@@ -2098,14 +2100,16 @@ act_txtobj(const HParseResult *p, void *u)
         case TW_Tj:
             memcpy(&tstr[idx], txte->tstr.text, txte->tstr.nchars);
             idx += txte->tstr.nchars;
-            *px += txte->tarray.flattened.nchars * node->ts.font->fref.fontsize; // TODO:: handle character width from font description
+            if (node->ts.font != NULL)
+                *px += txte->tarray.flattened.nchars * node->ts.font->fref.fontsize; // TODO:: handle character width from font description
             break;
 
 
         case TW_TJ:
             memcpy(&tstr[idx], txte->tarray.flattened.text, txte->tarray.flattened.nchars);
             idx += txte->tarray.flattened.nchars;
-            *px += txte->tarray.flattened.nchars * node->ts.font->fref.fontsize; // TODO:: handle character width from font description
+            if (node->ts.font != NULL)
+                *px += txte->tarray.flattened.nchars * node->ts.font->fref.fontsize; // TODO:: handle character width from font description
             break;
 
 		default:
-- 
GitLab