Skip to content

Fit the mnemonic font size to the column width of each card - #30

Open
fdegros wants to merge 1 commit into
pjkundert:masterfrom
fdegros:fit-card-mnemonics
Open

fdegros wants to merge 1 commit into
pjkundert:masterfrom
fdegros:fit-card-mnemonics

Conversation

@fdegros

@fdegros fdegros commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The mnemonic font size was derived only from the height of each row. On narrow cards the longest cell ("12 advocate": 2 digits, a space and an 8-letter word) is wider than its column: words run into the next column or are clipped at the edge of the card. For example, slip39 --card credit --anonymous (which uses the larger "big" mnemonics) overflows.

This uses the smaller of the height-based size and the size at which 11 monospaced characters fit within 90% of the column width. Cards that already fit (eg. the index card) are unchanged.

  • Change: slip39/layout/components.py (layout_card); constants MNEM_CHARS, MONO_WIDTH, MNEM_FIT.
  • Test: test_card_mnemonics_fit in slip39/output_test.py checks that the longest cell fits its column, for every card size and word count. On current master, it overflows for the credit card (20, 33 and 59 words) and the photo card (33 words).
  • pytest (without the invoice/communications tests): 42 passed, 4 skipped; recovery_test.py::test_dft_smoke fails on Python 3.14 when numpy isn't installed (the pure-Python idft fallback), with or without this change.

Before/after screenshots of --card credit --anonymous can be added.

The mnemonic font size was derived only from the height of each row.  On narrow cards
(eg. --card credit with --anonymous, which uses the larger "big" mnemonics), the
longest cell ("12 advocate": 2 digits, a space and an 8-letter word) was wider than
its column, so words ran into the next column or were clipped at the edge of the card.

Use the smaller of the height-based size and the size at which 11 monospaced
characters fit within 90% of the column width.  Cards that already fit (eg. index)
are unchanged.  On unmodified master, the longest cell overflowed for the credit card
(20, 33 and 59 words) and the photo card (33 words); the new test checks that every
card size and word count fits.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant