Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Text rotate [#80] #240

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Added: Text rotate [#80] #240

wants to merge 4 commits into from

Conversation

daanggc
Copy link

@daanggc daanggc commented Feb 19, 2025

Added: Text rotate [#80]

Text rotation was added by calculating the resulting rotation after all transformations were calculated.
So we are using the resulting matrix data in the Transform to get our final rotation.

The rotation function in the Transform class is universal, so it should be usable for other elements.

Copy link
Owner

@meyfa meyfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this, and sorry for not getting to it sooner. I've left some review comments, please take a look.

*
* @return float clockwise rotation
*/
public function rotation(): float
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be called getRotation(), so that there is less potential to confuse it with rotate(), and so it starts with a verb (like most functions besides convenience attribute accessors do).

@@ -25,7 +25,7 @@ class TextRenderer extends MultiPassRenderer
*/
protected function prepareRenderParams(array $options, Transform $transform, ?FontRegistry $fontRegistry): ?array
{
// this assumes there is no rotation or skew, but that's fine, we can't deal with that anyway
// only the rotational impact of skew is used
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would imagine skew has no impact on the rotation? In that case, maybe reword it:

Suggested change
// only the rotational impact of skew is used
// Only the rotational component of the transform is used

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skew does impact rotation, for example, use -1 and 1 here in skew: https://angrytools.com/css-generator/transform/

But your wording better in both cases, so I'll use that ;)

@@ -55,12 +55,16 @@ protected function prepareRenderParams(array $options, Transform $transform, ?Fo
$y = $options['y'];
$transform->map($x, $y);

//get clockwise rotation result from transform matrix
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick)

Suggested change
//get clockwise rotation result from transform matrix
// get clockwise rotation from transform matrix

return [
'x' => $x - $anchorOffset,
'y' => $y,
'size' => $size,
'fontPath' => $fontPath,
'text' => $options['text'],
'rotation' => $rotation
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick)

Suggested change
'rotation' => $rotation
'rotation' => $rotation,


$caRadian = atan2(-$this->matrix[2], $this->matrix[0]);
$bdRadian = atan2($this->matrix[1], $this->matrix[3]);
return ($caRadian + $bdRadian) / 2 * 180 / M_PI;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since rotate() uses radians, this should return radians as well, and leave the conversion up to the caller.

@Niellles
Copy link
Contributor

@daanggc Would you be able to incorporate the feedback into your PR when you have some time?

I'll try to add some tests for your work soon—just need to find the time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants