Skip to content

Commit

Permalink
Don't crash when drawing borders on 0-size boxes (fix #146)
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Dec 18, 2013
1 parent a0829ec commit 3e49ce8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion weasyprint/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def draw_dots(dashes, line, way, x, y, px, py, chl):
# 2x + 1 dashes
context.clip()
dash = length / (
round(length / dash) - (round(length / dash) + 1) % 2)
round(length / dash) - (round(length / dash) + 1) % 2) or 1
for i in range(0, int(round(length / dash)), 2):
if side == 'top':
context.rectangle(
Expand Down
16 changes: 15 additions & 1 deletion weasyprint/tests/test_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,21 @@ def test_small_borders():
</style>
<body>'''
for style in ['none', 'solid', 'dashed', 'dotted']:
HTML(string=html % style).render()
HTML(string=html % style).write_image_surface()

# Regression test for ZeroDivisionError on dashed or dotted borders
# smaller than a dash/dot.
# https://github.com/Kozea/WeasyPrint/issues/146
html = '''
<style>
@page { size: 50px 50px }
html { background: #fff }
body { height: 0; width: 0; border-width: 1px 0; border-style: %s }
</style>
<body>'''
for style in ['none', 'solid', 'dashed', 'dotted']:
print(html % style)
HTML(string=html % style).write_image_surface()


@assert_no_logs
Expand Down

0 comments on commit 3e49ce8

Please sign in to comment.