-
Notifications
You must be signed in to change notification settings - Fork 95
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:
// only the rotational impact of skew is used | |
// Only the rotational component of the transform is used |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nitpick)
//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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nitpick)
'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; |
There was a problem hiding this comment.
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.
@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! |
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 theTransform
class is universal, so it should be usable for other elements.