"""Generate minimal EPUB + PDF fixtures for the Windows smoke test. Run: python3 tests/fixtures/windows-smoke/make_fixtures.py Outputs kanzi-dummy.epub and kanzi-dummy.pdf next to this script. Both contain the highlight sentences from 'My Clippings.txt' so EPUB CFI and PDF text positioning can succeed. """ from __future__ import annotations from pathlib import Path import zipfile HERE = Path(__file__).resolve().parent EPUB_TEXT = "This is a test highlight long enough to import for EPUB." PDF_TEXT = "This is a test highlight long enough to import for PDF." def make_epub(path: Path) -> None: chapter = f""" Kanzi Dummy

Kanzi Dummy EPUB

Some intro text before the highlight.

{EPUB_TEXT}

Some trailing text after the highlight.

""" container = """ """ opf = """ Kanzi Dummy EPUBkanzi-dummy-epuben """ with zipfile.ZipFile(path, "w") as z: z.writestr("mimetype", "application/epub+zip", compress_type=zipfile.ZIP_STORED) z.writestr("META-INF/container.xml", container, compress_type=zipfile.ZIP_DEFLATED) z.writestr("OEBPS/content.opf", opf, compress_type=zipfile.ZIP_DEFLATED) z.writestr("OEBPS/chapter1.xhtml", chapter, compress_type=zipfile.ZIP_DEFLATED) def _pdf_escape(text: str) -> str: return text.replace("\\", "\\\\").replace("(", "\\(").replace(")", "\\)") def make_pdf(path: Path) -> None: # Minimal one-page PDF with Helvetica text. pdftotext extracts it fine. content = ( f"BT /F1 12 Tf 72 720 Td ({_pdf_escape('Kanzi Dummy PDF')}) Tj ET\n" f"BT /F1 12 Tf 72 700 Td ({_pdf_escape(PDF_TEXT)}) Tj ET\n" ) objects: list[bytes] = [] objects.append(b"<< /Type /Catalog /Pages 2 0 R >>") objects.append(b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>") objects.append( b"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] " b"/Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >>" ) objects.append(b"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>") objects.append(f"<< /Length {len(content.encode('latin-1'))} >>\nstream\n{content}endstream".encode("latin-1")) out = bytearray(b"%PDF-1.4\n") offsets = [0] for i, body in enumerate(objects, start=1): offsets.append(len(out)) out += f"{i} 0 obj\n".encode("ascii") + body + b"\nendobj\n" xref_pos = len(out) out += f"xref\n0 {len(objects) + 1}\n".encode("ascii") out += b"0000000000 65535 f \n" for off in offsets[1:]: out += f"{off:010d} 00000 n \n".encode("ascii") out += ( f"trailer\n<< /Size {len(objects) + 1} /Root 1 0 R >>\n" f"startxref\n{xref_pos}\n%%EOF\n" ).encode("ascii") path.write_bytes(bytes(out)) def main() -> None: make_epub(HERE / "kanzi-dummy.epub") make_pdf(HERE / "kanzi-dummy.pdf") print("wrote kanzi-dummy.epub + kanzi-dummy.pdf") if __name__ == "__main__": main()