From 77701f7240d545778b982049dffa76b6bf5ed6e1 Mon Sep 17 00:00:00 2001 From: Jim Mason Date: Sat, 9 Sep 2023 02:43:23 +0100 Subject: [PATCH] finessed scrubText defaults (non-semantic change) --- src/PDF_Label.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/PDF_Label.php b/src/PDF_Label.php index dc36e43..1085696 100644 --- a/src/PDF_Label.php +++ b/src/PDF_Label.php @@ -190,17 +190,18 @@ function SetLineHeight($pt) { } /** - * remove codepoints with no glyph in the current font + * replace codepoints with no glyph in the current font * * @param $text text to scrub * @param $substitute string to substitute for codepoint (default empty) - * @returns text with glyphless codepoints removed + * @returns text with glyphless codepoints replaced */ function scrubText($text, $substitute = '') { - if($this->unifontSubset) { - $cw = $this->CurrentFont['cw']; + if($this->unifontSubset && + ($cw = $this->CurrentFont['cw']) && + strlen($cw) == 0x10000 * 2) { foreach($this->UTF8StringToArray($text) as $char) { - if($char >= 128 && (ord($cw[2*$char] ?? 0) << 8) + ord($cw[2*$char+1] ?? 0) == 0) + if($char >= 128 && !ord($cw[2*$char]) && !ord($cw[2*$char+1])) $text = preg_replace('/' . mb_chr($char) . '/u', $substitute, $text); } }