margin struct

main
Matthew Butterick 5 years ago
parent 269b360a02
commit e15a268650

@ -9,6 +9,9 @@
;; for JPEG and PNG
(struct image (label width height obj) #:transparent #:mutable)
;; for page
(struct margin (top left bottom right) #:transparent #:mutable)
;; params
(define test-mode (make-parameter #f))

@ -67,8 +67,8 @@
(set! @pages (cons (make-object PDFPage this page-parent options-arg) @pages))
;; reset x and y coordinates
(set! @x (hash-ref (get-field margins (page)) 'left))
(set! @y (hash-ref (get-field margins (page)) 'top))
(set! @x (margin-left (get-field margins (page))))
(set! @y (margin-right (get-field margins (page))))
;; flip PDF coordinate system so that the origin is in
;; the top left rather than the bottom left
(set! _ctm default-ctm-value)

@ -4,11 +4,12 @@
"document.rkt"
"page.rkt"
"reference.rkt"
"core.rkt"
sugar/unstable/js)
(define p (make-object PDFPage (make-object PDFDocument)))
(check-equal? (· p size) "letter")
(check-equal? (· p layout) "portrait")
(check-equal? (· p margins) '#hasheq((right . 72) (bottom . 72) (left . 72) (top . 72)))
(check-equal? (· p margins) (margin 72 72 72 72))
(check-equal? (· p height) 792.0)
(check-equal? (· p width) 612.0)
(check-equal? (· p resources payload ProcSet) '("PDF" "Text" "ImageB" "ImageC" "ImageI"))

@ -4,11 +4,10 @@
racket/contract
sugar/unstable/class
sugar/unstable/js
sugar/unstable/dict)
sugar/unstable/dict
"core.rkt")
(provide PDFPage)
(struct margin (top left bottom right) #:transparent #:mutable)
(provide (all-defined-out))
(define PDFPage
(class object%

@ -10,7 +10,8 @@
sugar/unstable/dict
sugar/list
racket/promise
fontland/glyph-position)
fontland/glyph-position
"core.rkt")
(provide text-mixin)
#|
@ -111,7 +112,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee
;; wrap to margins if no x or y position passed
(unless (not (hash-ref options 'lineBreak #t))
(define margins (· this page margins))
(hash-ref! options 'width (λ () (- (· this page width) (· this x) (· margins right)))))
(hash-ref! options 'width (λ () (- (· this page width) (· this x) (margin-right margins)))))
(hash-ref! options 'columns 0)
(hash-ref! options 'columnGap 18) ; 1/4 inch in PS points

Loading…
Cancel
Save