You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/pitfall/pitfall/pdftest.rkt

41 lines
1.2 KiB
Racket

#lang pitfall/racket
(provide (all-from-out pitfall/racket))
(provide check-copy-equal? check-pdfkit? make-doc)
(test-mode #t)
(r+p rackunit racket/runtime-path pitfall/document)
(define (this->control this) (path-add-extension this #"" #" copy."))
(define (this->pdfkit-control this)
(string->path (string-replace (path->string this) "rkt." ".")))
(module+ test
(require rackunit)
(check-equal? (this->pdfkit-control (string->path "test1crkt.pdf")) (string->path "test1c.pdf")))
(define-syntax-rule (check-copy-equal? this)
(check-equal? (file->bytes this) (file->bytes (this->control this))))
(define-syntax-rule (check-pdfkit? this)
(check-equal? (bytes-length (file->bytes this))
(bytes-length (file->bytes (this->pdfkit-control this)))))
(define (make-doc ps compress? [proc (λ (doc) doc)] #:test [test? #t] #:pdfkit [pdfkit? #t])
(define doc (make-object PDFDocument (hash 'compress compress?)))
(send doc pipe (open-output-file ps #:exists 'replace))
(proc doc)
(send doc end)
(when test?
(check-copy-equal? ps)
(when pdfkit?
(check-pdfkit? ps))))
(module reader syntax/module-reader
#:language 'pitfall/pdftest
#:read read
#:read-syntax read-syntax)