Skip to content

Turn a positioned block for rotate: 90deg on PHP 8 as on PHP 7 - #579

Merged
jakejackson1 merged 2 commits into
gravitypdffrom
fix/552-rotate-angle
Sep 30, 2026
Merged

jakejackson1 merged 2 commits into
gravitypdffrom
fix/552-rotate-angle

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Problem

mPDF's own rotate property turns an absolutely or fixed positioned block. The block code checked the value with $p['ROTATE'] == 90 || == -90 || == 180. '90deg' == 90 is true on PHP 5.6 to 7.4 and false on PHP 8, so .t { position: absolute; rotate: 90deg } was turned on PHP 7 and not on PHP 8. Unitless 90, -90 and 180 worked on both.

Tables already read the same property through Table::parseTableRotate(), which parses the angle. That parser came from mpdf#2178.

The audit said 180 "is accepted and never drawn". That is not so: the block code has a branch for it (mPDF 6), and rotate: 180 draws the block upside down on the base branch. So 180 stays supported for positioned blocks. The manual documents only 90 | -90; tables never drew 180 and still do not.

Part of #552 (Layout, rotate row in the audit). Part of #520.

Change

  • Table::parseTableRotate() moves to Mpdf\Utils\Rotation::angle($rotate, $supported). It reads whole degrees with or without deg, wraps the angle to between -180 and 180, and returns it if the caller can draw it, or 0 if not.
  • Tables pass [90, -90], as before.
  • Positioned blocks pass [90, -90, 180], so 90deg, -90deg, 180deg, 270deg and -180deg are read the same on every PHP version.

The value is trimmed and DEG is read case-insensitively. Tables otherwise behave as before.

PHPStan now sees $rotate as an int that is 90, -90, 180 or 0. That removes two false "might not be defined" reports each for $preroth, $prerotw, $rot_bpos and $rot_rpos, and the baseline counts are lowered to match.

Tests

  • PositionedBlockRotateTest renders a positioned block for each of these values and reads which rotation matrices are drawn: 90, 90deg, -90, -90deg, 270deg, -270deg, 180, 180deg, -180deg, 45deg and auto.
  • PositionedBlockRotateSnapshotTest (positioned-block-rotate) puts six blocks beside captions saying which way each should be turned. The fixture was generated on PHP 8.5, which CI's snapshot job uses. On the base branch, the 90deg, -90deg, 270deg and 180deg blocks are drawn unturned.

With the source change reverted, the deg cases fail on PHP 8. No existing snapshot fixture changed.

Checks

  • composer test: OK. 4468 tests, 31 skipped for missing optional packages or ungenerated data. The snapshot suite ran with Imagick and Ghostscript.
  • composer cs: clean.
  • PHPStan: no errors, with the baseline counts above.

🤖 Generated with Claude Code

@jakejackson1 jakejackson1 added bug Something isn't working create-upstream-pr labels Sep 29, 2026
@jakejackson1
jakejackson1 force-pushed the fix/552-rotate-angle branch 2 times, most recently from e79cdb2 to c1225aa Compare September 29, 2026 22:54
The positioned-block code compared the rotate value with == 90, -90 and 180. "90deg" == 90 is true on PHP 5.6 to 7.4 and false on PHP 8, so the same document turned the block on one and not the other.

The angle is now read by Mpdf\Utils\Rotation::angle(), which tables already used as a private method: whole degrees, with or without "deg", wrapped to between -180 and 180, and kept only if the caller can draw it. A positioned block draws 90, -90 and 180, and a table 90 and -90, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakejackson1
jakejackson1 merged commit 2381958 into gravitypdf Sep 30, 2026
12 checks passed
@jakejackson1
jakejackson1 deleted the fix/552-rotate-angle branch September 30, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working create-upstream-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant