handle imperative breaks; add debug rendering
parent
f89808fc40
commit
cf3cc42dd0
@ -0,0 +1,28 @@
|
||||
#lang quad/text #:text
|
||||
Produces a list of three-element lists, where each three-element list represents a set of consecutive code points for-which the Unicode standard specifies character properties. Each three-element list contains two integers and a boolean; the first integer is a starting code-point value (inclusive), the second integer is an ending code-point value (inclusive), and the boolean is #t when all characters in the code-point range have identical results for all of the character predicates above. The three-element lists are ordered in the overall result list such that later lists represent larger code-point values, and all three-element lists are separated from every other by at least one code-point value that is not specified by Unicode.
|
||||
|
||||
One morning, when Gregor Samsa woke from troubled dreams, he found
|
||||
himself transformed in his bed into a horrible vermin. He lay on
|
||||
his armour-like back, and if he lifted his head a little he could
|
||||
see his brown belly, slightly domed and divided by arches into stiff
|
||||
sections. The bedding was hardly able to cover it and seemed ready
|
||||
to slide off any moment. His many legs, pitifully thin compared
|
||||
with the size of the rest of him, waved about helplessly as he
|
||||
looked.
|
||||
|
||||
"What's happened to me?" he thought. It wasn't a dream. His room,
|
||||
a proper human room although a little too small, lay peacefully
|
||||
between its four familiar walls. A collection of textile samples
|
||||
lay spread out on the table - Samsa was a travelling salesman - and
|
||||
above it there hung a picture that he had recently cut out of an
|
||||
illustrated magazine and housed in a nice, gilded frame. It showed
|
||||
a lady fitted out with a fur hat and fur boa who sat upright,
|
||||
raising a heavy fur muff that covered the whole of her lower arm
|
||||
towards the viewer.
|
||||
|
||||
Gregor then turned to look out the window at the dull weather.
|
||||
Drops of rain could be heard hitting the pane, which made him feel
|
||||
quite sad. "How about if I sleep a little bit longer and forget all
|
||||
this nonsense", he thought, but that was something he was unable to
|
||||
do because he was used to sleeping on his right, and in his present
|
||||
state couldn't get into that position. However hard he threw
|
@ -1,15 +1,16 @@
|
||||
#lang racket/base
|
||||
(require "quads.rkt" "typeset.rkt" "atomize.rkt" racket/list racket/string)
|
||||
(require "quads.rkt" "typeset.rkt" "atomize.rkt" "render.rkt" racket/list racket/string)
|
||||
(provide (except-out (all-from-out racket/base "quads.rkt") #%module-begin)
|
||||
(rename-out [~module-begin #%module-begin]))
|
||||
|
||||
(define-syntax-rule (~module-begin lang-line-config-arg . args)
|
||||
(#%module-begin
|
||||
(define main-quad (quad #f . args))
|
||||
(define main-quad (apply quad #f (add-between (list . args) "\n"))) ; at-reader splits lines, but we want one contiguous run
|
||||
;; branch on config-arg to allow debug / inspection options on #lang line
|
||||
(case (string-trim lang-line-config-arg)
|
||||
[("#:atoms") (atomize main-quad)]
|
||||
[else (typeset (atomize main-quad))])))
|
||||
[("#:text") (time (debug-render (typeset-fit (atomize main-quad))))]
|
||||
[else (typeset-fit (atomize main-quad))])))
|
||||
|
||||
(module reader syntax/module-reader
|
||||
"main.rkt")
|
@ -1,30 +0,0 @@
|
||||
#lang quad/dev
|
||||
(require "freetype-ffi.rkt")
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define measure-char
|
||||
(let ([measure-cache (make-hash)]
|
||||
[glyph-idx-cache (make-hash)]
|
||||
[glyph-width-cache (make-hash)]
|
||||
[em-size-cache (make-hash)]
|
||||
[ft-library (FT_Init_FreeType)]
|
||||
[ft-face-cache (make-hash)])
|
||||
(λ (font-pathstring char)
|
||||
(define (do-measure)
|
||||
(define ft-face (hash-ref! ft-face-cache font-pathstring (λ () (FT_New_Face ft-library font-pathstring 0))))
|
||||
(define width
|
||||
(let ([glyph-idx (hash-ref! glyph-idx-cache (cons char font-pathstring)
|
||||
(λ () (FT_Get_Char_Index ft-face (char->integer char))))])
|
||||
(hash-ref! glyph-width-cache (cons glyph-idx font-pathstring)
|
||||
(λ ()
|
||||
(FT_Load_Glyph ft-face glyph-idx FT_LOAD_NO_RECURSE) ; loads into FTFace's 'glyph' slot
|
||||
(define width (FT_Vector-x (FT_GlyphSlotRec-advance (FT_FaceRec-glyph ft-face))))
|
||||
(* width 1.0))))) ; store as inexact
|
||||
(define em-size
|
||||
(hash-ref! em-size-cache font-pathstring (λ () (FT_FaceRec-units_per_EM ft-face))))
|
||||
(/ width em-size))
|
||||
(hash-ref! measure-cache (cons font-pathstring char) do-measure))))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-equal? (measure-char "charter.ttf" #\f) .321))
|
@ -0,0 +1,30 @@
|
||||
#lang quad/dev
|
||||
(require racket/format)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define (debug-render qs)
|
||||
(define line-counter #f)
|
||||
(define (line-counter-increment!) (set! line-counter (add1 line-counter)))
|
||||
(define (line-counter-reset!) (set! line-counter 1))
|
||||
(line-counter-reset!)
|
||||
(printf " ")
|
||||
(for ([i (in-range 1 71)])
|
||||
(printf (cond
|
||||
[(zero? (modulo i 10)) "|"]
|
||||
[(zero? (modulo i 5)) "'"]
|
||||
[else "·"])))
|
||||
(define (print-line-counter)
|
||||
(printf "\n~a "(~r line-counter #:min-width 2 #:pad-string " " #:base 10)))
|
||||
(print-line-counter)
|
||||
(for ([q (in-vector qs)])
|
||||
(define qd (quad-dim q))
|
||||
(cond
|
||||
[(symbol? qd)
|
||||
(case qd
|
||||
[(line-break) (line-counter-increment!)]
|
||||
[(column-break) (line-counter-reset!) (printf "\n--col--")]
|
||||
[(page-break) (printf "\n\n==page==\n")])
|
||||
(print-line-counter)]
|
||||
[(or ($black? q) ($soft? q)) (printf "~a" (quad-val q))]
|
||||
[else (void)]))
|
||||
(printf "\n\n"))
|
Loading…
Reference in New Issue