diff --git a/slip39/layout/components.py b/slip39/layout/components.py index 61f770a..3f6fbd3 100644 --- a/slip39/layout/components.py +++ b/slip39/layout/components.py @@ -586,8 +586,8 @@ def layout_components( if bleed is None: bleed = 5/100 # FPDF().epw/.eph is *without* page margins, but *with* re-orienting for portrait/landscape - comp_cols = int(( pdf.epw - page_margin_mm * 2 * min( 1, 1 - bleed )) // comp_dim.x ) - comp_rows = int(( pdf.eph - page_margin_mm * 2 * min( 1, 1 - bleed )) // comp_dim.y ) + comp_cols = max( 1, int(( pdf.epw - page_margin_mm * 2 * min( 1, 1 - bleed )) // comp_dim.x )) + comp_rows = max( 1, int(( pdf.eph - page_margin_mm * 2 * min( 1, 1 - bleed )) // comp_dim.y )) comps_pp = comp_rows * comp_cols # Compute actual page margins to center cards. diff --git a/slip39/output_test.py b/slip39/output_test.py index 903c0b4..c496d46 100644 --- a/slip39/output_test.py +++ b/slip39/output_test.py @@ -4,6 +4,7 @@ from fpdf import FPDF, FlexTemplate from .layout import Region, Text, Image, Box, Coordinate +from .layout.components import layout_components from .defaults import MM_IN @@ -73,3 +74,13 @@ def test_Region(): tpl.render( offsetx = card_size.x * MM_IN, offsety = card_size.y * MM_IN ) #pdf.output( "test.pdf" ) # To view results in test.pdf, uncomment + + +def test_layout_components_oversize(): + """A component larger than the page is laid out 1 per page, instead of raising ZeroDivisionError.""" + pdf = FPDF( orientation='portrait', format='A4' ) + pdf.add_page() + comps_pp,page_xy = layout_components( pdf, comp_dim=Coordinate( x=pdf.epw * 2, y=pdf.eph * 2 )) + assert comps_pp == 1 + page,_ = page_xy( 3 ) + assert page == 3