diff --git a/src/Document/Object/Decorator/Font.php b/src/Document/Object/Decorator/Font.php index 41484bc6..3a45f62c 100644 --- a/src/Document/Object/Decorator/Font.php +++ b/src/Document/Object/Decorator/Font.php @@ -152,8 +152,13 @@ public function getWidthForChar(int $characterCode, TextState $textState, Transf /** @param list $chars */ public function getWidthForChars(array $chars, TextState $textState, TransformationMatrix $transformationMatrix): float { $totalCharacterWidth = 0; + $charWidthCache = []; foreach ($chars as $char) { - $totalCharacterWidth += $this->getWidthForChar($char, $textState, $transformationMatrix); + if (isset($charWidthCache[$char]) === false) { + $charWidthCache[$char] = $this->getWidthForChar($char, $textState, $transformationMatrix); + } + + $totalCharacterWidth += $charWidthCache[$char]; } return $totalCharacterWidth;