def get_svg_bounding_box(self): ''' Return a Rect describing the bounding box of coords in the SVG file. [TODO: is this already a function in the SVG lib?] ''' svg_bounding_box = Rect.far_extents() for elem in self.svg_root.iter(): elem_extents = self._get_elem_extents(elem) svg_bounding_box = svg_bounding_box.expand_to(elem_extents) print(f'SVG extents: {svg_bounding_box}') return svg_bounding_box
def _get_elem_extents(self, elem): elem_extents = Rect.far_extents() tag_suffix = elem.tag.split('}')[-1] if tag_suffix not in SVG_TAGS: return elem_extents shape_class = getattr(shapes, tag_suffix) shape_obj = shape_class(elem) path = shape_obj.d_path() mtx = shape_obj.transformation_matrix() if path: points = shapes.point_generator(path, mtx, self.settings.smoothness) for point in points: elem_extents = elem_extents.expand_to(rotate(Vector2(point), self.rotate_rads)) return elem_extents