start draw

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

@ -4,13 +4,13 @@
"Hello world"
(q ((position "absolute")
(draw "line")
(x1 "10") (y1 "10")
(x1 "100") (y1 "100")) "duh")
(q ((draw "line") (x1 "10") (y1 "10") (x2 "100") (y2 "200")))
(q ((draw "line") (x1 "100") (y1 "200") (x2 "200") (y2 "100")))
(q ((break "page")))
"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-pbr
page-number
doc-title))
doc-title
draw
position
text
x
y
x1
x2
y1
y2))
(define-attrs block-attrs (display
@ -187,7 +197,13 @@ Naming guidelines
:font-size
:font-tracking
:font-baseline-shift
:line-height)) #true))
:line-height
:x
:y
:x1
:x2
:y1
:y2)) #true))
(define (takes-path? k)
(and (memq k (list :image-file)) #true))

@ -22,18 +22,21 @@
(define-quad string-quad quad)
(define (q:string-draw q doc)
(when (pair? (quad-elems q))
(font doc (path->string (quad-ref q font-path-key default-font-face)))
(font-size doc (quad-ref q :font-size default-font-size))
(fill-color doc (quad-ref q :font-color default-font-color))
(define str (unsafe-car (quad-elems q)))
(match-define (list x y) (quad-origin q))
(text doc str x (- y (quad-ref q :font-baseline-shift 0))
#:tracking (quad-ref q :font-tracking 0)
#:bg (quad-ref q :bg)
#:features (quad-ref q :font-features default-font-features)
#:link (quad-ref q :link))))
(define (q:string-draw q doc
#: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-size doc (quad-ref q :font-size default-font-size))
(fill-color doc (quad-ref q :font-color default-font-color))
(match-define (list x y) (or origin-in (quad-origin q)))
(text doc str x (- y (quad-ref q :font-baseline-shift 0))
#:tracking (quad-ref q :font-tracking 0)
#:bg (quad-ref q :bg)
#:features (quad-ref q :font-features default-font-features)
#:link (quad-ref q :link))]))
(define (q:string-draw-end q doc)
(when (draw-debug-string?)
@ -99,7 +102,26 @@
[else 0]))
(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))
(and path-string
(let ()
@ -128,7 +150,7 @@
h)]
[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))
(define (do-string-quad q)
@ -142,8 +164,9 @@
(define (generic->typed-quad q)
(or
(maybe-do-line-break-quad? q)
(maybe-do-image-quad? q)
(maybe-convert-line-break-quad q)
(maybe-convert-draw-quad q)
(maybe-convert-image-quad q)
(do-string-quad q)))

Loading…
Cancel
Save