naive bulleting

main
Matthew Butterick 5 years ago
parent 5d0ae09c3a
commit 82a7974238

@ -1,92 +1,7 @@
#lang qtest/markdown
# Hyphenate
A simple _hyphenation engine_ that uses the KnuthLiang hyphenation algorithm originally developed for TeX.
I **have added little** to their work. Accordingly, I take no credit, except a spoonful of *snako-bits.*
And now, for something __altogether__ the same. Yes! No?!ß
## 1. Installation
At the command line:
We said `raco pkg install hyphenate` dude
```
it's a
codeblock!
```
> A simple _hyphenation engine_ that uses the KnuthLiang hyphenation algorithm originally developed for TeX. A simple _hyphenation engine_ that uses the KnuthLiang hyphenation algorithm originally developed for TeX.
```
it's a
codeblock!
```
> A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text.
A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text. A [list of web colors](https://en.wikipedia.org/wiki/Web_colors).
Certain word processors allow users to [insert soft
hyphens](http://practicaltypography.com/optional-hyphens.html) in their
text.
Why don't we
1. list the ways
2. we can

@ -76,11 +76,18 @@
'(inset-left "12") '(inset-right "12") '(inset-top "12") '(inset-bottom "12")
attrs) new-exprs))
(define draw-debug? #t)
(define draw-debug-line? #t)
(define draw-debug-block? #f)
(define draw-debug-string? #f)
(define (list-base attrs exprs [bullet-val #f])
(qexpr (list* '(inset-left "20") attrs)
(add-between
(for/list ([(expr idx) (in-indexed exprs)])
(list* (get-tag expr) (cons (list 'list-index (or bullet-val (format "~a." (add1 idx)))) (get-attrs expr)) (get-elements expr)))
(list* (get-tag expr) (cons (list 'list-index (or bullet-val (format "~a" (add1 idx)))) (get-attrs expr)) (get-elements expr)))
pbr)))
(define-tag-function (ol attrs exprs) (list-base attrs exprs))
@ -109,7 +116,9 @@
#:bg (hash-ref (quad-attrs q) 'bg #f)
#:features (list (cons #"tnum" 1))
#:link (hash-ref (quad-attrs q) 'link #f))))
#:draw-end (λ (q doc) (draw-debug q doc "#99f" "#ccf"))))
#:draw-end (if draw-debug-string?
(λ (q doc) (draw-debug q doc "#99f" "#ccf"))
void)))
(define-runtime-path charter "fonts/charter.ttf")
(define-runtime-path charter-bold "fonts/charter-bold.ttf")
@ -156,7 +165,7 @@
[else (current-line-height doc)]))
(pt (string-width doc str) line-height))])]))
(define draw-debug? #t)
(define (draw-debug q doc [fill-color "#f99"] [stroke-color "#fcc"])
(when draw-debug?
(save doc)
@ -177,13 +186,13 @@
#:inner 'sw
#:out 'sw
#:printable #true
#:draw-start draw-debug))
#:draw-start (if draw-debug-line? draw-debug void)))
(struct line-spacer quad () #:transparent)
(define q:line-spacer (q #:type line-spacer
#:size (pt dumb-hardcoded-value (* line-height 0.6))
#:out 'sw
#:printable (λ (q sig) (not (memq sig '(start end))))
#:draw-start draw-debug))
#:draw-start (if draw-debug-line? draw-debug void)))
(define softies (map string '(#\space #\- #\u00AD)))
@ -232,7 +241,7 @@
dest-hash)
(define (line-wrap xs wrap-size)
(wrap xs (λ (q idx) (- wrap-size
(wrap #R xs (λ (q idx) (- wrap-size
(quad-ref q 'inset-left 0)
(quad-ref q 'inset-right 0)))
#:hard-break line-break?
@ -266,25 +275,32 @@
pcs))
(match-define (list w h) (quad-size q:line))
(pt w (if (empty? line-heights) h (apply max line-heights))))]
[elems elems]
[offset (pt
(quad-ref elem 'inset-left 0)
(second (quad-offset q:line)))]
[draw-end (match (and (or (para-break? q) (not q))
(quad-ref elem 'list-index))
[#false void]
[val (λ (q doc)
(save doc)
(match-define (list x y)
(quad-origin (car (quad-elems q))))
(text doc val x y)
(restore doc))])]))]
[elems (append
(match (and (or (para-break? q) (not q))
(quad-ref elem 'list-index))
[#false null]
[bullet (list (make-quad
#:in 'sw
#:out 'sw
#:size (pt 10 10)
#:draw-end (λ (q doc) (draw-debug q doc "red" "red"))
#:elems (list (struct-copy quad (car elems)
[elems (list (if (number? bullet)
(format "~a." bullet)
bullet))]))))])
(list (make-quad
#:in 'nw
#:out 'nw
#:size (pt 15 15)
#:draw-end (λ (q doc) (draw-debug q doc "blue" "blue"))
#:offset (pt (quad-ref elem 'inset-left 0) 0)
#:elems elems)))]))]
[_ null])])
(if (and (para-break? q) (not (hr-break? q)))
(list q:line-spacer)
null)))))
(define zoom-mode? #f)
(define zoom-mode? #t)
(define top-margin 60)
(define bottom-margin 120)
(define side-margin 120)
@ -314,10 +330,10 @@
#:offset (pt 0 (+ (quad-ref first-line 'inset-top 0)))
#:elems lines
#:size (delay (pt (pt-x (size first-line)) ;
(+ (for/sum ([line (in-list lines)])
(pt-y (size line)))
(quad-ref first-line 'inset-top 0)
(quad-ref first-line 'inset-bottom 0))))
(+ (for/sum ([line (in-list lines)])
(pt-y (size line)))
(quad-ref first-line 'inset-top 0)
(quad-ref first-line 'inset-bottom 0))))
#:draw-start (λ (q doc)
;; adjust drawing coordinates for border inset
(match-define (list bil bit bir bib)
@ -355,7 +371,9 @@
(quad-ref first-line 'border-color-bottom) bw-bottom)
(box-side left (+ bottom (half bw-bottom)) left (- top (half bw-top))
(quad-ref first-line 'border-color-left) bw-left))
#:draw-end (λ (q doc) (draw-debug q doc "#6c6" "#9c9"))))
#:draw-end (if draw-debug-block?
(λ (q doc) (draw-debug q doc "#6c6" "#9c9"))
void)))
(define (contiguous-group-by pred xs)

@ -5,6 +5,7 @@
racket/list
racket/struct
txexpr
sugar/list
racket/function
"quad.rkt"
"param.rkt")
@ -49,7 +50,8 @@
(define (atomize qx)
;; atomize a quad by reducing it to the smallest indivisible formatting units.
;; which are multi-character quads with the same formatting.
(let loop ([x (make-quad qx)]
(define atomized-qs
(let loop ([x (make-quad qx)]
[attrs (hash-copy (current-default-attrs))]
[key (eq-hash-code (current-default-attrs))])
(match-define-values (next-key next-attrs)
@ -78,6 +80,8 @@
(list (apply x-maker next-attrs (list elem) x-tail)))
(loop elem next-attrs next-key))))]
[_ (list x)])))
#;(trimf atomized-qs (λ (q) (equal? (quad-elems q) '(" "))))
atomized-qs)
(module+ test
(define (filter-private-keys qs)

@ -83,6 +83,7 @@
(for ([kv (in-list attrs)])
(match-define (list k v) kv)
;; coerce number strings to actual numbers
;; this misbehaves on a list index like "1." which becomes 1.0
(hash-set! mheq k (or (string->number v) v)))
(q #:attrs mheq #:elems (map loop elems))]
[(list (? qexpr? elems) ...)

Loading…
Cancel
Save