Skip to content
86 changes: 44 additions & 42 deletions scribble-doc/scribblings/scribble/class-diagrams.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,19 @@
(blank 0 (+ class-box-margin class-box-margin)))
(cond
[(and methods fields)
(let* ([top-spacer (mk-blank)]
[bottom-spacer (mk-blank)]
[main (vl-append name
top-spacer
(if (null? fields)
(blank 0 4)
(apply vl-append fields))
bottom-spacer
(if (null? methods)
(blank 0 4)
(apply vl-append methods)))])
(add-hline (add-hline (frame (inset main class-box-margin)) top-spacer) bottom-spacer))]
(define top-spacer (mk-blank))
(define bottom-spacer (mk-blank))
(define main
(vl-append name
top-spacer
(if (null? fields)
(blank 0 4)
(apply vl-append fields))
bottom-spacer
(if (null? methods)
(blank 0 4)
(apply vl-append methods))))
(add-hline (add-hline (frame (inset main class-box-margin)) top-spacer) bottom-spacer)]
[fields
(define top-spacer (mk-blank))
(define main
Expand Down Expand Up @@ -350,36 +351,37 @@
[count 1]
#:connect-dots [connect-dots connect-dots]
#:dot-delta [dot-delta 0])
(let ([going-down? (let-values ([(_1 start-y) (find-cc main0 start-field)]
[(_2 finish-y) (find-cc main0 finish-name)])
(< start-y finish-y))])
(define-values (main1 dot1)
(add-dot-delta (λ () (add-dot-left main0 start-class start-field))
0
(if going-down?
dot-delta
(- dot-delta))))
(define-values (main2 dot2)
(add-dot-delta (λ () (add-dot-left/space main1 start-class start-field count))
(- dot-delta)
(if going-down?
dot-delta
(- dot-delta))))
(define-values (main3 dot3)
(add-dot-delta (λ () (add-dot-left main2 finish-class finish-name))
0
(if going-down?
(- dot-delta)
dot-delta)))
(define-values (main4 dot4) (add-dot-delta (λ () (add-dot-junction main3 dot2 dot3)) 0 0))
(define-values (main5 dot5) (add-dot-left main4 finish-class finish-name))
(define-values (main6 dot6)
(add-dot-delta
(λ () (add-dot-left main5 finish-class finish-name))
-1 ;; just enough to get the arrowhead going the right direction; not enough to see the line
0))

(connect-dots #t (connect-dots #f main6 dot1 dot2 dot4 dot3) dot6 dot5)))
(define going-down?
(let-values ([(_1 start-y) (find-cc main0 start-field)]
[(_2 finish-y) (find-cc main0 finish-name)])
(< start-y finish-y)))
(define-values (main1 dot1)
(add-dot-delta (λ () (add-dot-left main0 start-class start-field))
0
(if going-down?
dot-delta
(- dot-delta))))
(define-values (main2 dot2)
(add-dot-delta (λ () (add-dot-left/space main1 start-class start-field count))
(- dot-delta)
(if going-down?
dot-delta
(- dot-delta))))
(define-values (main3 dot3)
(add-dot-delta (λ () (add-dot-left main2 finish-class finish-name))
0
(if going-down?
(- dot-delta)
dot-delta)))
(define-values (main4 dot4) (add-dot-delta (λ () (add-dot-junction main3 dot2 dot3)) 0 0))
(define-values (main5 dot5) (add-dot-left main4 finish-class finish-name))
(define-values (main6 dot6)
(add-dot-delta
(λ () (add-dot-left main5 finish-class finish-name))
-1 ;; just enough to get the arrowhead going the right direction; not enough to see the line
0))

(connect-dots #t (connect-dots #f main6 dot1 dot2 dot4 dot3) dot6 dot5))

(define (left-top-reference main0
start-class
Expand Down
71 changes: 31 additions & 40 deletions scribble-doc/scribblings/scribble/struct-hierarchy.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,15 @@
(inset (panorama w/delayed-connections) 0 0 1 0))

(define (double f p0 a b c d [count 1])
(let ([arrows1 (launder (f (ghost p0) a b c d count #:dot-delta 1))]
[arrows2 (launder (f (ghost p0) a b c d count #:dot-delta -1))])
(cc-superimpose p0
arrows1
arrows2)))
(define arrows1 (launder (f (ghost p0) a b c d count #:dot-delta 1)))
(define arrows2 (launder (f (ghost p0) a b c d count #:dot-delta -1)))
(cc-superimpose p0 arrows1 arrows2))

(define (triple f p0 a b c d [count 1])
(let ([arrows (launder (f (ghost p0) a b c d count))]
[up-arrows (launder (f (ghost p0) a b c d count #:dot-delta 2))]
[down-arrows (launder (f (ghost p0) a b c d count #:dot-delta -2))])
(cc-superimpose p0
arrows
up-arrows
down-arrows)))
(define arrows (launder (f (ghost p0) a b c d count)))
(define up-arrows (launder (f (ghost p0) a b c d count #:dot-delta 2)))
(define down-arrows (launder (f (ghost p0) a b c d count #:dot-delta -2)))
(cc-superimpose p0 arrows up-arrows down-arrows))

(define (connect-circly-dots show-arrowhead? main dot1 . dots)
(let loop ([prev-dot dot1]
Expand All @@ -343,38 +338,34 @@

;; this is a hack -- it will only work with right-right-reference
(define (connect-two-circly-dots pict dot1 dot2 arrowhead?)
(let ([base
(let*-values ([(sx sy) (cc-find pict dot1)]
[(raw-ex ey) (cc-find pict dot2)]
[(ex) (if arrowhead?
(+ raw-ex 2)
raw-ex)])
(cc-superimpose
(dc
(λ (dc dx dy)
(let ([pen (send dc get-pen)])
(send dc set-pen
type-link-color ;(send pen get-color)
(if (is-a? dc post-script-dc%)
4
2)
'dot)
(send dc draw-line
(+ dx sx) (+ dy sy)
(+ dx ex) (+ dy ey))
(send dc set-pen pen)))
(pict-width pict)
(pict-height pict))
pict))])
(define base
(let*-values ([(sx sy) (cc-find pict dot1)]
[(raw-ex ey) (cc-find pict dot2)]
[(ex) (if arrowhead?
(+ raw-ex 2)
raw-ex)])
(cc-superimpose (dc (λ (dc dx dy)
(let ([pen (send dc get-pen)])
(send dc set-pen
type-link-color ;(send pen get-color)
(if (is-a? dc post-script-dc%) 4 2)
'dot)
(send dc draw-line (+ dx sx) (+ dy sy) (+ dx ex) (+ dy ey))
(send dc set-pen pen)))
(pict-width pict)
(pict-height pict))
pict)))
(if arrowhead?
(pin-arrow-line field-arrowhead-size
base
dot1 (λ (ignored1 ignored2)
(let-values ([(x y) (cc-find pict dot2)])
(values (+ x 2) y)))
dot2 cc-find
dot1
(λ (ignored1 ignored2)
(let-values ([(x y) (cc-find pict dot2)])
(values (+ x 2) y)))
dot2
cc-find
#:color type-link-color)
base)))
base))

(define (dotted-right-right-reference p0 a b c d [count 1])
(right-right-reference p0 a b c d count #:connect-dots connect-circly-dots))
Expand Down
19 changes: 9 additions & 10 deletions scribble-doc/scribblings/scribble/utils.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,15 @@
(cdr (apply append (map (lambda (x) (list #f x)) r)))
r)])
(make-table plain
(map (lambda (x)
(let ([@expr (if x
(litchar/lines (car x))
"")]
[sexpr (if x
(racket:to-paragraph ((norm-spacing 0) (cadr x)))
"")]
[reads-as (if x reads-as "")])
(map as-flow (list spacer @expr reads-as sexpr))))
r)))]))))
(for/list ([x (in-list r)])
(let ([@expr (if x
(litchar/lines (car x))
"")]
[sexpr (if x
(racket:to-paragraph ((norm-spacing 0) (cadr x)))
"")]
[reads-as (if x reads-as "")])
(map as-flow (list spacer @expr reads-as sexpr))))))]))))

;; stuff for the scribble/text examples

Expand Down
30 changes: 14 additions & 16 deletions scribble-lib/scribble/blueboxes.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
(port-count-lines! port)
(file-position port (+ (car offset+len) (or offset 0)))
(for/list ([i (in-range (cdr offset+len))])
(read-line port)))))))
(read-line port 'any)))))))
(cond
[(not (andmap string? lines)) #f]
[(null? lines) #f]
Expand All @@ -87,7 +87,7 @@
(define (fetch-blueboxes-method-tags sym #:blueboxes-cache [cache (make-blueboxes-cache #f)])
(populate-cache! cache)
(define ht (blueboxes-cache-method->tags cache))
(or (and ht (hash-ref ht sym (λ () '()))) '()))
(or (and ht (hash-ref ht sym '())) '()))

(define (populate-cache! cache)
(define cache-content (blueboxes-cache-info-or-paths cache))
Expand All @@ -100,13 +100,12 @@
(define (compute-methods-table lst)
(define meth-ht (make-hash))
(for ([a-bluebox-info (in-list lst)])
(match a-bluebox-info
[(bluebox-info blueboxes.rktd offset tag-ht mod-time)
(when tag-ht
(for ([(tag val) (in-hash tag-ht)])
(when (method-tag? tag)
(define-values (class/intf meth) (get-class/interface-and-method tag))
(hash-set! meth-ht meth (cons tag (hash-ref meth-ht meth (λ () '())))))))]))
(match-define (bluebox-info blueboxes.rktd offset tag-ht mod-time) a-bluebox-info)
(when tag-ht
(for ([(tag val) (in-hash tag-ht)])
(when (method-tag? tag)
(define-values (class/intf meth) (get-class/interface-and-method tag))
(hash-set! meth-ht meth (cons tag (hash-ref meth-ht meth (λ () '()))))))))
meth-ht)

(define (build-blueboxes-cache blueboxes-dirs)
Expand All @@ -119,12 +118,11 @@
a-bluebox-info)))

(define (check-and-update-bluebox-info! a-bluebox-info)
(match a-bluebox-info
[(bluebox-info blueboxes.rktd offset tag-ht mod-time)
(when (or (not mod-time)
(and (file-exists? blueboxes.rktd)
(not (mod-time . = . (file-or-directory-modify-seconds blueboxes.rktd)))))
(populate-bluebox-info! a-bluebox-info))]))
(match-define (bluebox-info blueboxes.rktd offset tag-ht mod-time) a-bluebox-info)
(when (or (not mod-time)
(and (file-exists? blueboxes.rktd)
(not (mod-time . = . (file-or-directory-modify-seconds blueboxes.rktd)))))
(populate-bluebox-info! a-bluebox-info)))

(define (populate-bluebox-info! a-bluebox-info)
(define blueboxes.rktd (bluebox-info-blueboxes.rktd a-bluebox-info))
Expand All @@ -133,7 +131,7 @@
(call-with-input-file blueboxes.rktd
(λ (port)
(port-count-lines! port)
(define first-line (read-line port))
(define first-line (read-line port 'any))
(define pos (file-position port))
(define desed
(with-handlers ([exn:fail? (λ (x)
Expand Down
19 changes: 9 additions & 10 deletions scribble-lib/scribble/lp/lang/common.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,15 @@
(strip-comments (cdr body))]
[(eq? ad 'code:blank)
(strip-comments (cdr body))]
[(and (or (eq? ad 'code:hilite)
(eq? ad 'code:quote))
(let* ([d (cdr body)]
[dd (if (syntax? d)
(syntax-e d)
d)])
(and (pair? dd)
(or (null? (cdr dd))
(and (syntax? (cdr dd))
(null? (syntax-e (cdr dd))))))))
[(cond
[(or (eq? ad 'code:hilite) (eq? ad 'code:quote))
(define d (cdr body))
(define dd
(if (syntax? d)
(syntax-e d)
d))
(and (pair? dd) (or (null? (cdr dd)) (and (syntax? (cdr dd)) (null? (syntax-e (cdr dd))))))]
[else #f])
(define d (cdr body))
(define r
(strip-comments (car (if (syntax? d) (syntax-e d) d))))
Expand Down
67 changes: 35 additions & 32 deletions scribble-lib/scribble/text-render.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@
(define/override (render-part d ht)
(let ([number (collected-info-number (part-collected-info d ht))])
(unless (part-style? d 'hidden)
(let ([s (format-number number '() #t)])
(unless (null? s)
(printf "~a~a"
(car s)
(if (part-title-content d)
" "
"")))
(when (part-title-content d)
(render-content (part-title-content d) d ht))
(when (or (pair? number) (part-title-content d))
(newline)
(newline))))
(define s (format-number number '() #t))
(unless (null? s)
(printf "~a~a" (car s) (if (part-title-content d) " " "")))
(when (part-title-content d)
(render-content (part-title-content d) d ht))
(when (or (pair? number) (part-title-content d))
(newline)
(newline)))
(render-flow (part-blocks d) d ht #f)
(let loop ([pos 1]
[secs (part-parts d)]
Expand Down Expand Up @@ -78,26 +74,33 @@
null
(let* ([strs (map (lambda (flows styles)
(map (lambda (d style)
(if (eq? d 'cont)
d
(let ([o (open-output-string)])
(define padding
(or (findf cell-padding-property? (style-properties style))
(cell-padding-property 0 0 0 0)))
(define (int n) (inexact->exact (floor n)))
(parameterize ([current-indent 0]
[current-output-port o])
(render-block d part ht #f))
(define strs (regexp-split
#rx"\n"
(regexp-replace #rx"\n$" (get-output-string o) "")))
(append
(make-list (int (cell-padding-property-top padding)) "")
(for/list ([str (in-list strs)])
(string-append (make-string (int (cell-padding-property-left padding)) #\space)
str
(make-string (int (cell-padding-property-right padding)) #\space)))
(make-list (int (cell-padding-property-bottom padding)) "")))))
(cond
[(eq? d 'cont) d]
[else
(define o (open-output-string))
(define padding
(or (findf cell-padding-property? (style-properties style))
(cell-padding-property 0 0 0 0)))
(define (int n)
(inexact->exact (floor n)))
(parameterize ([current-indent 0]
[current-output-port o])
(render-block d part ht #f))
(define strs
(regexp-split
#rx"\n"
(regexp-replace #rx"\n$" (get-output-string o) "")))
(append
(make-list (int (cell-padding-property-top padding)) "")
(for/list ([str (in-list strs)])
(string-append
(make-string (int (cell-padding-property-left padding))
#\space)
str
(make-string (int (cell-padding-property-right padding))
#\space)))
(make-list (int (cell-padding-property-bottom padding))
""))]))
flows
styles))
flowss
Expand Down
Loading