From cccb26b92dc2361073af5645a98d451f062135c5 Mon Sep 17 00:00:00 2001 From: PrinsFrank <25006490+PrinsFrank@users.noreply.github.com> Date: Fri, 17 Jul 2026 20:50:41 +0200 Subject: [PATCH] Don't return new TransformationMatrix when multiplying with identity matrix reducing memory footprint --- .../PositionedText/TransformationMatrix.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Document/ContentStream/PositionedText/TransformationMatrix.php b/src/Document/ContentStream/PositionedText/TransformationMatrix.php index 96082bc9..64471905 100644 --- a/src/Document/ContentStream/PositionedText/TransformationMatrix.php +++ b/src/Document/ContentStream/PositionedText/TransformationMatrix.php @@ -14,6 +14,16 @@ public function __construct( /** Please note that a concatenated transformation matrix of A B !== B A */ public function multiplyWith(self $other): self { + if ($other->scaleX === 1.0 + && $other->scaleY === 1.0 + && $other->shearX === 0.0 + && $other->shearY === 0.0 + && $other->offsetX === 0.0 + && $other->offsetY === 0.0 + ) { + return $this; // When multiplying with the identity matrix, the current matrix is unchanged + } + return new self( $this->scaleX * $other->scaleX + $this->shearX * $other->shearY, $this->scaleX * $other->shearX + $this->shearX * $other->scaleY,