Skip to content

Commit

Permalink
Add extra space to include ink extents for aligned text in SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe authored and okkays committed May 1, 2024
1 parent ee0563f commit 71afe7a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion weasyprint/svg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,10 @@ def draw_node(self, node, font_size, fill_stroke=True):
self.stream.push_state()
if is_valid_bounding_box(node.text_bounding_box):
x, y, width, height = node.text_bounding_box
group.extra['BBox'][:] = (x, y, x + width, y + height)
# Add extra space to include ink extents
group.extra['BBox'][:] = (
x - font_size, y - font_size,
x + width + font_size, y + height + font_size)
x_align = width / 2 if text_anchor == 'middle' else width
self.stream.transform(e=-x_align)
self.stream.draw_x_object(group_id)
Expand Down

0 comments on commit 71afe7a

Please sign in to comment.