"""Lays a whole French novel out and writes it as one PDF.
The Python twin of the `write_french_book` example in Rust.
The twin of `write_book`, on a text that draws the accented letters as well as
the plain ones. It shows what a wider alphabet costs: more outlines to carry, and
metrics still stated only for the glyphs the book draws.
Usage: python examples/write_french_book.py [out.pdf] [font.ttf]
"""
from __future__ import annotations
import _book
import _licence
import _out
import hqf_pdf
BOOK = _book.Book(
title="Le tour du monde en quatre-vingts jours",
author="Jules Verne",
file="tourdumonde.txt",
)
def main() -> None:
out = _out.output_path("french_book")
document = hqf_pdf.Document()
document.set_license(_licence.licensed())
handle = document.add_font(hqf_pdf.Font.from_path(_out.font_path()))
text = BOOK.path().read_text(encoding="utf-8")
_book.lay_out(document, handle, BOOK, text)
data = document.to_bytes()
out.parent.mkdir(parents=True, exist_ok=True)
out.write_bytes(data)
print(f"wrote {out}: {len(data)} bytes")
if __name__ == "__main__":
main()