add width' and height' arguments to post-script-dc% and pdf-dc%

and document the change that the PS bounding box is no longer
 inferred from drawing operations
This commit is contained in:
Matthew Flatt 2010-11-26 17:20:24 -07:00
parent a45792ca1c
commit abcaa1775c
5 changed files with 70 additions and 26 deletions

View File

@ -23,12 +23,22 @@
[parent #f]
[use-paper-bbox #f]
[as-eps #t]
[(init-w width) #f]
[(init-h height) #f]
[output #f])
(let ([get-name (lambda ()
(init-name (if pdf? 'pdf-dc% 'post-script-dc%)))])
(unless (or (not init-w)
(and (real? init-w) (not (negative? init-w))))
(raise-type-error (get-name) "nonnegative real or #f" init-w))
(unless (or (not init-h)
(and (real? init-h) (not (negative? init-h))))
(raise-type-error (get-name) "nonnegative real or #f" init-h))
(unless (or (not output)
(path-string? output)
(output-port? output))
(raise-type-error (init-name (if pdf? 'pdf-dc% 'post-script-dc%)) "path string, output port, or #f" output))
(raise-type-error (get-name) "path string, output port, or #f" output)))
(define-values (s port-box close-port? width height landscape?)
(let ([su (if interactive
@ -60,8 +70,12 @@
(not fn))
(values #f #f #f #f #f #f)
(let* ([paper (assoc (send pss get-paper-name) paper-sizes)]
[w (cadr paper)]
[h (caddr paper)]
[w (if (or (not init-w) use-paper-bbox)
(cadr paper)
init-w)]
[h (if (or (not init-h) use-paper-bbox)
(caddr paper)
init-h)]
[landscape? (eq? (send pss get-orientation) 'landscape)]
[file (if (output-port? fn)
fn
@ -91,17 +105,21 @@
(values #f #f #f #f #f #f)])))
(define-values (margin-x margin-y)
(if as-eps
(values 0.0 0.0)
(let ([xb (box 0)] [yb (box 0.0)])
(send (current-ps-setup) get-margin xb yb)
(values (unbox xb) (unbox yb))))
(values (unbox xb) (unbox yb)))))
(define-values (scale-x scale-y)
(let ([xb (box 0)] [yb (box 0.0)])
(send (current-ps-setup) get-scaling xb yb)
(values (unbox xb) (unbox yb))))
(define-values (trans-x trans-y)
(if as-eps
(values 0.0 0.0)
(let ([xb (box 0)] [yb (box 0.0)])
(send (current-ps-setup) get-translation xb yb)
(values (unbox xb) (unbox yb))))
(values (unbox xb) (unbox yb)))))
(unless pdf?
(when (and s as-eps)

View File

@ -16,6 +16,8 @@ See also @scheme[printer-dc%].
[parent (or/c (is-a?/c frame%) (is-a?/c dialog%) false/c) #f]
[use-paper-bbox any/c #f]
[as-eps any/c #t]
[width (or/c (and/c real? (not/c negative?)) #f) #f]
[height (or/c (and/c real? (not/c negative?)) #f) #f]
[output (or/c path-string? output-port? #f) #f])]{
If @scheme[interactive] is true, the user is given a dialog for
@ -36,19 +38,21 @@ If @scheme[interactive] is @scheme[#f], then the settings returned by
hit @onscreen{Cancel} in that case so that @method[dc<%> ok?] returns @scheme[#f].
If @scheme[use-paper-bbox] is @scheme[#f], then the PostScript
bounding box for the output is determined by drawing commands issued
to the object; such a bounding box encloses all parts of the drawing
@italic{ignoring} clipping regions (so the bounding box may be
approximate). If @scheme[use-paper-bbox] is not @scheme[#f], then the
bounding box is determined by the current paper size (as specified by
@scheme[current-ps-setup]), and the bounding box does not include the
margin (also specified by @scheme[current-ps-setup]).
bounding box for the output is determined by @racket[width] and
@racket[height]. If @scheme[use-paper-bbox] is not @scheme[#f], then
the bounding box is determined by the current paper size (as
specified by @scheme[current-ps-setup]). When @racket[width] or
@racket[height] is @racket[#f], then the corresponding dimension is
determined by the paper size, even if @racket[use-paper-bbox] is
@racket[#f].
@index["Encapsulated PostScript (EPS)"]{If} @scheme[as-eps] is
@scheme[#f], then the generated PostScript does not include an
Encapsulated PostScript (EPS) header, and instead includes a generic
PostScript header. Otherwise, the generated PostScript includes a
header that identifiers it as EPS.
PostScript header. The margin and translation factors specified by
@racket[current-ps-setup] are used only when @racket[as-eps] is
@racket[#f]. If @racket[as-eps] is true, then the generated
PostScript includes a header that identifiers it as EPS.
When @racket[output] is not @racket[#f], then file-mode output is
written to @racket[output]. If @racket[output] is @racket[#f], then

View File

@ -953,8 +953,20 @@
(let ([dc (if kind
(let ([dc (case kind
[(print) (make-object printer-dc%)]
[(ps) (make-object post-script-dc%)]
[(pdf) (make-object pdf-dc%)])])
[(ps pdf)
(let ([page?
(eq? 'yes (message-box
"Bounding Box"
"Use paper bounding box?"
#f
'(yes-no)))])
(new (if (eq? kind 'ps)
post-script-dc%
pdf-dc%)
[width (* xscale DRAW-WIDTH)]
[height (* yscale DRAW-HEIGHT)]
[as-eps (not page?)]
[use-paper-bbox page?]))])])
(and (send dc ok?) dc))
(if (and use-bitmap?)
(begin

View File

@ -459,6 +459,8 @@
(let ([dc (new (if (eq? format 'eps-bytes) post-script-dc% pdf-dc%)
[interactive #f]
[as-eps #t]
[width (pict-width p)]
[height (pict-height p)]
[output s])])
(send dc start-doc "pict")
(send dc start-page)

View File

@ -95,6 +95,17 @@ backward-compatibile. Methods like `get-translation',
`set-translation', `scale', etc. help hide the reundancy.
PostScript and PDF Drawing Contexts
-----------------------------------
The dimensions for PostScript output are no longer inferred from the
drawing. Instead, the width and height must be supplied when the
`post-script-dc%' is created.
The new `pdf-dc%' drawing context is like `post-script-dc%', but it
generates PDF output.
Other Drawing-Context Changes
-----------------------------
@ -112,9 +123,6 @@ that it is installed as a clipping region.
The old 'xor mode for pens and brushes is no longer available (since
it is not supported by Cairo).
The new `pdf-dc%' drawing context is like `post-script-dc%', but it
generates PDF output.
Editor Changes
--------------