Skip to content

Commit cae8803

Browse files
committed
add book cover
1 parent 403824d commit cae8803

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

cover.png

887 KB
Loading

scripts/build_pdf.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,17 @@ def draw(self):
347347

348348

349349
class CoverImage(Flowable):
350+
"""Placeholder flowable that triggers a page — the actual image is drawn by the page template."""
350351
def __init__(self, path):
351352
super().__init__()
352-
self.path = path; self.height = PAGE_H
353+
self.path = path
354+
self.height = 1 # minimal height, actual drawing is in onPage
353355

354356
def wrap(self, aw, ah):
355-
return (PAGE_W, PAGE_H)
357+
return (aw, 1)
356358

357359
def draw(self):
358-
self.canv.drawImage(self.path, -ML, -MB, width=PAGE_W, height=PAGE_H,
359-
preserveAspectRatio=True, anchor="c", mask="auto")
360+
pass # drawn by _pg_cover_with_image instead
360361

361362

362363
class AccentBar(Flowable):
@@ -397,8 +398,11 @@ def fn(cv, doc):
397398
cv.restoreState()
398399
return fn
399400

400-
def _pg_cover(T):
401-
def fn(cv, doc): pass
401+
def _pg_cover(T, image_path=None):
402+
def fn(cv, doc):
403+
if image_path and os.path.exists(image_path):
404+
cv.drawImage(image_path, 0, 0, width=PAGE_W, height=PAGE_H,
405+
preserveAspectRatio=False, mask="auto")
402406
return fn
403407

404408

@@ -590,7 +594,7 @@ def build_pdf(output, dark=False):
590594
fr_cover = Frame(0, 0, PAGE_W, PAGE_H, id="cover",
591595
leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0)
592596
doc.addPageTemplates([
593-
PageTemplate(id="cover", frames=fr_cover, onPage=_pg_cover(T)),
597+
PageTemplate(id="cover", frames=fr_cover, onPage=_pg_cover(T, cover if os.path.exists(cover) else None)),
594598
PageTemplate(id="blank", frames=fr, onPage=_pg_blank(T)),
595599
PageTemplate(id="normal", frames=fr, onPage=_pg_normal(T)),
596600
])

0 commit comments

Comments
 (0)