From 20ced13aa6453861e288eaeebda6b6cf1a000b68 Mon Sep 17 00:00:00 2001 From: Andrew Yoon Date: Sat, 6 Jan 2024 22:25:37 -0500 Subject: [PATCH 1/3] Make transform origin respect Text alignment --- neoscore/core/text.py | 2 +- tests/test_core/test_text.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/neoscore/core/text.py b/neoscore/core/text.py index 1f1ba564..ec3b720e 100644 --- a/neoscore/core/text.py +++ b/neoscore/core/text.py @@ -206,7 +206,7 @@ def _render_slice( None if inside_flowable else self.parent.interface_for_children, self.scale, self.rotation, - self.transform_origin, + self.transform_origin - self._alignment_offset, self.brush.interface, self.pen.interface, self.text, diff --git a/tests/test_core/test_text.py b/tests/test_core/test_text.py index 7f1b76d5..f0e725db 100644 --- a/tests/test_core/test_text.py +++ b/tests/test_core/test_text.py @@ -151,7 +151,12 @@ def test_rendered_interface_with_offset(self): "testing", alignment_x=AlignmentX.CENTER, alignment_y=AlignmentY.CENTER, + transform_origin=(Mm(15), Mm(10)), ) obj.render() rendered_pos = obj.interfaces[0].pos + transform_origin = obj.interfaces[0].transform_origin assert_almost_equal(rendered_pos, Point(Unit(-20), Unit(2.5)), epsilon=1.5) + assert_almost_equal( + transform_origin, Point(Unit(-20) - Mm(15), Unit(2.5) - Mm(10)), epsilon=1.5 + ) From 63720b5bae52a17e9565854a2612c2b9bbc9872c Mon Sep 17 00:00:00 2001 From: Andrew Yoon Date: Sat, 6 Jan 2024 22:33:44 -0500 Subject: [PATCH 2/3] Fix test --- tests/test_core/test_text.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_core/test_text.py b/tests/test_core/test_text.py index f0e725db..d6fc4fae 100644 --- a/tests/test_core/test_text.py +++ b/tests/test_core/test_text.py @@ -151,12 +151,14 @@ def test_rendered_interface_with_offset(self): "testing", alignment_x=AlignmentX.CENTER, alignment_y=AlignmentY.CENTER, - transform_origin=(Mm(15), Mm(10)), + transform_origin=(Unit(15), Unit(10)), ) obj.render() rendered_pos = obj.interfaces[0].pos transform_origin = obj.interfaces[0].transform_origin assert_almost_equal(rendered_pos, Point(Unit(-20), Unit(2.5)), epsilon=1.5) assert_almost_equal( - transform_origin, Point(Unit(-20) - Mm(15), Unit(2.5) - Mm(10)), epsilon=1.5 + transform_origin, + Point(Unit(35), Unit(7.5)), + epsilon=1.5, ) From 8ba1be6d29fc93b551f64c982448850a179bb933 Mon Sep 17 00:00:00 2001 From: Andrew Yoon Date: Sat, 6 Jan 2024 22:46:33 -0500 Subject: [PATCH 3/3] Update `Text.bounding_rect` docs to clarify meaning --- neoscore/core/text.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/neoscore/core/text.py b/neoscore/core/text.py index ec3b720e..55d5bc2c 100644 --- a/neoscore/core/text.py +++ b/neoscore/core/text.py @@ -171,8 +171,11 @@ def bounding_rect(self) -> Rect: """The bounding rect for this text positioned relative to ``pos``. The rect ``(x, y)`` position is relative to the object's position. + Note that with text objects, the rect's ``(x, y)`` position will + typically not be at the origin. - Note that this currently accounts for scaling, but not rotation. + This currently accounts for scaling and alignment, but not rotation. + Rotated objects will generally have incorrect bounding rects. """ raw_rect = self._raw_scaled_bounding_rect alignment_offset = self._alignment_offset