From 3e75e07ea212b3d029ebf98abea104b950346d62 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 1 Jul 2016 17:33:53 -0700 Subject: [PATCH] improvements --- quad/quad/quadlang-test.rkt | 6 ++++-- quad/quad/render-pdf.rkt | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/quad/quad/quadlang-test.rkt b/quad/quad/quadlang-test.rkt index 4cd5b7b2..fa14d7cb 100644 --- a/quad/quad/quadlang-test.rkt +++ b/quad/quad/quadlang-test.rkt @@ -1,2 +1,4 @@ -#lang quad/text test 240 -Not that you need to be a programmer to start using Pollen. On the contrary, the Pollen language is markup-based, so you can write & edit text naturally. But when you want to automate repetitive tasks, add cross-references, or pull in data from other sources, you can access a full programming language from within the text. \ No newline at end of file +#lang quad/text pdf 360 300 +@quad[(make-attrs #:font "Charter.ttf")]{Not that you need to be a programmer to start using Pollen. On the contrary, the Pollen language is markup-based, so you can write & edit text naturally. But when you want to automate repetitive tasks, add cross-references, or pull in data from other sources, you can access a full programming language from within the text. + +Not that you need to be a programmer to start using Pollen. On the contrary, the Pollen language is markup-based, so you can write & edit text naturally. But when you want to automate repetitive tasks, add cross-references, or pull in data from other sources, you can access a full programming language from within the text.} \ No newline at end of file diff --git a/quad/quad/render-pdf.rkt b/quad/quad/render-pdf.rkt index ab28b531..77198c5c 100644 --- a/quad/quad/render-pdf.rkt +++ b/quad/quad/render-pdf.rkt @@ -1,5 +1,5 @@ #lang quad/dev -(require racket/class racket/contract sugar/debug sugar/cache racket/list racket/file racket/draw data/gvector) +(require racket/class racket/contract racket/string sugar/debug sugar/cache racket/list racket/file racket/draw data/gvector) (provide (all-defined-out)) (define (world:paper-width-default) 612) @@ -28,25 +28,34 @@ (send dc end-page)) (define (print-status) - (send dc draw-text (format "foobar ~a" (current-milliseconds)) 0 0)) + (send dc draw-text (format "quad pdf test @ ~a" (current-milliseconds)) 0 0)) - (define f (make-font #:face "Source Code Pro" #:size 10)) - (send dc set-font f) + (send dc set-font (make-font #:face "Source Code Pro" #:size 10)) (send dc start-page) - (print-status) + (print-status) + + (define default-x 40) + (define default-y 40) (when qs (for/fold ([page-pos 0] - [x-pos 40] - [y-pos 40]) + [x-pos default-x] + [y-pos default-y]) ([q (in-vector qs)]) + (let ([font-attr (hash-ref (quad-attrs q) 'font #f)]) + (when font-attr + (send dc set-font (make-font #:face (string-trim font-attr ".ttf") #:size 10)))) (cond [(eq? (quad-dim q) 'page-break) (send dc end-page) (send dc start-page) (print-status) - (values page-pos 40 40)] + (values page-pos default-x default-y)] + [(eq? (quad-dim q) 'line-break) + (values page-pos default-x (+ y-pos 12))] + [(eq? (quad-dim q) 'column-break) + (values page-pos x-pos y-pos)] ; ignore for now [(quad-printable? q) (send dc draw-text (format "~a" (quad-val q)) x-pos y-pos) (values page-pos (+ x-pos (quad-dim q)) y-pos)]