|(require bookcover/draw)||package: bookcover|
This module is automatically provided by #lang bookcover. The only difference between the require form and #lang bookcover is that with the former, finish-cover is not automatically called at the end of your program. You might prefer to use the require form when doing something fancier than creating just a single static cover; for example, when defining your own functions that create multiple book covers of the same style for different titles.
interior-pdf : path-string? cover-pdf-filename : path-string? bleed-pts : real? = (* 0.125 72)
spinewidth-calc : (exact-positive-integer? . -> . real?) = (createspace-spine 'white-bw)
The cover dimensions are calculated as follows:
The width and height of the first page in interior-pdf are used as the size of the front and back covers.
The page count of interior-pdf is passed to spinewidth-calc to determine the width of the spine. (See spine width calculators.)
A width equal to bleed-pts is added to all four edges of the cover.
; The minimum viable setup call (setup #:interior-pdf "my-book-contents.pdf" #:cover-pdf "cover.pdf") ; Using more options: (setup #:interior-pdf "my-book-contents.pdf" #:cover-pdf "cover.pdf" #:spinewidth-calc (using-ppi 339) ; Calculate spine width using 339 PPI #:bleed-pts (inches->pts 0.25)) ; Use 1/4" bleed
If setup has not yet been called since the start of the program, or if it hasn’t been called since the last time finish-cover was called, then there is no active cover, and current-cover-dc will return null.
If current-cover-dc is already null, calling this function has no effect.
In order to properly calculate the overall width of the book cover, the module needs (among other things) a way to calculate the thickness of your book’s spine.
This spine width calculator is any function that takes a page count (a positive integer) and returns a value in points.
You may pass any such function to the #:spine-calculator argument of setup; if you choose not to, setup will default to the function returned by (createspace-spine 'white-bw) —
Different printers specify different ways of calculating the spine width of your book. As a convenience, this module provides some functions which return ready-made spine width calculators that cover the most common cases, but you can also supply your own.
→ (exact-positive-integer? . -> . real?) paper-type : (or/c 'white-bw 'cream-bw 'color)
Use this if your printing service instructs you to calculate spine width using a PPI value for a particular paper type.
(frontcover-draw pic [ #:top top #:left left #:horiz-center? hcenter #:vert-center? vcenter]) → void? pic : pict-convertible? top : real? = 0 left : real? = 0 hcenter : any/c = #f vcenter : any/c = #f
(backcover-draw pic [ #:top top #:left left #:horiz-center? hcenter #:vert-center? vcenter]) → void? pic : pict-convertible? top : real? = 0 left : real? = 0 hcenter : any/c = #f vcenter : any/c = #f
; These two lines do exactly the same thing: (cover-draw pic 0 0) (backcover-draw pic) ; These two lines also do exactly the same thing: (cover-draw pic (spinerightedge) 0) (frontcover-draw pic)
The 0 coordinates for either function’s #:top argument (as well as the #:left argument of backcover) start at the very outside edge of the bleed.
When hcenter is #t, left is ignored; likewise when vcenter is #t, top is ignored.
By design, this function does not check or care if pic will fit inside spinewidth.
; Draw some text on the spine (define spine-title (text "My Book Title" "Helvetica" 10 (degrees->radians 270))) (spine-draw spine-title (centering-offset spine-title page-height pict-height)) ; Draw a blue rectangle that wraps around the spine equally on front and back (define spine-rectangle (filled-rectangle (* (spinewidth) 4) (pageheight) #:color "lightblue" #:draw-border #f)) (spine-draw spine-rectangle)
When setting up your cover, everything is specified in points. But when you ask Racket for the dimensions of the PDF object you’ve just created, you’ll get a different value than the point value you specified. This is because PDF objects in Racket also have a scaling factor (0.8 by default) that is applied to each dimension when the object is created. So if you specify that your cover should have a bleed of 9 points (1/8 inch), the “actual” width —
The (pagewidth) includes the width of the bleed along one edge (i.e. the right edge for the front cover, the left edge for the back cover).
pic : pict-convertible? context-dim : real? dim-func : (pict? . -> . real?) = pict-width
If centering vertically, use pict-height as the last argument.
> (define blue-rectangle (filled-rectangle 20 60 #:color "blue")) > (centering-offset blue-rectangle 100)
> (centering-offset blue-rectangle 250 pict-height)
output-pdf : path-string? width-pts : real? height-pts : real? page-count : exact-positive-integer? = 1
This PDF can be useful for mocking up a cover if you don’t yet have a PDF of your book’s interior to pass to the setup function, or for rapidly experimenting with different paper sizes. See the documentation for check-cover for an example.
unit-func : (real? . -> . string?) = pts->inches-string
> (dummy-pdf "my-book.pdf" (inches->pts 4) (inches->pts 6) #:pages 100)
> (setup #:interior-pdf "my-book.pdf" #:cover-pdf "my-cover.pdf") > (check-cover)
pdf-dc% get-size: 763.75 ⨉ 562.5
Cover size (w/bleed): 8.475″ ⨉ 6.25″ (610.2144pts ⨉ 450.0pts, w/scaling 762.768 ⨉ 562.5)
Scaling factor: 0.8
Bleed: 0.125″ (11.25)
Interior PDF size: 4.0″ ⨉ 6.0″
Interior pagecount: 100 pages
Spine multiplier: 0.162144
Spine width: 0.225″ (100 pages ⨉ 0.162144 = 16.2144 pts)
CreateSpace would not allow text on spine (pages < 101)