;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; UTILS ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define num number->string) (define (mm x) ; add mm mark (string-append (num x) "mm")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DEFINITIONS ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; SIZE ; INFO: Setting viewbox and size to the same it makes the measurements real ; world ones, in this case millimeters ; Read more: https://mpetroff.net/2013/08/analysis-of-svg-units/ (define (elenq-logo sub size x y . extra) ; 10 x 4mm `(g (@ (id "elenq-logo") (transform ,(string-append "translate(" (num x) "," (num y) ")" "scale(" (num size) ")" (if (< 0 (length extra)) (string-append "rotate (" (num (first extra)) ")") "") ))) (g (@ (transform "scale(0.1667)")) (text (@ (x 0) (y 0) (style "font-size: 30; line-height: 1.25; font-family: armata; stroke: none; text-anchor: middle")) "ElenQ") (text (@ (x 0) (y 8) (style "font-size: 10; line-height: 1.25; font-family: armata; stroke: none; text-anchor: middle;")) ,sub)))) ;(define elenq-technology (elenq-logo "TECHNOLOGY" 1 0 0)) ;(define elenq-publishing (elenq-logo "PUBLISHING" 1 0 0)) ; Text area, Inkscape-only svg parameter (define (textArea text class x y w h) `(flowRoot (@ (class ,class)) (flowRegion (rect (@ (width ,w) (height ,h) (x ,x) (y ,y)))) ,(map (lambda (p) `(flowPara ,p)) (reverse (fold (lambda (s acc) (if (string=? s "") (cons "" acc) (let* ((prev (car acc)) (val (string-append prev (if (string=? "" prev) "" " ") s))) (cons val (cdr acc))))) (list "") (string-split text #\newline)))))) (define (metadata->svg metadata outport) (let* (;B5 Paper size (page-height 250) ;mm (page-width 176) ;mm (margin 3) ;mm (isbn "9780201379624") (book-title "Programación en Python") (book-subtitle "Introducción a la programación y al lenguaje") (book-title-before "") ; TODO: Thinking about removing this (book-title-after book-subtitle) (book-category "Básico") (book-authors '("Giacomo Tesio" "Ekaitz Zarraga")) (book-summary " ") (company-info "") (main-title-size (let ((size (exact->inexact (* 3 (/ page-width (length (string->list book-title))))))) (if (< (/ page-height 5) size) (exact->inexact (/ page-height 5)) size))) ;mm (spine-width 10) ;mm TODO (spine-title-margin-min (* 0.1 spine-width)) (spine-title-max-size 10) (spine-title-size (let ((size (- spine-width (* 2 spine-title-margin-min)))) (if (> size spine-title-max-size) spine-title-max-size size))) (text-size (exact->inexact (/ page-height 70))); mm (category-size (* 1.5 text-size)); mm (authors-size (* 1.8 text-size)) (title-size (* 2.5 text-size)); mm (main-subtitle-size (* 2 text-size)) (main-title-width (exact->inexact (* 6/8 page-width))) (main-title-margin (/ (- page-width main-title-width) 2)) (width (+ (* 2 margin) (* 2 page-width) spine-width)) ;mm (height (+ (* 2 margin) page-height)) ;mm (viewBox (string-append "0 0 " (num width) " " (num height))) (style (string-append " .margin-mark { stroke-width: 0.1; stroke-linecap: butt; stroke: red; } .title-back { font-family: 'Pathway Gothic One'; font-size: "(num title-size)"; fill: white; } .title-spine { font-family: 'Pathway Gothic One'; font-size: "(num spine-title-size)"; dominant-baseline: mathematical; fill: black; } .authors-spine { font-family: 'Lato'; font-size: "(num text-size)"; dominant-baseline: mathematical; text-anchor: end; } #black-part { fill: black; } .text-elenq{ font-family:Lato; -inkscape-font-specification:'Lato Light Italic'; font-style: italic; font-weight: 300; fill: black; font-size: "(num text-size)"; text-align: justify; } .text-summary { font-family:Lato; font-size: "(num text-size)"; fill: white; text-align: justify; } rect.category{ fill: black; } text.category{ fill: white; font-size: "(num category-size)"; -inkscape-font-specification:'Lato Light'; font-family:Lato; font-weight: 300; } .main-title { font-size: "(num main-title-size)"; font-family: 'Pathway Gothic One'; } .main-title-before { font-size: "(num (* 1 title-size))"; font-family: 'Pathway Gothic One'; font-weight:300; } .main-title-after { font-size: "(num main-subtitle-size)"; -inkscape-font-specification:'Lato Light Italic'; line-height: 0.9; font-style: italic; font-family:Lato; font-weight: 300; text-anchor: middle; } .author { font-size: "(num authors-size)"; font-family:Lato; text-anchor: end; } "))) (display "" outport) (display (sxml->xml `(svg (@ (width ,(mm width)) (height ,(mm height)) (viewBox ,viewBox)) (defs (style ,style)) ; BLACK BACKGROUND FOR SUMMARY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (g (@ (transform ,(string-append ; TODO extender lo negro en el margen "translate( 0," (num (+ margin (* 0.05 page-height))) ") scale(" (num (+ margin (* 0.95 page-width))) ")"))) (path (@ (id "black-part") (d "M 1.00, 0.10 L 0.30, 0.00 L 0.00, 0.16 L 0.00, 0.67 L 0.45, 0.76 L 0.97, 0.67 Z")))) ;; CUTTING MARKS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ,(map (lambda (posx posy rot) `(g (@ (id ,(string-append "marks-" (num posx) "-" (num posy))) (transform ,rot)) (line (@ (x1 ,(+ posx)) (y1 ,(+ posy margin)) (x2 ,(+ posx (* 0.6 margin))) (y2 ,(+ posy margin)) (class "margin-mark"))) (line (@ (x1 ,(+ posx margin)) (y1 ,(+ posy)) (x2 ,(+ posx margin)) (y2 ,(+ posy (* 0.6 margin))) (class "margin-mark"))))) (list 0 0 width width) (list 0 height 0 height) (list "rotate(0,0,0)" (string-append "rotate(-90, 0," (num height) ")") (string-append "rotate(-270," (num width) ", 0)") (string-append "rotate(-180," (num width) "," (num height) ")"))) ;; BACK SIDE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; TITLE + BOOK SUMMARY (text (@ (class "title-back") (x ,(+ margin (* 0.15 page-width))) (y ,(+ margin (* page-height 0.20)))) ,(string-upcase book-title)) ,(textArea book-summary "text-summary" (+ margin (* 0.15 page-width)) (+ margin (* page-height 0.20)) (* 0.7 page-width) (* 0.25 page-height)) ; LOGO + ELENQ SUMMARY ,(elenq-logo "TECHNOLOGY" 3 (* (+ (+ margin (* 0.5 page-width)) (+ margin (* 0.5 page-width) (- (* 0.5 page-width) (* 0.1 page-width)))) 0.5) (+ margin (* 0.70 page-height) -10)) ,(textArea company-info "text-elenq" (+ margin (* 0.5 page-width)) (+ margin (* 0.70 page-height)) (- (* 0.5 page-width) (* 0.1 page-width)) (- (* 0.25 page-height) (* 0.1 page-height))) ; BARCODE ,(barcode-sxml isbn (+ margin (* 0.1 page-width)) (+ margin (* 0.75 page-height)) (* 0.25 page-width)) ;; SPINE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ,(let ((x (+ margin page-width)) (y height) (width (+ margin margin page-height)) (height spine-width)) `(g (@ (transform ,(string-append "translate(" (num x) "," (num y) ") rotate (-90)"))) (rect (@ (height ,height) (width ,width) (style "fill: white;"))) (text (@ (class "title-spine") (x ,(* 0.2 width)) (y ,(* 0.5 spine-width)) (width ,(* 0.3 width)) (height ,spine-title-size)) ,book-title) (text (@ (class "authors-spine") (x ,(* 0.9 width)) (y ,(* 0.5 spine-width)) (width ,(* 0.3 width)) (height ,spine-title-size)) ,(string-join book-authors ", ")))) ,(if (< spine-width 10) ; Smaller than 10mm -> Renders just a Q `(text (@ (style ,(string-append "font-family: armata; text-anchor: middle; font-size: " (num spine-width))) (x ,(+ margin page-width (* 0.5 spine-width))) (y ,(+ margin (* 0.95 page-height)))) "Q") (elenq-logo "PUBLISHING" ; Max logo size is as the spine was 40mm thick (* (if (< 40 spine-width) 40 spine-width) 0.1 0.75) (+ margin page-width (* 0.5 spine-width)) ;anchor is centered (+ margin (* 0.95 page-height)))) ;; FRONT SIDE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ,(let* ((win (* 0.35 page-width)) (w (+ win margin)) (h (* 1.5 category-size)) (x (- width margin win)) (y (+ margin (* 0.15 page-height)))) `(g (rect (@ (class "category") (x ,x) (y ,y) (width ,w) (height ,h))) (text (@ (class "category") (x ,(+ x (* 0.10 w))) (y ,(+ y (* 0.75 h))) (w ,w) (h ,h)) ,book-category))) (text (@ (class "main-title-before") (x ,(exact->inexact (- width (- page-width (/ (- page-width main-title-width) 2)) margin))) (y ,(+ margin (* 0.30 page-height)))) ,book-title-before) (text (@ (class "main-title") (textLength ,main-title-width) (lengthAdjust ,"spacingAndGlyphs") (x ,(exact->inexact (- width main-title-width main-title-margin margin))) (y ,(+ main-title-size margin (* 0.30 page-height)))) ,(string-upcase book-title)) #;(text (@ (class "main-title-after") (x ,(exact->inexact (- width (/ page-width 8) margin))) (y ,(+ main-title-size (* 1.25 title-size) margin (* 0.30 page-height)))) ,book-title-after) ; TODO WORK ON THIS ,(textArea book-title-after "main-title-after" (exact->inexact (- width margin main-title-margin main-title-width)) (+ main-title-size (* main-subtitle-size 0.5) margin (* 0.30 page-height)) main-title-width (* 2 1.25 main-subtitle-size)) ,(map (lambda (author pos) `(text (@ (class "author") (x ,(exact->inexact (- width main-title-margin margin))) (y ,(+ main-title-size margin (* 0.35 page-height) (* (+ 2 pos) (* 1.3 authors-size))))) ,author)) book-authors (iota (length book-authors))) ,(elenq-logo "PUBLISHING" 3 (exact->inexact (- width (/ page-width 2) margin)) (+ margin (* 0.95 page-height))))) outport)))