parse dimension better

main
Matthew Butterick 6 years ago
parent b7525a94a1
commit 71e5ef7353

@ -18,7 +18,7 @@ Naming guidelines
(define (in->pts x) (* 72 x))
(define (mm->cm x) (/ x 10))
(define (parse-points x [round? #f])
(define (parse-dimension x [round? #f])
(define val
(match x
[(? number?) x]
@ -26,9 +26,10 @@ Naming guidelines
(match (cdr (regexp-match #rx"^(-?[0-9\\.]+)([a-z]+)$" (string-downcase x)))
[(list num-string unit)
((match unit
[(regexp #rx"in(ch|ches)?") in->pts]
[(regexp #rx"cm") (compose1 in->pts cm->in)]
[(regexp #rx"mm") (compose1 in->pts cm->in mm->cm)]) (string->number num-string))])]))
[(regexp #rx"in(ch(es)?)?$") in->pts]
[(regexp #rx"cm$") (compose1 in->pts cm->in)]
[(regexp #rx"mm$") (compose1 in->pts cm->in mm->cm)]
[_ (raise-argument-error 'parse-dimension "dimension string" x)]) (string->number num-string))])]))
(if round? (inexact->exact (floor val)) val))
(define (copy-block-attrs source-hash dest-hash)

@ -698,7 +698,7 @@
(match-let ([(list page-width page-height) (for/list ([k (list @page-width @page-height)])
(match (quad-ref (car qs) k)
[#false #false]
[val (parse-points val 'round)]))])
[val (parse-dimension val 'round)]))])
;; `make-pdf` will sort out conflicts among page dimensions
(make-pdf #:compress #t
#:auto-first-page #f

Loading…
Cancel
Save