Skip to content

Commit

Permalink
finessed scrubText defaults (non-semantic change)
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed Sep 9, 2023
1 parent a82fe45 commit 77701f7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/PDF_Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 77701f7

Please sign in to comment.