start draw

main
Matthew Butterick 5 years ago
parent 6ecd6eee90
commit 66f4d93b13

@ -4,13 +4,13 @@
"Hello world" "Hello world"
(q ((position "absolute") (q ((draw "line") (x1 "10") (y1 "10") (x2 "100") (y2 "200")))
(draw "line") (q ((draw "line") (x1 "100") (y1 "200") (x2 "200") (y2 "100")))
(x1 "10") (y1 "10")
(x1 "100") (y1 "100")) "duh")
(q ((break "page"))) (q ((break "page")))
"Goodbye fools" "Goodbye fools"
(q ((draw "text")(font-italic "true")(x "20")(y "20")(text "Hello from 20,20")) "outside")
) )

@ -82,7 +82,17 @@ Naming guidelines
no-colbr no-colbr
no-pbr no-pbr
page-number page-number
doc-title)) doc-title
draw
position
text
x
y
x1
x2
y1
y2))
(define-attrs block-attrs (display (define-attrs block-attrs (display
@ -187,7 +197,13 @@ Naming guidelines
:font-size :font-size
:font-tracking :font-tracking
:font-baseline-shift :font-baseline-shift
:line-height)) #true)) :line-height
:x
:y
:x1
:x2
:y1
:y2)) #true))
(define (takes-path? k) (define (takes-path? k)
(and (memq k (list :image-file)) #true)) (and (memq k (list :image-file)) #true))

@ -22,18 +22,21 @@
(define-quad string-quad quad) (define-quad string-quad quad)
(define (q:string-draw q doc) (define (q:string-draw q doc
(when (pair? (quad-elems q)) #:origin [origin-in #f]
#:text [str-in #f])
(match (or str-in (and (pair? (quad-elems q)) (unsafe-car (quad-elems q))))
[#false (void)]
[str
(font doc (path->string (quad-ref q font-path-key default-font-face))) (font doc (path->string (quad-ref q font-path-key default-font-face)))
(font-size doc (quad-ref q :font-size default-font-size)) (font-size doc (quad-ref q :font-size default-font-size))
(fill-color doc (quad-ref q :font-color default-font-color)) (fill-color doc (quad-ref q :font-color default-font-color))
(define str (unsafe-car (quad-elems q))) (match-define (list x y) (or origin-in (quad-origin q)))
(match-define (list x y) (quad-origin q))
(text doc str x (- y (quad-ref q :font-baseline-shift 0)) (text doc str x (- y (quad-ref q :font-baseline-shift 0))
#:tracking (quad-ref q :font-tracking 0) #:tracking (quad-ref q :font-tracking 0)
#:bg (quad-ref q :bg) #:bg (quad-ref q :bg)
#:features (quad-ref q :font-features default-font-features) #:features (quad-ref q :font-features default-font-features)
#:link (quad-ref q :link)))) #:link (quad-ref q :link))]))
(define (q:string-draw-end q doc) (define (q:string-draw-end q doc)
(when (draw-debug-string?) (when (draw-debug-string?)
@ -99,7 +102,26 @@
[else 0])) [else 0]))
(list string-size (quad-ref q :line-height (current-line-height pdf))))) (list string-size (quad-ref q :line-height (current-line-height pdf)))))
(define (maybe-do-image-quad? q) (define (maybe-convert-draw-quad q)
(define draw-type (quad-ref q :draw))
(and draw-type
(quad-update! q
[draw (λ (q doc)
(save doc)
(match draw-type
["line"
(move-to doc (quad-ref q :x1) (quad-ref q :y1))
(line-to doc (quad-ref q :x2) (quad-ref q :y2))
(stroke doc "black")]
["text" (move-to doc 0 0)
(q:string-draw q doc
#:origin (pt (quad-ref q :x 0) (quad-ref q :y 0))
#:text (quad-ref q :text))]
[_ (void)])
(restore doc))]
[size (pt 0 0)])))
(define (maybe-convert-image-quad q)
(define path-string (quad-ref q :image-file)) (define path-string (quad-ref q :image-file))
(and path-string (and path-string
(let () (let ()
@ -128,7 +150,7 @@
h)] h)]
[size #:parent quad (pt layout-width layout-height)])))) [size #:parent quad (pt layout-width layout-height)]))))
(define (maybe-do-line-break-quad? q) (define (maybe-convert-line-break-quad q)
(and (line-break-quad? q) q)) (and (line-break-quad? q) q))
(define (do-string-quad q) (define (do-string-quad q)
@ -142,8 +164,9 @@
(define (generic->typed-quad q) (define (generic->typed-quad q)
(or (or
(maybe-do-line-break-quad? q) (maybe-convert-line-break-quad q)
(maybe-do-image-quad? q) (maybe-convert-draw-quad q)
(maybe-convert-image-quad q)
(do-string-quad q))) (do-string-quad q)))

Loading…
Cancel
Save