Skip to content

Commit

Permalink
Double-sided printing
Browse files Browse the repository at this point in the history
  • Loading branch information
fmthoma committed Oct 2, 2022
1 parent 71af6e5 commit fd8ecab
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/Zureg/Main/BadgesPdf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,32 @@ pageHeight = millimeters 297
createRegistrantPdf :: C.SVG -> [Registrant a] -> C.Render ()
createRegistrantPdf _ [] = pure ()
createRegistrantPdf template registrants = do
renderPage cardsPerPageH cardsPerPageV template registrants
renderPage Front cardsPerPageH cardsPerPageV template registrants
C.showPage
renderPage Back cardsPerPageH cardsPerPageV template registrants
C.showPage
createRegistrantPdf template (drop cardsPerPage registrants)
where
cardsPerPageH = floor (pageWidth / cardWidth)
cardsPerPageV = floor (pageHeight / cardHeight)
cardsPerPage = cardsPerPageH * cardsPerPageV

renderPage :: Int -> Int -> C.SVG -> [Registrant a] -> C.Render ()
renderPage cardsPerPageH cardsPerPageV template registrants = do
data PageSide = Front | Back

renderPage :: PageSide -> Int -> Int -> C.SVG -> [Registrant a] -> C.Render ()
renderPage side cardsPerPageH cardsPerPageV template registrants = do
C.save
C.translate leftMargin topMargin
for_ (distributeOnPage cardsPerPageH cardsPerPageV registrants) $ \row -> do
C.save
for_ row $ \reg -> do
for_ (zip row [0..]) $ \(reg, col) -> do
C.save
let xPos = case side of
Front -> cardWidth * fromIntegral col
Back -> cardWidth * fromIntegral (cardsPerPageH - col - 1)
C.translate xPos 0
registrantCard template reg
C.translate cardWidth 0
C.restore
C.restore
C.translate 0 cardHeight
C.restore
Expand Down

0 comments on commit fd8ecab

Please sign in to comment.