move and rename pict `convert' support
Renamed `convert' to `pict-convert', etc., to avoid confusion with `file/convert' bindings. Moved out of `slideshow/pict' to `slideshow/pict-convert', because most `slideshow/pict' clients do not need it.
This commit is contained in:
parent
1a9ab0b018
commit
351e82735b
|
@ -373,7 +373,7 @@
|
|||
(define convert-table (make-hasheq))
|
||||
(define pict:convertible?
|
||||
(with-handlers ((exn:fail? (λ (exn) (λ (val) #f))))
|
||||
(dynamic-require 'texpict/mrpict 'convertible?)))
|
||||
(dynamic-require 'slideshow/pict-convert 'pict-convertible?)))
|
||||
(parameterize ([pretty-print-pre-print-hook (λ (val port) (void))]
|
||||
[pretty-print-post-print-hook (λ (val port) (void))]
|
||||
[pretty-print-exact-as-decimal #f]
|
||||
|
@ -469,8 +469,9 @@
|
|||
(define (mk-pict-snip convertible)
|
||||
(define-syntax-rule
|
||||
(dyn name args ...)
|
||||
((dynamic-require 'texpict/mrpict 'name) args ...))
|
||||
(define pict (dyn convert convertible))
|
||||
((dynamic-require 'slideshow/pict 'name) args ...))
|
||||
(define pict ((dynamic-require 'slideshow/pict-convert 'pict-convert)
|
||||
convertible))
|
||||
(define w (dyn pict-width pict))
|
||||
(define h (dyn pict-height pict))
|
||||
(define a (dyn pict-ascent pict))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#lang scribble/doc
|
||||
@(require "ss.rkt" "pict-diagram.rkt"
|
||||
(for-label racket/gui slideshow/code slideshow/flash slideshow/face
|
||||
slideshow/balloon))
|
||||
slideshow/balloon slideshow/pict-convert))
|
||||
|
||||
@title[#:style 'toc]{Making Pictures}
|
||||
|
||||
|
@ -21,7 +21,8 @@ PostScript for inclusion into a larger document. The
|
|||
|
||||
@section{Pict Datatype}
|
||||
|
||||
A picture is a @racket[pict] structure. Some functions, such as
|
||||
A @deftech{pict} is a @racket[pict] structure representing an image.
|
||||
Some functions, such as
|
||||
@racket[hline], create new simple picts. Other functions, such as
|
||||
@racket[ht-append], build new picts out of existing picts. In the
|
||||
latter case, the embedded picts retain their identity, so that
|
||||
|
@ -1130,23 +1131,26 @@ A parameter used to refine text measurements to better match an
|
|||
expected scaling of the image. The @racket[scale/improve-new-text]
|
||||
form sets this parameter while also scaling the resulting pict.}
|
||||
|
||||
@section{Convertion to @racket[pict?]s}
|
||||
@;----------------------------------------
|
||||
|
||||
This section describes a protocol for values to be
|
||||
able to convert themselves to @racket[pict?]s. The
|
||||
protocol is used by DrRacket's REPL to render values
|
||||
that it prints out.
|
||||
@section{Conversion to Picts}
|
||||
|
||||
@defthing[prop:convertible struct-type-property?]{
|
||||
@defmodule[slideshow/pict-convert]{The
|
||||
@racketmodname[slideshow/pict-convert] library defines a protocol for
|
||||
values to convert themselves to @tech{picts}. The protocol
|
||||
is used by DrRacket's interactions window, for example, to render
|
||||
values that it prints}
|
||||
|
||||
@defthing[prop:pict-convertible struct-type-property?]{
|
||||
|
||||
A property whose value should be a procedure matching the
|
||||
contract @racket[(-> any/c pict?)]. The
|
||||
procedure is called when a structure with the property is passed to
|
||||
@racket[convert]; the argument to the procedure is the
|
||||
@racket[pict-convert]; the argument to the procedure is the
|
||||
structure, and the procedure's result should be a pict.
|
||||
}
|
||||
|
||||
@defthing[prop:convertible? struct-type-property?]{
|
||||
@defthing[prop:pict-convertible? struct-type-property?]{
|
||||
A property whose value should be a predicate procedure
|
||||
(i.e., matching the contract @racket[predicate/c]).
|
||||
|
||||
|
@ -1154,18 +1158,18 @@ If this property is not set, then it is assumed to be
|
|||
the function @racket[(λ (x) #t)].
|
||||
|
||||
If this property is set, then this procedure is called
|
||||
by @racket[convertible?] to determine if this particular
|
||||
by @racket[pict-convertible?] to determine if this particular
|
||||
value is convertible (thereby supporting situations
|
||||
where some instances of a given struct are convertible
|
||||
to picts, but others are not).
|
||||
}
|
||||
|
||||
@defproc[(convertible? [v any/c]) boolean?]{
|
||||
@defproc[(pict-convertible? [v any/c]) boolean?]{
|
||||
Returns @racket[#t] if @racket[v] supports the conversion protocol
|
||||
(by being a struct with the @racket[prop:convertible] property)
|
||||
(by being a struct with the @racket[prop:pict-convertible] property)
|
||||
and @racket[#f] otherwise.
|
||||
}
|
||||
|
||||
@defproc[(convert [v convertible?]) pict?]{
|
||||
Requests a data conversion from @racket[v] to a @racket[pict?].
|
||||
@defproc[(pict-convert [v pict-convertible?]) pict?]{
|
||||
Requests a data conversion from @racket[v] to a pict.
|
||||
}
|
||||
|
|
10
collects/slideshow/pict-convert.rkt
Normal file
10
collects/slideshow/pict-convert.rkt
Normal file
|
@ -0,0 +1,10 @@
|
|||
#lang racket/base
|
||||
(require "pict.rkt"
|
||||
racket/contract
|
||||
texpict/private/convertible)
|
||||
|
||||
|
||||
(provide pict-convert pict-convertible?)
|
||||
(provide/contract
|
||||
[prop:pict-convertible (struct-type-property/c (-> pict-convertible? pict?))]
|
||||
[prop:pict-convertible? (struct-type-property/c predicate/c)])
|
|
@ -8,7 +8,6 @@
|
|||
racket/draw/draw-unit
|
||||
"private/mrpict-sig.rkt"
|
||||
"private/common-sig.rkt"
|
||||
"private/convertible.rkt"
|
||||
"mrpict-sig.rkt"
|
||||
"mrpict-unit.rkt")
|
||||
|
||||
|
@ -53,7 +52,3 @@
|
|||
pict?)])
|
||||
|
||||
(provide text-style/c)
|
||||
|
||||
(provide convert convertible?)
|
||||
(provide/contract
|
||||
[prop:convertible (struct-type-property/c (-> convertible? pict?))])
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
panbox ; panorama box, computed on demand
|
||||
last) ; a descendent for the bottom-right
|
||||
#:mutable
|
||||
#:property prop:convertible (λ (v) v)
|
||||
#:property prop:pict-convertible (λ (v) v)
|
||||
#:property file:prop:convertible (lambda (v mode default)
|
||||
(convert-pict v mode default)))
|
||||
(define-struct child (pict dx dy sx sy syx sxy))
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
#lang racket/base
|
||||
(provide prop:convertible prop:convertible? convertible? convert)
|
||||
(provide prop:pict-convertible prop:pict-convertible? pict-convertible? pict-convert)
|
||||
|
||||
(define-values (prop:convertible -convertible? convertible-ref)
|
||||
(make-struct-type-property 'convertible))
|
||||
(define-values (prop:pict-convertible -pict-convertible? pict-convertible-ref)
|
||||
(make-struct-type-property 'pict-convertible))
|
||||
|
||||
(define-values (prop:convertible? convertible?? convertible?-ref)
|
||||
(make-struct-type-property 'convertible?))
|
||||
(define-values (prop:pict-convertible? pict-convertible?? pict-convertible?-ref)
|
||||
(make-struct-type-property 'pict-convertible?))
|
||||
|
||||
(define (convertible? x)
|
||||
(and (-convertible? x)
|
||||
(if (convertible?? x)
|
||||
((convertible?-ref x) x)
|
||||
(define (pict-convertible? x)
|
||||
(and (-pict-convertible? x)
|
||||
(if (pict-convertible?? x)
|
||||
((pict-convertible?-ref x) x)
|
||||
#t)))
|
||||
|
||||
(define (convert v)
|
||||
(unless (convertible? v)
|
||||
(raise-type-error 'convert "convertible" v))
|
||||
((convertible-ref v) v))
|
||||
(define (pict-convert v)
|
||||
(unless (pict-convertible? v)
|
||||
(raise-type-error 'pict-convert "pict-convertible" v))
|
||||
((pict-convertible-ref v) v))
|
||||
|
|
Loading…
Reference in New Issue
Block a user