fixed issue with bounding box height being wrong
Python CI / test (3.10) (push) Has been cancelled
Python CI / test (3.12) (push) Has been cancelled
Python CI / test (3.13) (push) Has been cancelled

This commit is contained in:
2025-11-09 17:10:50 +01:00
parent 56c2c21021
commit 50b9aa5431
4 changed files with 56 additions and 13 deletions
+2 -2
View File
@@ -125,8 +125,8 @@ class TestLinkText(unittest.TestCase):
# Mock width property
renderable._width = 80
# Point inside link
self.assertTrue(renderable.in_object((15, 25)))
# Point inside link - origin is at baseline (10, 20), so test at baseline Y
self.assertTrue(renderable.in_object((15, 20)))
# Point outside link
self.assertFalse(renderable.in_object((200, 200)))
+7 -1
View File
@@ -76,8 +76,14 @@ class TestText(unittest.TestCase):
def test_in_object_true(self):
text_instance = Text(text="Test", style=self.style, draw=self.draw)
# Set origin at baseline position (50, 50)
text_instance.set_origin(np.array([50, 50]))
# Test with a point that should be inside the text bounds
point = (5, 5)
# The text origin is at the baseline (50, 50)
# Visual bounds are: top = 50 - ascent, bottom = 50 + descent
# So a point at (55, 50) should be inside (at baseline)
point = (55, 50)
self.assertTrue(text_instance.in_object(point))
def test_in_object_false(self):
+17 -8
View File
@@ -145,7 +145,9 @@ class TestTextQueryPoint(unittest.TestCase):
text.set_origin(np.array([100, 100]))
# Point inside text bounds
self.assertTrue(text.in_object(np.array([110, 105])))
# Origin is at baseline (100, 100), so test a point slightly above (at ascent/2)
# and to the right
self.assertTrue(text.in_object(np.array([110, 100])))
def test_in_object_miss(self):
"""Test in_object returns False for point outside text"""
@@ -188,7 +190,9 @@ class TestLineQueryPoint(unittest.TestCase):
# (after rendering, text objects have positions set)
if len(line._text_objects) > 0:
text_obj = line._text_objects[0]
point = (int(text_obj._origin[0] + 5), int(text_obj._origin[1] + 5))
# Origin is at baseline, so query at baseline position (Y = origin[1])
# with X offset into the text
point = (int(text_obj._origin[0] + 5), int(text_obj._origin[1]))
result = line.query_point(point)
@@ -234,7 +238,8 @@ class TestLineQueryPoint(unittest.TestCase):
# Query the link
if len(line._text_objects) > 0:
text_obj = line._text_objects[0]
point = (int(text_obj._origin[0] + 5), int(text_obj._origin[1] + 5))
# Origin is at baseline, query at baseline Y position
point = (int(text_obj._origin[0] + 5), int(text_obj._origin[1]))
result = line.query_point(point)
@@ -279,7 +284,8 @@ class TestPageQueryPoint(unittest.TestCase):
# Query a point inside the line
if len(line._text_objects) > 0:
text_obj = line._text_objects[0]
point = (int(text_obj._origin[0] + 5), int(text_obj._origin[1] + 5))
# Origin is at baseline, query at baseline Y position
point = (int(text_obj._origin[0] + 5), int(text_obj._origin[1]))
result = self.page.query_point(point)
@@ -321,7 +327,8 @@ class TestPageQueryPoint(unittest.TestCase):
# Query first line
if len(line1._text_objects) > 0:
text_obj1 = line1._text_objects[0]
point1 = (int(text_obj1._origin[0] + 5), int(text_obj1._origin[1] + 5))
# Origin is at baseline, query at baseline Y position
point1 = (int(text_obj1._origin[0] + 5), int(text_obj1._origin[1]))
result1 = self.page.query_point(point1)
self.assertIsNotNone(result1)
@@ -330,7 +337,8 @@ class TestPageQueryPoint(unittest.TestCase):
# Query second line
if len(line2._text_objects) > 0:
text_obj2 = line2._text_objects[0]
point2 = (int(text_obj2._origin[0] + 5), int(text_obj2._origin[1] + 5))
# Origin is at baseline, query at baseline Y position
point2 = (int(text_obj2._origin[0] + 5), int(text_obj2._origin[1]))
result2 = self.page.query_point(point2)
self.assertIsNotNone(result2)
@@ -368,9 +376,10 @@ class TestPageQueryRange(unittest.TestCase):
start_text = line._text_objects[0]
end_text = line._text_objects[1]
# Origin is at baseline, query at baseline Y position
start_point = (
int(start_text._origin[0] + 5), int(start_text._origin[1] + 5))
end_point = (int(end_text._origin[0] + 5), int(end_text._origin[1] + 5))
int(start_text._origin[0] + 5), int(start_text._origin[1]))
end_point = (int(end_text._origin[0] + 5), int(end_text._origin[1]))
sel_range = self.page.query_range(start_point, end_point)