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 convert-table (make-hasheq))
|
||||||
(define pict:convertible?
|
(define pict:convertible?
|
||||||
(with-handlers ((exn:fail? (λ (exn) (λ (val) #f))))
|
(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))]
|
(parameterize ([pretty-print-pre-print-hook (λ (val port) (void))]
|
||||||
[pretty-print-post-print-hook (λ (val port) (void))]
|
[pretty-print-post-print-hook (λ (val port) (void))]
|
||||||
[pretty-print-exact-as-decimal #f]
|
[pretty-print-exact-as-decimal #f]
|
||||||
|
@ -469,8 +469,9 @@
|
||||||
(define (mk-pict-snip convertible)
|
(define (mk-pict-snip convertible)
|
||||||
(define-syntax-rule
|
(define-syntax-rule
|
||||||
(dyn name args ...)
|
(dyn name args ...)
|
||||||
((dynamic-require 'texpict/mrpict 'name) args ...))
|
((dynamic-require 'slideshow/pict 'name) args ...))
|
||||||
(define pict (dyn convert convertible))
|
(define pict ((dynamic-require 'slideshow/pict-convert 'pict-convert)
|
||||||
|
convertible))
|
||||||
(define w (dyn pict-width pict))
|
(define w (dyn pict-width pict))
|
||||||
(define h (dyn pict-height pict))
|
(define h (dyn pict-height pict))
|
||||||
(define a (dyn pict-ascent pict))
|
(define a (dyn pict-ascent pict))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#lang scribble/doc
|
#lang scribble/doc
|
||||||
@(require "ss.rkt" "pict-diagram.rkt"
|
@(require "ss.rkt" "pict-diagram.rkt"
|
||||||
(for-label racket/gui slideshow/code slideshow/flash slideshow/face
|
(for-label racket/gui slideshow/code slideshow/flash slideshow/face
|
||||||
slideshow/balloon))
|
slideshow/balloon slideshow/pict-convert))
|
||||||
|
|
||||||
@title[#:style 'toc]{Making Pictures}
|
@title[#:style 'toc]{Making Pictures}
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ PostScript for inclusion into a larger document. The
|
||||||
|
|
||||||
@section{Pict Datatype}
|
@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[hline], create new simple picts. Other functions, such as
|
||||||
@racket[ht-append], build new picts out of existing picts. In the
|
@racket[ht-append], build new picts out of existing picts. In the
|
||||||
latter case, the embedded picts retain their identity, so that
|
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]
|
expected scaling of the image. The @racket[scale/improve-new-text]
|
||||||
form sets this parameter while also scaling the resulting pict.}
|
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
|
@section{Conversion to Picts}
|
||||||
able to convert themselves to @racket[pict?]s. The
|
|
||||||
protocol is used by DrRacket's REPL to render values
|
|
||||||
that it prints out.
|
|
||||||
|
|
||||||
@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
|
A property whose value should be a procedure matching the
|
||||||
contract @racket[(-> any/c pict?)]. The
|
contract @racket[(-> any/c pict?)]. The
|
||||||
procedure is called when a structure with the property is passed to
|
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.
|
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
|
A property whose value should be a predicate procedure
|
||||||
(i.e., matching the contract @racket[predicate/c]).
|
(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)].
|
the function @racket[(λ (x) #t)].
|
||||||
|
|
||||||
If this property is set, then this procedure is called
|
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
|
value is convertible (thereby supporting situations
|
||||||
where some instances of a given struct are convertible
|
where some instances of a given struct are convertible
|
||||||
to picts, but others are not).
|
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
|
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.
|
and @racket[#f] otherwise.
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(convert [v convertible?]) pict?]{
|
@defproc[(pict-convert [v pict-convertible?]) pict?]{
|
||||||
Requests a data conversion from @racket[v] to a @racket[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
|
racket/draw/draw-unit
|
||||||
"private/mrpict-sig.rkt"
|
"private/mrpict-sig.rkt"
|
||||||
"private/common-sig.rkt"
|
"private/common-sig.rkt"
|
||||||
"private/convertible.rkt"
|
|
||||||
"mrpict-sig.rkt"
|
"mrpict-sig.rkt"
|
||||||
"mrpict-unit.rkt")
|
"mrpict-unit.rkt")
|
||||||
|
|
||||||
|
@ -53,7 +52,3 @@
|
||||||
pict?)])
|
pict?)])
|
||||||
|
|
||||||
(provide text-style/c)
|
(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
|
panbox ; panorama box, computed on demand
|
||||||
last) ; a descendent for the bottom-right
|
last) ; a descendent for the bottom-right
|
||||||
#:mutable
|
#:mutable
|
||||||
#:property prop:convertible (λ (v) v)
|
#:property prop:pict-convertible (λ (v) v)
|
||||||
#:property file:prop:convertible (lambda (v mode default)
|
#:property file:prop:convertible (lambda (v mode default)
|
||||||
(convert-pict v mode default)))
|
(convert-pict v mode default)))
|
||||||
(define-struct child (pict dx dy sx sy syx sxy))
|
(define-struct child (pict dx dy sx sy syx sxy))
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
#lang racket/base
|
#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)
|
(define-values (prop:pict-convertible -pict-convertible? pict-convertible-ref)
|
||||||
(make-struct-type-property 'convertible))
|
(make-struct-type-property 'pict-convertible))
|
||||||
|
|
||||||
(define-values (prop:convertible? convertible?? convertible?-ref)
|
(define-values (prop:pict-convertible? pict-convertible?? pict-convertible?-ref)
|
||||||
(make-struct-type-property 'convertible?))
|
(make-struct-type-property 'pict-convertible?))
|
||||||
|
|
||||||
(define (convertible? x)
|
(define (pict-convertible? x)
|
||||||
(and (-convertible? x)
|
(and (-pict-convertible? x)
|
||||||
(if (convertible?? x)
|
(if (pict-convertible?? x)
|
||||||
((convertible?-ref x) x)
|
((pict-convertible?-ref x) x)
|
||||||
#t)))
|
#t)))
|
||||||
|
|
||||||
(define (convert v)
|
(define (pict-convert v)
|
||||||
(unless (convertible? v)
|
(unless (pict-convertible? v)
|
||||||
(raise-type-error 'convert "convertible" v))
|
(raise-type-error 'pict-convert "pict-convertible" v))
|
||||||
((convertible-ref v) v))
|
((pict-convertible-ref v) v))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user