main
Matthew Butterick 10 years ago
parent 8eced29892
commit 44a806bde5

@ -1,5 +1,5 @@
#lang racket/base
(require racket/list sugar)
(require racket/list sugar/define)
(require "samples.rkt" "quads.rkt" "utils.rkt")
(define ti (block '(measure 54 leading 18) "Meg is " (box '(foo 42)) " ally."))
@ -15,7 +15,7 @@
;; 2) be compact / not duplicate information unnecessarily
;; 3) allow sequential access to the tokens
;; 4) allow fast computation of token state (i.e., attrs that apply)
(define (make-tokens-and-attrs quad-in)
(define+provide (make-tokens-and-attrs quad-in)
(define-values (all-tokens all-attrs _)
(let loop ([current-quad quad-in][attr-acc empty][starting-tidx 0])
(cond
@ -49,9 +49,9 @@
(values (list->vector (reverse (flatten all-tokens))) (flatten all-attrs)))
(define-values (tokens attrs) (time (make-tokens-and-attrs (ti5))))
(define current-tokens (make-parameter tokens))
(define current-token-attrs (make-parameter attrs))
(define-values (tokens attrs) (make-tokens-and-attrs (ti5)))
(define+provide current-tokens (make-parameter tokens))
(define+provide current-token-attrs (make-parameter attrs))
;(filter (λ(idx) (box? (vector-ref tokens idx))) (range (vector-length tokens)))
@ -61,6 +61,3 @@
(define (calc-attrs tref)
(map attr-ref-hash (filter (λ(attr) (<= (attr-ref-start attr) tref (sub1 (attr-ref-end attr)))) (current-token-attrs))))
(vector-ref tokens 4)
(time (calc-attrs 4))

@ -224,5 +224,5 @@
(parameterize ([world:quality-default world:adaptive-quality]
[world:paper-width-default 600]
[world:paper-height-default 700])
(define to (begin (time (typeset (ti5)))))
(define to (begin (time (typeset (jude0)))))
(time (send (new pdf-renderer%) render-to-file to "foo.pdf"))))

@ -68,19 +68,19 @@
(check-equal? (quad-append (box #f "foo") (box #f "bar")) (box #f "foo" (box #f "bar")))
(check-equal? (quad-last-char (box #f (box #f "foo") "food")) "d")
(check-equal? (quad-last-char (box #f (box #f "foo") "")) "o")
(check-equal? (quad-last-char (box #f (box #f "foo"))) "o")
(check-equal? (quad-last-char (box #f "foo")) "o")
(check-false (quad-last-char (box)))
(check-equal? (quad-first-char (box #f (box #f "foo") "bar")) "f")
(check-equal? (quad-first-char (box #f "" (box #f "foo") "bar")) "f")
(check-equal? (quad-first-char (box #f (box #f "foo") "bar")) "f")
(check-equal? (quad-first-char (box #f "foo")) "f")
(check-false (quad-first-char (box)))
(check-equal? (quad->string (box '(width 100) "foo")) "foo")
(check-equal? (quad->string (box '(width 100) "foo" (box '(width 100) "bar"))) "foobar")
(check-equal? (quad->string (box '(width 100) "foo" (box '(width 100) "bar") "ino")) "foobarino")
(check-equal? (quad->string (box '(width 100) (box '(width 100)))) "")
(check-equal? (quad->string (box '(width 100))) "")
(check-false (whitespace? (~a #\u00A0)))
@ -91,3 +91,13 @@
(define funny-unicode-spaces (map ~a (list #\u2000 #\u2007 #\u2009 #\u200a #\u202f)))
(check-true (andmap whitespace? funny-unicode-spaces))
(check-true (andmap whitespace/nbsp? funny-unicode-spaces))
(require "experimental.rkt")
(define ti (block '(measure 54) "Meg is " (box '(foo 42)) " ally."))
(define-values (tokens attrs) (make-tokens-and-attrs ti))
(current-tokens tokens)
(current-token-attrs attrs)
(check-equal? tokens (vector #\M #\e #\g #\space #\i #\s #\space (box) #\space #\a #\l #\l #\y #\.))
(check-equal? attrs '(#(#hash((measure . 54)) 0 14) #(#hash((foo . 42)) 7 8)))

Loading…
Cancel
Save