diff --git a/collects/racket/draw/private/dc.rkt b/collects/racket/draw/private/dc.rkt index f0c3e159d5..2d5f5e46b9 100644 --- a/collects/racket/draw/private/dc.rkt +++ b/collects/racket/draw/private/dc.rkt @@ -122,6 +122,11 @@ ;; Used to keep smoothing disabled for b&w contexts dc-adjust-smoothing + ;; get-hairline-width + ;; + ;; Gets the pen width to use in place of 0 in 'smoothed mode + get-hairline-width + ;; install-color : cairo_t color<%> alpha boolean? -> void ;; ;; Installs a color, which a monochrome context might reduce @@ -186,6 +191,7 @@ (define/public (ok?) #t) (define/public (dc-adjust-smoothing s) s) + (define/public (get-hairline-width sx) (/ 1 sx)) (define/public (install-color cr c a bg?) (let ([norm (lambda (v) (/ v 255.0))]) @@ -236,7 +242,7 @@ (super-new) (inherit flush-cr get-cr release-cr end-cr init-cr-matrix get-pango - install-color dc-adjust-smoothing reset-clip + install-color dc-adjust-smoothing get-hairline-width reset-clip collapse-bitmap-b&w? ok? can-combine-text? can-mask-bitmap? get-clear-operator) @@ -873,11 +879,14 @@ alpha #f))) (cairo_set_line_width cr (let* ([v (send pen get-width)] - [v (if (aligned? smoothing) + [align? (aligned? smoothing)] + [v (if align? (/ (floor (* effective-scale-x v)) effective-scale-x) v)]) (if (zero? v) - 1 + (if align? + (/ 1 effective-scale-x) + (get-hairline-width effective-scale-x)) v))) (unless (or (eq? s 'solid) (eq? s 'xor)) diff --git a/collects/racket/draw/private/local.rkt b/collects/racket/draw/private/local.rkt index 779249ef87..171434b8a2 100644 --- a/collects/racket/draw/private/local.rkt +++ b/collects/racket/draw/private/local.rkt @@ -44,6 +44,7 @@ get-font-metrics-key install-color dc-adjust-smoothing + get-hairline-width can-combine-text? can-mask-bitmap? reset-clip diff --git a/collects/racket/draw/private/post-script-dc.rkt b/collects/racket/draw/private/post-script-dc.rkt index bc083d9fcc..53ddff8ac4 100644 --- a/collects/racket/draw/private/post-script-dc.rkt +++ b/collects/racket/draw/private/post-script-dc.rkt @@ -182,6 +182,8 @@ (define/override (can-mask-bitmap?) #f) + (define/override (get-hairline-width cx) (/ 1.0 (* cx 4))) + (define is-eps? (and as-eps #t)) (define/public (multiple-pages-ok?) (not is-eps?)) diff --git a/collects/scribblings/draw/pen-class.scrbl b/collects/scribblings/draw/pen-class.scrbl index 6da11e48c4..dbda515d49 100644 --- a/collects/scribblings/draw/pen-class.scrbl +++ b/collects/scribblings/draw/pen-class.scrbl @@ -49,10 +49,15 @@ To avoid creating multiple pens with the same characteristics, use the global @scheme[pen-list%] object @indexed-scheme[the-pen-list], or provide a color, width, and style to @xmethod[dc<%> set-pen]. -A pen of size @scheme[0] uses the minimum line size for the - destination drawing context. In (unscaled) canvases and bitmaps, - a zero-width pen behaves the nearly same as a pen of - size @scheme[1]. +When drawing in @racket['smoothed] or @racket['aligned] mode, a pen's + size is truncated after scaling to an integral size. A pen of size + @scheme[0] (after truncation, if applicable) uses a non-zero, + scale-insensitive line size for the destination drawing context: + @racket[1/4] unit (after scaling) for @racket[post-script-dc%] or + @racket[pdf-dc%] contexts in @racket['smoothed] mode, or @racket[1] + unit (after scaling) for any other context. For example, in unscaled + canvas and bitmap contexts, a zero-width pen behaves the same as a + pen of size @scheme[1]. @defconstructor[([color (or/c string? (is-a?/c color%)) "black"] diff --git a/doc/release-notes/racket/Draw_and_GUI_5_1.txt b/doc/release-notes/racket/Draw_and_GUI_5_1.txt index 75d625c27b..1c8aef3cf8 100644 --- a/doc/release-notes/racket/Draw_and_GUI_5_1.txt +++ b/doc/release-notes/racket/Draw_and_GUI_5_1.txt @@ -108,6 +108,13 @@ generates PDF output. The new `svg-dc%' drawing context is similar to `post-script-dc%', but it generates SVG output. +All drawing contexts, including `post-script-dc%' support smoothing +modes, and the default is 'unsmoothed even for `post-script-dc%' --- +which means that PostScript drawing is aligned and pen widths are +truncated to integer sizes by default. Drawing at pen size 0 no longer +triggers ``hairline'' mode, but instead just uses a 1/4-width pen +when in 'smoothed mode. + Other Drawing-Context Changes -----------------------------