From 71e5ef7353deae5aafc7bfd5db930698e5ea3faa Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 26 May 2019 19:00:09 -0700 Subject: [PATCH] parse dimension better --- quad/quadwriter/attrs.rkt | 9 +++++---- quad/quadwriter/core.rkt | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/quad/quadwriter/attrs.rkt b/quad/quadwriter/attrs.rkt index 5f67918c..b371aa21 100644 --- a/quad/quadwriter/attrs.rkt +++ b/quad/quadwriter/attrs.rkt @@ -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) diff --git a/quad/quadwriter/core.rkt b/quad/quadwriter/core.rkt index 9d0b79dc..700568c2 100644 --- a/quad/quadwriter/core.rkt +++ b/quad/quadwriter/core.rkt @@ -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