diff --git a/neoscore/core/text.py b/neoscore/core/text.py index 1f1ba564..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 @@ -206,7 +209,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..d6fc4fae 100644 --- a/tests/test_core/test_text.py +++ b/tests/test_core/test_text.py @@ -151,7 +151,14 @@ def test_rendered_interface_with_offset(self): "testing", alignment_x=AlignmentX.CENTER, alignment_y=AlignmentY.CENTER, + 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(35), Unit(7.5)), + epsilon=1.5, + )