Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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).

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 ;)

$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

'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.

3 participants