clean up drawing with 0-width pens (hairline mode)

This commit is contained in:
Matthew Flatt 2011-03-27 14:10:34 -06:00
parent 009468d6a8
commit 95f0d16761
5 changed files with 31 additions and 7 deletions

View File

@ -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))

View File

@ -44,6 +44,7 @@
get-font-metrics-key
install-color
dc-adjust-smoothing
get-hairline-width
can-combine-text?
can-mask-bitmap?
reset-clip

View File

@ -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?))

View File

@ -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"]

View File

@ -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
-----------------------------