Updated
On this page
Bounding box computation for predraw elements.
#predraw.bbox
#predraw.bbox
Bounding box computation for predraw elements.
Computes axis-aligned bounding boxes from element geometry, including SVG path data parsing and transform application.
#compute_bbox
python
def compute_bbox(element: Element) -> tuple[float, float, float, float] | NoneCompute the bounding box (min_x, min_y, max_x, max_y) of an element.
Handles:
- rect: (x, y, x+width, y+height)
- text: (x, y - font_size, x + estimated_width, y) -- rough estimate
- path: parse the d string and find coordinate extremes
- group: union of children's bboxes, with transform applied
- background: (0, 0, 0, 0) -- skip
Returns None if bbox can't be determined.
#_bbox_from_path_d
python
def _bbox_from_path_d(d: str) -> tuple[float, float, float, float] | NoneParse SVG path d string and extract coordinate bounding box.
Handles M, L, H, V, C, S, Q, T, A, Z commands (uppercase = absolute). For curves (C, S, Q), use control points as bbox approximation. Lowercase (relative) commands need accumulation from current point.
#_apply_transform_to_bbox
python
def _apply_transform_to_bbox(bbox: tuple[float, float, float, float], transform: Transform) -> tuple[float, float, float, float]Apply translate and scale to a bounding box.