From c080f17266c4fb8c5cba57ef17cca31c92f95eb9 Mon Sep 17 00:00:00 2001 From: Till Berger Date: Sat, 11 Jun 2022 12:28:34 +0200 Subject: [PATCH] Always return a list for the `transform` property --- src/Css/Style.php | 6 +++--- src/Renderer.php | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Css/Style.php b/src/Css/Style.php index 10953737a..c310b7ff5 100644 --- a/src/Css/Style.php +++ b/src/Css/Style.php @@ -153,7 +153,7 @@ * @property float|string $text_indent Length in pt or a percentage value * @property string $text_transform * @property float|string $top Length in pt, a percentage value, or `auto` - * @property array $transform + * @property array $transform List of transforms * @property array $transform_origin * @property string $unicode_bidi * @property string $unicode_range @@ -3440,7 +3440,7 @@ protected function _compute_size(string $val) /** * @param string $computed - * @return array|null + * @return array * * @link https://www.w3.org/TR/css-transforms-1/#transform-property */ @@ -3453,7 +3453,7 @@ protected function _get_transform($computed) $angle = "\s*([^,\s]+(?:deg|rad)?)\s*"; if (!preg_match_all("/[a-z]+\([^\)]+\)/i", $computed, $parts, PREG_SET_ORDER)) { - return null; + return []; } $functions = [ diff --git a/src/Renderer.php b/src/Renderer.php index d7ff8b9de..36966fb38 100644 --- a/src/Renderer.php +++ b/src/Renderer.php @@ -65,19 +65,21 @@ public function render(Frame $frame) $style = $frame->get_style(); - if (in_array($style->visibility, ["hidden", "collapse"])) { + if (in_array($style->visibility, ["hidden", "collapse"], true)) { return; } $display = $style->display; + $transformList = $style->transform; + $hasTransform = $transformList !== []; // Starts the CSS transformation - if ($style->transform && is_array($style->transform)) { + if ($hasTransform) { $this->_canvas->save(); list($x, $y) = $frame->get_padding_box(); $origin = $style->transform_origin; - foreach ($style->transform as $transform) { + foreach ($transformList as $transform) { list($function, $values) = $transform; if ($function === "matrix") { $function = "transform"; @@ -200,7 +202,7 @@ public function render(Frame $frame) $this->_canvas->clipping_end(); } - if ($style->transform && is_array($style->transform)) { + if ($hasTransform) { $this->_canvas->restore(); }