diff --git a/quad/main-typed-sample.rkt b/quad/main-typed-sample.rkt index 217dc5ee..4f4f8f22 100644 --- a/quad/main-typed-sample.rkt +++ b/quad/main-typed-sample.rkt @@ -1,13 +1,12 @@ #lang typed/racket/base -(require "main-typed.rkt" "logger-typed.rkt" "world-typed.rkt") +(require "main-typed.rkt" "logger-typed.rkt" "world-typed.rkt" "samples-typed.rkt") (require "render.rkt" racket/class profile) -(require "samples.rkt") (activate-logger quad-logger) (parameterize ([world:quality-default world:draft-quality] [world:paper-width-default 600.0] [world:paper-height-default 700.0]) (define sample (ti5)) - sample - #;(define to (begin (time (typeset sample)))) + (define to (begin (time (typeset sample)))) + to #; (time (send (new pdf-renderer%) render-to-file to "foo.pdf"))) \ No newline at end of file diff --git a/quad/main-typed.rkt b/quad/main-typed.rkt index b63673bc..8a2e7d91 100644 --- a/quad/main-typed.rkt +++ b/quad/main-typed.rkt @@ -80,7 +80,6 @@ hyphenate-quad hyphenate-quad-except-last-word) (merge-adjacent-within b)) Quad))) wrapped-lines-without-hyphens)) - (when gets-hyphenation? (log-quad-debug* (log-debug-lines wrapped-lines))) @@ -204,7 +203,7 @@ (for/fold ([current-x : Flonum (/ (- (world:paper-width-default) width-of-printed-area) 2.0)] [cols : (Listof Quad) empty]) ([col (in-list page-cols)][idx (in-naturals)]) - (values (+ current-x column-width column-gutter) (cons (cast (quad-attr-set* col 'x current-x 'y 40 world:column-index-key idx) Quad) cols)))) + (values (+ current-x column-width column-gutter) (cons (cast (quad-attr-set* col 'x current-x 'y 40.0 world:column-index-key idx) Quad) cols)))) (reverse cols)))) result-pages) @@ -215,7 +214,7 @@ ((Listof Quad) . -> . (Listof Quad)) (block->lines (quads->block qs))) -(define/typed (typeset x) +(define/typed+provide (typeset x) (Quad . -> . Quad) ; (coerce/input? . -> . doc?) (load-text-cache-file) (define pages (append* (for/list : (Listof (Listof Quad)) ([multipage (in-list (input->nested-blocks x))]) diff --git a/quad/samples-typed.rkt b/quad/samples-typed.rkt index 203740de..9cb683f2 100644 --- a/quad/samples-typed.rkt +++ b/quad/samples-typed.rkt @@ -1,33 +1,34 @@ #lang typed/racket/base (require "quads-typed.rkt" racket/file racket/string racket/list) +(provide (all-defined-out)) -;(define ti (block '(measure 54 leading 18) "Meg is an ally.")) -(define (ti2) (block '(leading 10 measure 400 size 13 x-align left x-align-last-line left font "Equity Text B") (block #f "Foo-d" (word '(size 13) "og ") "and " (box) "Zu" (word-break '(nb "c" bb "k-")) "kerman’s. Instead of a circle, the result is a picture of the code that, if it were used as an expression, would produce a circle. In other words, code is not a function, but instead a " (block '(style italic) "new syntactic form") " for creating pictures; the bit between the opening " (block '(weight bold) "parenthesis") " with code is not an expression, but instead manipulated by the code syntactic form. " (word '(font "Triplicate T4" size 22.5 color "Orchid" background "Yellow") "Bangazoom!") " This helps explain what we meant in the previous section when we said that racket provides require and the function-calling syntax.") (block-break) (block #f "Libraries are not restricted to exporting values, such as functions; they can also define new syntactic forms. In this sense, Racket isn’t exactly a language at all; it’s more of an idea for how to structure a language so that you can extend it or create entirely new ones."))) +;(define ti (block '(measure 54.0 leading 18.0) "Meg is an ally.")) +(define (ti2) (block '(leading 10.0 measure 400.0 size 13 x-align left x-align-last-line left font "Equity Text B") (block #f "Foo-d" (word '(size 13) "og ") "and " (box) "Zu" (word-break '(nb "c" bb "k-")) "kerman’s. Instead of a circle, the result is a picture of the code that, if it were used as an expression, would produce a circle. In other words, code is not a function, but instead a " (block '(style italic) "new syntactic form") " for creating pictures; the bit between the opening " (block '(weight bold) "parenthesis") " with code is not an expression, but instead manipulated by the code syntactic form. " (word '(font "Triplicate T4" size 22.5 color "Orchid" background "Yellow") "Bangazoom!") " This helps explain what we meant in the previous section when we said that racket provides require and the function-calling syntax.") (block-break) (block #f "Libraries are not restricted to exporting values, such as functions; they can also define new syntactic forms. In this sense, Racket isn’t exactly a language at all; it’s more of an idea for how to structure a language so that you can extend it or create entirely new ones."))) -(define (ti3) (block '(measure 54 leading 18) "Meg is an ally.")) +(define (ti3) (block '(measure 54.0 leading 18.0) "Meg is an ally.")) -(define (ti4) (block '(measure 300 x-align justify x-align-last-line right leading 18) "In this Madagascarian hoo-ha, Racket isn’t exactly a language at all")) +(define (ti4) (block '(measure 300.0 x-align justify x-align-last-line right leading 18.0) "In this Madagascarian hoo-ha, Racket isn’t exactly a language at all")) -(define (ti5) (block '(measure 240 font "Equity Text B" leading 16 vmeasure 300 size 13.5 x-align justify x-align-last-line left) (box '(width 15)) (block #f (block '(weight bold font "Equity Caps B") "Hot" (word '(size 22) "Z") "ogs, My Fellow Americans.") " This " (block '(no-break #t) "is some truly") " bullshit generated from my typesetting system, which is called Quad. I’m writing this in a source file in DrRacket. When I click [Run], a PDF pops out. Not bad\u200a—\u200aand no LaTeX needed. Quad, however, does use the fancy linebreaking algorithm developed for TeX. (It also includes a faster linebreaking algorithm for when speed is more important than quality.) Of course, it can also handle " (block '(font "Triplicate C4") "different fonts,") (block '(style italic) " styles, ") (word '(size 14 weight bold) "and sizes-") " within the same line. As you can see, it can also justify paragraphs." (block-break) (box '(width 15)) (block #f "“Each horizontal row represents an OS-level thread, and the colored dots represent important events in the execution of the program (they are color-coded to distinguish one event type from another). The upper-left blue dot in the timeline represents the future’s creation. The future executes for a brief period (represented by a green bar in the second line) on thread 1, and then pauses to allow the runtime thread to perform a future-unsafe operation.") (column-break) (box '(width 15))(block #f "In the Racket implementation, future-unsafe operations fall into one of two categories. A blocking operation halts the evaluation of the future, and will not allow it to continue until it is touched. After the operation completes within touch, the remainder of the future’s work will be evaluated sequentially by the runtime thread. A synchronized operation also halts the future, but the runtime thread may perform the operation at any time and, once completed, the future may continue running in parallel. Memory allocation and JIT compilation are two common examples of synchronized operations." (page-break) "another page")))) +(define (ti5) (block '(measure 240.0 font "Equity Text B" leading 16.0 vmeasure 300.0 size 13.5 x-align justify x-align-last-line left) (box '(width 15.0)) (block #f (block '(weight bold font "Equity Caps B") "Hot" (word '(size 22.0) "Z") "ogs, My Fellow Americans.") " This " (block '(no-break #t) "is some truly") " bullshit generated from my typesetting system, which is called Quad. I’m writing this in a source file in DrRacket. When I click [Run], a PDF pops out. Not bad\u200a—\u200aand no LaTeX needed. Quad, however, does use the fancy linebreaking algorithm developed for TeX. (It also includes a faster linebreaking algorithm for when speed is more important than quality.) Of course, it can also handle " (block '(font "Triplicate C4") "different fonts,") (block '(style italic) " styles, ") (word '(size 14.0 weight bold) "and sizes-") " within the same line. As you can see, it can also justify paragraphs." (block-break) (box '(width 15.0)) (block #f "“Each horizontal row represents an OS-level thread, and the colored dots represent important events in the execution of the program (they are color-coded to distinguish one event type from another). The upper-left blue dot in the timeline represents the future’s creation. The future executes for a brief period (represented by a green bar in the second line) on thread 1, and then pauses to allow the runtime thread to perform a future-unsafe operation.") (column-break) (box '(width 15.0))(block #f "In the Racket implementation, future-unsafe operations fall into one of two categories. A blocking operation halts the evaluation of the future, and will not allow it to continue until it is touched. After the operation completes within touch, the remainder of the future’s work will be evaluated sequentially by the runtime thread. A synchronized operation also halts the future, but the runtime thread may perform the operation at any time and, once completed, the future may continue running in parallel. Memory allocation and JIT compilation are two common examples of synchronized operations." (page-break) "another page")))) -(define (ti6) (block '(font "Equity Text B" measure 210 leading 14 size 20 x-align justify x-align-last-line left) +(define (ti6) (block '(font "Equity Text B" measure 210.0 leading 14.0 size 20.0 x-align justify x-align-last-line left) "Firstlinerhere" (column-break) "Secondlinerhere" (column-break) "Thirdlinerhere")) -(define/typed (make-sample jude-text line-limit) - (String (Option Integer) . -> . Quad) +(define/typed (make-sample jude-text [line-limit #f]) + ((String) ((Option Integer)) . ->* . Quad) (define sample-string : String (if line-limit (let ([lines : (Listof String) (file->lines jude-text)]) (string-join (take lines (min line-limit (length lines))) "\n")) (file->string jude-text))) (define jude-blocks ((inst map String String) (λ(s) (regexp-replace* #rx"\n" s " ")) (string-split sample-string "\n\n"))) - (apply block '(font "Equity Text B" measure 360 leading 14 column-count 1 column-gutter 10 size 11.5 x-align justify x-align-last-line left) (add-between (map (λ([jb : String]) (block #f (box '(width 10)) (optical-kern) jb)) (filter (λ([jb : String]) (< 0 (string-length jb))) jude-blocks)) (block-break)))) + (apply block '(font "Equity Text B" measure 360.0 leading 14.0 column-count 1 column-gutter 10.0 size 11.5 x-align justify x-align-last-line left) (add-between (map (λ([jb : String]) (block #f (box '(width 10)) (optical-kern) jb)) (filter (λ([jb : String]) (< 0 (string-length jb))) jude-blocks)) (block-break)))) -(define (jude) (make-sample "texts/jude.txt" #f)) -(define (jude0) (make-sample "texts/jude0.txt" #f)) -(define (judebig) (make-sample "texts/judebig.txt" #f)) -(define (segfault) (make-sample "texts/segfault.txt" #f)) +(define (jude) (make-sample "texts/jude.txt")) +(define (jude0) (make-sample "texts/jude0.txt")) +(define (judebig) (make-sample "texts/judebig.txt")) +(define (segfault) (make-sample "texts/segfault.txt")) -(define (jude1) (block '(font "Equity Text B" measure 150 leading 14 column-count 4 size 11 x-align justify x-align-last-line left) "this—is—a—test—of—em—dashes—breakable—or—not?")) \ No newline at end of file +(define (jude1) (block '(font "Equity Text B" measure 150.0 leading 14.0 column-count 4 size 11.0 x-align justify x-align-last-line left) "this—is—a—test—of—em—dashes—breakable—or—not?")) \ No newline at end of file diff --git a/quad/world-typed.rkt b/quad/world-typed.rkt index a3df26d3..c6b06cc0 100644 --- a/quad/world-typed.rkt +++ b/quad/world-typed.rkt @@ -25,7 +25,7 @@ (define-key-and-parameter font-background 'background "none") (define-key-and-parameter column-count 'column-count 2) -(define-key-and-parameter column-gutter 'column-gutter 30) +(define-key-and-parameter column-gutter 'column-gutter 30.0) (define max-quality 100) diff --git a/quad/wrap-typed.rkt b/quad/wrap-typed.rkt index ed2ee4c1..d6857289 100644 --- a/quad/wrap-typed.rkt +++ b/quad/wrap-typed.rkt @@ -385,12 +385,13 @@ (for/list : (Listof (Vector Flonum Flonum Flonum)) ([p (in-vector pieces)]) (define wb (cast (quad-attr-ref p world:word-break-key #f) (U Quad False))) (vector - (cast (apply + (for/list : (Listof Flonum) ([qli (in-list (quad-list p))]) + ;; throw in 0.0 in case for/list returns empty + (apply + 0.0 (for/list : (Listof Flonum) ([qli (in-list (quad-list p))]) (define q (cast qli Quad)) (define str (quad->string q)) (if (equal? str "") (cast (quad-attr-ref q world:width-key 0.0) Flonum) - (apply measure-text (quad->string q) (font-attributes-with-defaults q))))) Flonum) + (apply measure-text (quad->string q) (font-attributes-with-defaults q))))) (if wb (cast (apply measure-text (cast (quad-attr-ref wb world:no-break-key) String) (font-attributes-with-defaults wb)) Flonum) 0.0) (if wb (cast (apply measure-text (cast (quad-attr-ref wb world:before-break-key) String) (font-attributes-with-defaults wb)) Flonum) 0.0)))) (values