Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions slip39/layout/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions slip39/output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Loading