From 7dc63162728b695b93a28b047dfafc841e4302e4 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 5 Jan 2014 12:29:42 -0700 Subject: [PATCH] correct backing scale on Retina canvas & derived contexts One consequence is that drawing with a pen of width 0 into a canvas% object on a Retina display draws a line that is half as wide as a pen of width 1. --- .../draw-doc/scribblings/draw/pen-class.scrbl | 6 +++--- .../gui-lib/mred/private/wx/cocoa/dc.rkt | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pkgs/draw-pkgs/draw-doc/scribblings/draw/pen-class.scrbl b/pkgs/draw-pkgs/draw-doc/scribblings/draw/pen-class.scrbl index 61fe0d2a7e..b324bd0b90 100644 --- a/pkgs/draw-pkgs/draw-doc/scribblings/draw/pen-class.scrbl +++ b/pkgs/draw-pkgs/draw-doc/scribblings/draw/pen-class.scrbl @@ -55,15 +55,15 @@ To avoid creating multiple pens with the same characteristics, use the global @racket[pen-list%] object @indexed-racket[the-pen-list], or provide a color, width, and style to @xmethod[dc<%> set-pen]. -When drawing in @racket['smoothed] or @racket['aligned] mode, a pen's +When drawing in @racket['unsmoothed] or @racket['aligned] mode, a pen's size is truncated after scaling to an integral size. A pen of size @racket[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 @racket[1]. + canvas and bitmap contexts with a @tech{backing scale} of 1.0, + a zero-width pen behaves the same as a pen of size @racket[1]. See also @racket[make-pen]. diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/dc.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/dc.rkt index d0cdabf1c6..419a5c2037 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/dc.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/dc.rkt @@ -160,12 +160,16 @@ (define is-trans? trans?) - (super-make-object w h trans? 1 - (let ([cg (CGLayerGetContext layer)]) - (unless flipped? - (CGContextTranslateCTM cg 0 h) - (CGContextScaleCTM cg 1 -1)) - cg)) + (let ([bs (inexact->exact + (display-bitmap-resolution 0 (lambda () 1)))]) + (super-make-object w h trans? bs + (let ([cg (CGLayerGetContext layer)]) + (unless flipped? + (CGContextTranslateCTM cg 0 h) + (CGContextScaleCTM cg 1 -1)) + (unless (= bs 1) + (CGContextScaleCTM cg (/ 1 bs) (/ 1 bs))) + cg))) (define/override (draw-bitmap-to cr sx sy dx dy w h alpha clipping-region) ;; Called when the destination rectangle is inside the clipping region