fixed issue with bounding box height being wrong
This commit is contained in:
@@ -227,8 +227,11 @@ class Text(Renderable, Queriable):
|
||||
|
||||
@property
|
||||
def size(self) -> int:
|
||||
"""Get the width of the text"""
|
||||
return np.array((self._width, self._style.font_size))
|
||||
"""Get the width and height of the text"""
|
||||
# Return actual rendered height (ascent + descent) not just font_size
|
||||
ascent, descent = self._style.font.getmetrics()
|
||||
actual_height = ascent + descent
|
||||
return np.array((self._width, actual_height))
|
||||
|
||||
def set_origin(self, origin: np.generic):
|
||||
"""Set the origin (left baseline ("ls")) of this text element"""
|
||||
@@ -238,6 +241,31 @@ class Text(Renderable, Queriable):
|
||||
"""Add this text to a line"""
|
||||
self._line = line
|
||||
|
||||
def in_object(self, point: np.generic):
|
||||
"""
|
||||
Check if a point is in the text object.
|
||||
|
||||
Override Queriable.in_object() because Text uses baseline-anchored positioning.
|
||||
The origin is at the baseline (anchor="ls"), not the top-left corner.
|
||||
|
||||
Args:
|
||||
point: The coordinates to check
|
||||
|
||||
Returns:
|
||||
True if the point is within the text bounds
|
||||
"""
|
||||
point_array = np.array(point)
|
||||
|
||||
# Text origin is at baseline, so visual top is origin[1] - ascent
|
||||
visual_top = self._origin[1] - self._ascent
|
||||
visual_bottom = self._origin[1] + (self.size[1] - self._ascent)
|
||||
|
||||
# Check if point is within bounds
|
||||
# X: origin[0] to origin[0] + width
|
||||
# Y: visual_top to visual_bottom
|
||||
return (self._origin[0] <= point_array[0] < self._origin[0] + self.size[0] and
|
||||
visual_top <= point_array[1] < visual_bottom)
|
||||
|
||||
def _apply_decoration(self, next_text: Optional['Text'] = None, spacing: int = 0):
|
||||
"""
|
||||
Apply text decoration (underline or strikethrough).
|
||||
|
||||
Reference in New Issue
Block a user