main
Matthew Butterick 5 years ago
parent e894910d3f
commit 3c39e3ab39

@ -13,7 +13,7 @@
"attrs.rkt"
"param.rkt"
"font.rkt")
(provide hrbr lbr pbr run)
(provide hrbr lbr pbr render-pdf)
(define-quad string-quad quad ())
@ -52,7 +52,7 @@
(define (make-size-promise q [str-arg #f])
(delay
(define doc (current-doc))
(define pdf (current-pdf))
(define str
(cond
[str-arg]
@ -61,16 +61,16 @@
(define string-size
(cond
[str
(font-size doc (quad-ref q 'font-size default-font-size))
(font doc (path->string (quad-ref q font-path-key default-font-face)))
(+ (string-width doc str
(font-size pdf (quad-ref q 'font-size default-font-size))
(font pdf (path->string (quad-ref q font-path-key default-font-face)))
(+ (string-width pdf str
#:tracking (quad-ref q 'character-tracking 0))
;; add one more dose because `string-width` only adds it intercharacter,
;; and this quad will be adjacent to another
;; (so we need to account for the "inter-quad" space
(quad-ref q 'character-tracking 0))]
[else 0]))
(list string-size (quad-ref q 'line-height (current-line-height doc)))))
(list string-size (quad-ref q 'line-height (current-line-height pdf)))))
(define (->string-quad q)
(cond
@ -517,7 +517,7 @@
#:attrs (quad-attrs next-q)
#:size (pt indent-val 0)) qs-out)])))
(define (run xs pdf-path)
(define (render-pdf xs pdf-path)
(define pdf (time-name make-pdf (make-pdf #:compress #t
#:auto-first-page #f
#:output-path pdf-path
@ -525,7 +525,7 @@
#:height (if zoom-mode? 400 792))))
(define line-width (- (pdf-width pdf) (* 2 side-margin)))
(define vertical-height (- (pdf-height pdf) top-margin bottom-margin))
(parameterize ([current-doc pdf]
(parameterize ([current-pdf pdf]
[verbose-quad-printing? #false])
(setup-font-path-table! pdf-path)
(let* ([x (time-name parse-qexpr

@ -5,7 +5,8 @@
quadwriter/core
"tags.rkt"
"font.rkt"
"reader-helper.rkt")
"reader-helper.rkt"
"param.rkt")
(provide (except-out (all-defined-out) mb)
(rename-out [mb #%module-begin])
#%app #%datum #%top-interaction
@ -19,17 +20,22 @@
(define ndash "")
(define mdash "")
(define-syntax-rule (mb PATH-STRING . STRS)
(#%module-begin
;; stick an nbsp in the strings so we have one printing char
(define strs (match (list . STRS)
[(? null?) '(" ")]
[strs strs]))
(define qx (root null (add-between strs (list pbr)
#:before-first (list pbr)
#:after-last (list pbr)
#:splice? #true)))
(run qx (path-string->pdf-path 'PATH-STRING))))
(define-syntax (mb stx)
(syntax-case stx ()
[(_ PATH-STRING . STRS)
(with-syntax ([DOC (datum->syntax #'PATH-STRING 'doc)])
#'(#%module-begin
;; stick an nbsp in the strings so we have one printing char
(define strs (match (list . STRS)
[(? null?) '(" ")]
[strs strs]))
(define DOC (root null (add-between strs (list pbr)
#:before-first (list pbr)
#:after-last (list pbr)
#:splice? #true)))
(provide DOC)
(module+ main
(render-pdf DOC (path-string->pdf-path 'PATH-STRING)))))]))
(module reader racket/base
(require syntax/strip-context

@ -1,6 +1,7 @@
#lang debug racket/base
(provide (all-defined-out))
(define current-doc (make-parameter #f))
(define current-pdf (make-parameter #f))
(define draw-debug? (make-parameter #f))
(define draw-debug-line? (make-parameter #t))

Loading…
Cancel
Save