summaryrefslogtreecommitdiff
path: root/Makefile.scm
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-07-16 17:13:02 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-07-16 17:13:02 +0200
commitf3868f9d7be48f24a1505cd596f5b73ae733e916 (patch)
tree1d3dfe79ea834bd741b14fa7785d05e8ef69c505 /Makefile.scm
parent96d77792fcc799b6eb2bfa18ec044e2de8c36d0a (diff)
Add PDF cover creation system
Diffstat (limited to 'Makefile.scm')
-rw-r--r--Makefile.scm29
1 files changed, 27 insertions, 2 deletions
diff --git a/Makefile.scm b/Makefile.scm
index 6a40e43..72565b4 100644
--- a/Makefile.scm
+++ b/Makefile.scm
@@ -4,6 +4,7 @@ exec chibi-scheme -A utils/ $0 $@
|#
(import (chibi)
(chibi json)
+ (chibi string)
(only (chibi filesystem)
directory-files
create-directory*
@@ -11,7 +12,6 @@ exec chibi-scheme -A utils/ $0 $@
(chibi process)
(only (chibi pathname) path-strip-directory path-extension make-path)
;(chibi app)
- (only (chibi string) string-prefix? string-trim-right string-join)
(prefix (chibi io) io:)
(utils cover cover)
(srfi 1)
@@ -180,6 +180,20 @@ exec chibi-scheme -A utils/ $0 $@
files)
"Error in ebook creation")))
+(define (get-print-box svg-file)
+ "SVG covers have a rectangle `meta-content-box` prepared to serve as the
+ printing bounding box. Its position is the (x0,y0) and (width,height) is
+ (x1,y1). This function extracts that information."
+ (string-join
+ (string-split
+ (process->string-or-fail
+ `("inkscape"
+ ,svg-file
+ "-I" "meta-content-box"
+ "-XYWH")
+ "Error: impossible to extract cover printing bounding box")
+ #\newline)
+ ":"))
(define (make-cover lang output input)
(let* ((outpath (make-path output lang))
(files (directory-sources lang input))
@@ -197,7 +211,18 @@ exec chibi-scheme -A utils/ $0 $@
"--export-filename" ,(make-path outpath "cover.pdf")
"--export-type=pdf"
,svg-file))
- "Error in cover creation")))
+ "Error in PDF cover creation")
+
+ (process->string-or-fail
+ (append
+ `("inkscape"
+ ,svg-file
+ "--export-filename" ,(make-path outpath "cover.png")
+ "--export-type=png"
+ "--export-background=white"
+ "--export-background-opacity=1.0"
+ "--export-area" ,(get-print-box svg-file)))
+ "Error in PNG cover creation")))
(define (build-lang lang output input)
(pandoc-web lang output input)