CodexPageLayout.kt

2.1 KB · raw

1package com.peachpasswords.codex23/**4 * A4 Codex page geometry — the exact port of the browser's5 * `popup/codex/pdf-layout.ts`, which is the canonical Codex page format.6 *7 * A Codex is a *cross-platform paper backup*: a PDF printed from the browser8 * extension has to restore on Android and vice versa. That only holds if both9 * sides agree on where every Aztec sits on the page, to the point.10 *11 * They didn't. Android's generator used its own geometry (36pt margin, 54pt12 * header, a computed square cell) and its importer blind-cropped that same13 * private grid, so it could only ever read PDFs it had produced itself. Handed14 * a real browser-generated Codex it cropped the wrong regions and decoded15 * roughly a quarter of the codes — enough to look like a flaky scan rather16 * than a format mismatch.17 *18 * Units are PDF points (1pt = 1/72 inch). Keep these values identical to19 * pdf-layout.ts; drift here silently breaks paper restore across platforms.20 */21object CodexPageLayout {22    const val PAGE_WIDTH = 595.28f23    const val PAGE_HEIGHT = 841.89f2425    const val MARGIN = 28f2627    const val HEADER_HEIGHT = 44f2829    /** Vertical gap between the header hairline and the top of row 0. */30    const val HEADER_GAP = 16f3132    const val CODE_SIZE = 80f3334    /** Horizontal gap between adjacent codes in a row. */35    const val COL_GAP = (PAGE_WIDTH - 2 * MARGIN - CODES_PER_ROW * CODE_SIZE) / (CODES_PER_ROW - 1)3637    /** Space reserved for the per-code numeric label drawn under each Aztec. */38    const val LABEL_HEIGHT = 14f3940    /** Printed white space between a label and the next row's code. */41    const val ROW_GAP = 18f4243    /** Top-of-code-N to top-of-code-N+1 distance — what the importer steps by. */44    const val ROW_STEP = CODE_SIZE + ROW_GAP + LABEL_HEIGHT4546    /** Top of row 0, measured from the top of the page. */47    const val GRID_TOP = MARGIN + HEADER_HEIGHT + HEADER_GAP4849    /** Quiet zone the importer includes around each code, as a fraction of it. */50    const val QUIET_FRACTION = 0.12f5152    fun codeLeft(col: Int): Float = MARGIN + col * (CODE_SIZE + COL_GAP)5354    fun codeTop(row: Int): Float = GRID_TOP + row * ROW_STEP55}