resolve relative paths in attribute values (closes #38)

main
Matthew Butterick 5 years ago
parent 530f4fad2d
commit 31761a3502

@ -11,7 +11,7 @@
(with-syntax ([PDF-NAME (test-pdf-name (syntax-e #'PATH))])
#'(begin
(parameterize ([quadwriter-test-mode #t])
(render-pdf (dynamic-require PATH 'doc) PDF-NAME))
(render-pdf (dynamic-require PATH 'doc) PDF-NAME PATH))
(make-test-pdf . REST)))]))
(define-syntax (test-each stx)
@ -26,7 +26,7 @@
(define-runtime-path path (path-replace-extension MOD-PATH #".pdf"))
(check-pdfs-equal? (time (parameterize ([quadwriter-test-mode #t]
[current-output-port (open-output-nowhere)])
(render-pdf (dynamic-require path-to-test 'doc) path)
(render-pdf (dynamic-require path-to-test 'doc) path path-to-test)
path)) test-base)
(test-each . REST)))]))

@ -184,3 +184,6 @@ Naming guidelines
:font-tracking
:font-baseline-shift
:line-height)) #true))
(define (takes-path? k)
(and (memq k (list :image-file)) #true))

@ -70,7 +70,7 @@
(current-output-port)
(λ () (with-logging-to-port
(current-output-port)
(λ () (render-pdf DOC pdf-path))
(λ () (render-pdf DOC pdf-path PATH-STRING))
#:logger quadwriter-logger
'debug))
#:logger quad-logger

@ -96,8 +96,16 @@
(hash-set! attrs k (parse-dimension (hash-ref attrs k))))
attrs)
(define (complete-every-path! attrs)
;; relies on `current-directory` being parameterized to source file's dir
(for ([(k v) (in-hash attrs)]
#:when (takes-path? k))
(hash-set! attrs k (path->string (path->complete-path v))))
attrs)
(define (handle-cascading-attrs attrs)
(parse-dimension-strings! attrs)
(complete-every-path! attrs)
(resolve-font-path! attrs)
(resolve-font-size! attrs)
(parse-font-features! attrs))
@ -161,12 +169,19 @@
(define (setup-column-gap qs)
(or (debug-column-gap) (quad-ref (car qs) :column-gap default-column-gap)))
(define/contract (render-pdf qx-arg pdf-path-arg
(define/contract (render-pdf qx-arg pdf-path-arg [base-dir-arg #f]
#:replace [replace-existing-file? #t]
#:compress [compress? #t])
((qexpr? (or/c #false path? path-string?)) (#:replace any/c
((qexpr? (or/c #false path? path-string?))
((or/c #false path? path-string?)
#:replace any/c
#:compress any/c) . ->* . (or/c void? bytes?))
(define base-dir (match base-dir-arg
[#false (current-directory)]
[path (define-values (dir name _) (split-path path))
dir]))
(define pdf-path (setup-pdf-path pdf-path-arg))
(unless replace-existing-file?
(when (file-exists? pdf-path)
@ -176,6 +191,9 @@
#:auto-first-page #false
#:output-path pdf-path))
(parameterize ([current-pdf the-pdf]
;; set `current-directory` so that ops like `path->complete-path`
;; will be handled relative to the original directory
[current-directory base-dir]
[verbose-quad-printing? #false])
(define qs (time-log setup-qs (setup-qs qx-arg pdf-path)))
(define sections

Loading…
Cancel
Save