added pdf-bytes+bounds to the docs for file/convertible and then used it

to make scribble render inline picts with a nearly good looking baseline
This commit is contained in:
Robby Findler 2011-03-14 09:48:20 -05:00
parent bd3a43db98
commit 615bc86668
3 changed files with 36 additions and 10 deletions

View File

@ -1,6 +1,6 @@
#lang scribble/doc #lang scribble/doc
@(require scribble/manual @(require scribble/manual
(for-label file/convertible)) (for-label file/convertible racket/base racket/contract))
@title[#:tag "convertible"]{Convertible: Data-Conversion Protocol} @title[#:tag "convertible"]{Convertible: Data-Conversion Protocol}
@ -25,6 +25,9 @@ should be considered standard:
@item{@scheme['ps-bytes] --- a byte string containing a PostScript document} @item{@scheme['ps-bytes] --- a byte string containing a PostScript document}
@item{@scheme['eps-bytes] --- a byte string containing an Encapsulated PostScript document} @item{@scheme['eps-bytes] --- a byte string containing an Encapsulated PostScript document}
@item{@scheme['pdf-bytes] --- a byte string containing a PDF document} @item{@scheme['pdf-bytes] --- a byte string containing a PDF document}
@item{@scheme['pdf-bytes+bounds] --- a list containing a byte string and four numbers;
the byte string contains a PDF document and the four numbers are sizing information for the PDF document,
namely the width, height, ascent and descent in that order}
] ]
@defthing[prop:convertible struct-type-property?]{ @defthing[prop:convertible struct-type-property?]{
@ -43,8 +46,17 @@ Returns @racket[#t] if @racket[v] supports the conversion protocol,
@racket[#f] otherwise.} @racket[#f] otherwise.}
@defproc[(convert [v convertible?] [request symbol?] [default any/c #f]) @defproc[(convert [v convertible?] [request symbol?] [default any/c #f])
any]{ (case request
[(text) (or/c string? (λ (x) (eq? x default)))]
[(gif-bytes png-bytes ps-bytes eps-bytes pdf-bytes)
(or/c bytes? (λ (x) (eq? x default)))]
[(pdf-bytes+bounds) (or/c (list/c bytes?
(and/c real? (not/c negative?))
(and/c real? (not/c negative?))
(and/c real? (not/c negative?))
(and/c real? (not/c negative?)))
(λ (x) (eq? x default)))]
[else any/c])]{
Requests a data conversion from @racket[v], where @racket[request] Requests a data conversion from @racket[v], where @racket[request]
indicates the type of requested data and @racket[default] is the value indicates the type of requested data and @racket[default] is the value

View File

@ -250,13 +250,18 @@
[(and (convertible? e) [(and (convertible? e)
(not (disable-images)) (not (disable-images))
(let ([ftag (lambda (v suffix) (and v (list v suffix)))]) (let ([ftag (lambda (v suffix) (and v (list v suffix)))])
(or (ftag (convert e 'pdf-bytes) ".pdf") (or (ftag (convert e 'pdf-bytes+bounds) ".pdf")
(ftag (convert e 'eps-bytes) ".ps") (ftag (list (convert e 'pdf-bytes) #f #f #f #f) ".pdf")
(ftag (convert e 'png-bytes) ".png")))) (ftag (list (convert e 'eps-bytes) #f #f #f #f) ".ps")
=> (lambda (bstr+suffix) (ftag (list (convert e 'png-bytes) #f #f #f #f) ".png"))))
(let ([fn (install-file (format "pict~a" (cadr bstr+suffix)) => (lambda (bstr+info+suffix)
(car bstr+suffix))]) (let* ([bstr (list-ref (list-ref bstr+info+suffix 0) 0)]
(printf "\\includegraphics{~a}" fn)))] [suffix (list-ref bstr+info+suffix 1)]
[descent (list-ref (list-ref bstr+info+suffix 0) 3)]
[fn (install-file (format "pict~a" suffix) bstr)])
(if descent
(printf "\\raisebox{-~apx}{\\includegraphics{~a}}" descent fn)
(printf "\\includegraphics{~a}" fn))))]
[else [else
(parameterize ([rendering-tt (or tt? (rendering-tt))]) (parameterize ([rendering-tt (or tt? (rendering-tt))])
(super render-content e part ri))]))] (super render-content e part ri))]))]

View File

@ -447,6 +447,15 @@
(define (convert-pict p format default) (define (convert-pict p format default)
(if (eq? format 'pdf-bytes+bounds)
(list (convert-pict/bytes p 'pdf-bytes default)
(pict-width p)
(pict-height p)
(pict-descent p)
0)
(convert-pict/bytes p format default)))
(define (convert-pict/bytes p format default)
(case format (case format
[(png-bytes) [(png-bytes)
(let* ([bm (make-bitmap (max 1 (inexact->exact (ceiling (pict-width p)))) (let* ([bm (make-bitmap (max 1 (inexact->exact (ceiling (pict-width p))))