From: Matthew Flatt <mflatt@cs.utah.edu> To: plt-scheme@web-ext.cs.brown.edu Subject: [plt-scheme] 299.26 Date: Tue, 4 Jan 2005 11:20:41 -0700 The exp-tagged code in CVS for MzScheme and MrEd is now version 299.26. This version of MrEd includes support for smooth (i.e., anti-aliased) drawing of lines and curves, plus drawing and filling of paths. For example, the program (which is in the new docs) http://www.cs.utah.edu/~mflatt/tmp/plt-logo.ss produces the output shown in the screen dump http://www.cs.utah.edu/~mflatt/tmp/plt-logo.png (The screen dump is from X, but it looks the same under Mac OS X and Windows.) To get smoothing under X, you must install Cairo before configuring and compiling MrEd. To get smoothing under Windows, you need Windows XP or Microsoft’s gdiplus.dll (someplace that MrEd can find it). Smoothing is always available under Mac OS X. Path-based drawing works with or without smoothing. Here’s a screen dump for "plt-logo.ss" without smoothing: http://www.cs.utah.edu/~mflatt/tmp/plt-logo-bumpy.png MrEd supports two smoothing modes. With the ’smoothed mode, drawing works as in PostScript (i.e., the pen is centered over a path), and integer coordinates fall between pixels. As a result, drawing a horizontal line from (0,10) to (10, 10) with a pen width 1 actually paints two rows of pixels, each at 50%. The ’aligned mode is like ’smoothed, but most drawing is shifted by half a pixel in each dimension (but only when the context is unscaled and when the pen width is no larger than 1). See the docs for details. For region% objects, operations like `subtract’ are not reliable in smoothed mode. Instead of using these operations to define a region, construct a suitable path and then either fill the path or use the new `set-path’ method of region%. Filling the path is preferable, in part because the Windows implementation of smoothing does not smooth the boundary of a clipping region. Changes: * Added `set-smoothing’ and `get-smoothing’ to dc<%>. If smoothing is not available, then calling `set-smoothing’ has no effect, and `get-smoothing’ always returns ’unsmoothed. For a post-script-dc%, `get-smoothing’ always returns ’smoothed. * Added dc-path% class, added `draw-path’ to dc<%>, and added `set-path’ to region%. A dc-path% object encapsulates a PostScript-style path, and it supports `translate’, `scale’, and `rotate’ methods. Internally, a path is a sequence of lines and Bezier curves, but the dc-path% class includes convenience methods like `rectangle’, `ellipse’, and `arc’. Drawing an `ellipse’ path is not the same as using `draw-ellipse’; the `draw-ellipse’ method uses the ellipse-drawing API of the platform’s graphics toolbox, whereas MrEd always converts a path to Bezier curves --- and in unsmoothed mode, converts the curves to lines to use with the platform’s support for polygon. In practice, `ellipse’ and `draw-ellipse’ turn out to be the same in smoothed mode, but `ellipse’ is different and more consistent across platforms in unsmoothed mode. * Added `in-region?’ and `xor’ methods to region%. * Added variants of dc<%>’s `set-{pen,brush}’ that accept arguments like `find-or-create-{pen,brush}’ in `the-{pen,brush}-list’. * Changed default of radius argument of `set-rounded-rectangle ’ in region% to -0.25 (to make it consistent with the dc<%> method). * Cleaned up the interaction between regions and dc% scaling. Matthew From: Matthew Flatt <mflatt@cs.utah.edu> To: plt-scheme@web-ext.cs.brown.edu Subject: [plt-scheme] 299.26 - now more ’aligned Date: Thu, 6 Jan 2005 15:37:13 -0700 New exp-tagged code for MrEd makes ’aligned smoothing work better. Although ’smoothed mode is mathematically simpler, probably ’aligned mode is better than ’smoothed for most purposes. Like ’smoothed mode, ’aligned draws curves and lines with smoothing, but it first aligns shapes on pixel boundaries to avoid blurring. In particular, vertical and horizontal lines always match pixel boundaries in ’aligned mode. The ’aligned mode is also more consistent with ’unsmoothed mode. For example, the outline of two ellipses of width N will touch --- but not overlap --- when they are separated horizontally by N. In contrast, the two ellipses overlap by half a pen width in ’smoothed mode, since the pen is cenetered on the ellipse edge. Consistency with ’unsmoothed is useful if you cannot depend on the availability of smoothing (e.g., because the end user under X didn’t install Cairo). The ’aligned mode is implemented by applying `floor’ to drawing locations after scaling and translation. For pen drawing, the locations are further shifted down and right by half a pen width, and widths and heights (for rectangles, ellipses, etc.) are reduced by half a pen width. [I think that ’aligned is essentially the same thing as Java 1.3’s VALUE_STROKE_NORMALIZE.] Matthew