From 351e82735bb280825bb9c6fb042941134528939e Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 6 Apr 2012 11:15:33 -0600 Subject: [PATCH] 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. --- collects/drracket/private/language.rkt | 7 +++-- collects/scribblings/slideshow/picts.scrbl | 34 ++++++++++++---------- collects/slideshow/pict-convert.rkt | 10 +++++++ collects/texpict/mrpict.rkt | 5 ---- collects/texpict/private/common-unit.rkt | 2 +- collects/texpict/private/convertible.rkt | 26 ++++++++--------- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 collects/slideshow/pict-convert.rkt diff --git a/collects/drracket/private/language.rkt b/collects/drracket/private/language.rkt index bbbd7aca0f..c92d1090c9 100644 --- a/collects/drracket/private/language.rkt +++ b/collects/drracket/private/language.rkt @@ -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)) diff --git a/collects/scribblings/slideshow/picts.scrbl b/collects/scribblings/slideshow/picts.scrbl index fdbb3c28ed..cf9c907e4d 100644 --- a/collects/scribblings/slideshow/picts.scrbl +++ b/collects/scribblings/slideshow/picts.scrbl @@ -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. } diff --git a/collects/slideshow/pict-convert.rkt b/collects/slideshow/pict-convert.rkt new file mode 100644 index 0000000000..90bb7f545c --- /dev/null +++ b/collects/slideshow/pict-convert.rkt @@ -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)]) diff --git a/collects/texpict/mrpict.rkt b/collects/texpict/mrpict.rkt index 708b119b76..edbd9c469f 100644 --- a/collects/texpict/mrpict.rkt +++ b/collects/texpict/mrpict.rkt @@ -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?))]) diff --git a/collects/texpict/private/common-unit.rkt b/collects/texpict/private/common-unit.rkt index 7cb13ff1b8..62305a1908 100644 --- a/collects/texpict/private/common-unit.rkt +++ b/collects/texpict/private/common-unit.rkt @@ -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)) diff --git a/collects/texpict/private/convertible.rkt b/collects/texpict/private/convertible.rkt index b324b7c2ff..579c48da3d 100644 --- a/collects/texpict/private/convertible.rkt +++ b/collects/texpict/private/convertible.rkt @@ -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))