diff --git a/collects/file/scribblings/convertible.scrbl b/collects/file/scribblings/convertible.scrbl index 40b9bbf39f..3170bc3184 100644 --- a/collects/file/scribblings/convertible.scrbl +++ b/collects/file/scribblings/convertible.scrbl @@ -1,6 +1,6 @@ #lang scribble/doc @(require scribble/manual - (for-label file/convertible)) + (for-label file/convertible racket/base racket/contract)) @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['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+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?]{ @@ -43,8 +46,17 @@ Returns @racket[#t] if @racket[v] supports the conversion protocol, @racket[#f] otherwise.} @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] indicates the type of requested data and @racket[default] is the value diff --git a/collects/scribble/latex-render.rkt b/collects/scribble/latex-render.rkt index 8d18c1cf6f..3cb9a13f44 100644 --- a/collects/scribble/latex-render.rkt +++ b/collects/scribble/latex-render.rkt @@ -250,13 +250,18 @@ [(and (convertible? e) (not (disable-images)) (let ([ftag (lambda (v suffix) (and v (list v suffix)))]) - (or (ftag (convert e 'pdf-bytes) ".pdf") - (ftag (convert e 'eps-bytes) ".ps") - (ftag (convert e 'png-bytes) ".png")))) - => (lambda (bstr+suffix) - (let ([fn (install-file (format "pict~a" (cadr bstr+suffix)) - (car bstr+suffix))]) - (printf "\\includegraphics{~a}" fn)))] + (or (ftag (convert e 'pdf-bytes+bounds) ".pdf") + (ftag (list (convert e 'pdf-bytes) #f #f #f #f) ".pdf") + (ftag (list (convert e 'eps-bytes) #f #f #f #f) ".ps") + (ftag (list (convert e 'png-bytes) #f #f #f #f) ".png")))) + => (lambda (bstr+info+suffix) + (let* ([bstr (list-ref (list-ref bstr+info+suffix 0) 0)] + [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 (parameterize ([rendering-tt (or tt? (rendering-tt))]) (super render-content e part ri))]))] diff --git a/collects/texpict/private/mrpict-extra.rkt b/collects/texpict/private/mrpict-extra.rkt index 6da0d3d8d4..b9aaed66aa 100644 --- a/collects/texpict/private/mrpict-extra.rkt +++ b/collects/texpict/private/mrpict-extra.rkt @@ -447,6 +447,15 @@ (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 [(png-bytes) (let* ([bm (make-bitmap (max 1 (inexact->exact (ceiling (pict-width p))))