gillies@m.cs.uiuc.edu (Don Gillies) (06/07/91)
A while ago someone wrote in complaining that they couldn't get ms-word to print graphic PICTures precisely; figures that align or overlap in precise locations change when the graphic was taken from MacDraw II to MS-Word. I've been wrestling with this problem for 3 years. I suggested that, in MacDraw II, you draw everything at 4x resolution (approx 300dpi resolution), and align it at this resolution, and then print on a postscript device to get aligned results. I also suggested using a grid that divides 300 (like 50 divisions / inch). This works fine if all you do is print on a postscript laser printer. But now I own a deskwriter, and have access to three different postscript devices. I need my documents to print well on all devices. After 4 hours of experimenting this evening, and reading INSIDE MACINTOSH, I think I've found the source of the problem, and a sure workaround. In short, "Avoid the rectangle tools in both MacDraw II and in Canvas!". It seems (from inside macintosh) that in the Quickdraw replay language, Rectanges might be stored in PICTures using relative coordinates (i.e. a base plus an offset). Inside Mac volume 1 implies that they are probably *scaled* using relative coordinates. This is bad bad news, since a rectangle x-coordinate represented as (x1,delta) whose right edge must overlap the left edge of a rectangle that is (x2, mu) where x2 = x1 + delta, will not scale correctly in integer arithmetic; you will get (for the right edge) int(x1*scale) + int(delta*scale) <= int(x2*scale) in general; the (x,delta) rectangle will fall to the left of the (y,mu) rectange. The fix is simple: NEVER USE RECTANGLES IN THESE DRAW PROGRAMS. DRAW RECTANGLES WITH THE POLYGON TOOL TO GET DEVICE INDEPENDENCE. NUKE THE RECTANGLE TOOL! Inside macintosh volume 1 says that the scaling methods for polygons are better than for rectangles. I just spent 4 hours drawing a figure with many rectangles (some filled, some cleared, all with hairline borders) with both rectangles polygons in MacDraw II, Canvas. I printed the results on the HP Deskwriter Driver, and with the Freedom of the Press Postscript driver. In all cases, rectangles can NEVER be aligned correctly with the Deskwriter driver; this is because Quickdraw is probably doing stupid scaling to 300dpi (some sort of relative coordinate scaling for rectangles). Not only that, but if you use hairlines (like .5 pt or .25 pt lines), rectangles put fill material OUTSIDE the hairlines on postscript devices -- but POLYGONS FILL CORRECTLY with hairlines in postscript. So by using polygons, you fix TWO problems. And MS-Word prints perfect results! I'm never going to use a rectangle again! REMEMBER: RECTANGLES ARE DEVICE-INDEPENDENCE DEATH. I haven't checked to see what happens with ovals and circles, since I never align these objects. Someone should get Apple to patch quickdraw to solve this problem. When I get some time, I'll try to find out exactly where the problem is in the toolbox. Don Gillies | University of Illinois at Urbana-Champaign gillies@cs.uiuc.edu | Digital Computer Lab, 1304 W. Springfield, Urbana IL --
gillies@m.cs.uiuc.edu (Don Gillies) (06/08/91)
Actually, after reading Inside Macintosh some more, I think there is a fundamental flaw in the architecture of quickdraw. The five primitives Rectangle, RoundRectangle, Oval, Arc, and Region are all specified to fall *within* a rectangular frame. The other two primitives Line and Polygon, paint below and to the right of the display path. The objects that are below and to the right paint correctly; this is because when two objects that overlap along some border, the display path is exactly the same. So you could increase only the pen size and the two objects would continue to be aligned. And when you multiply each integer coordinate by some constant scale factor and round it, you get exactly the same intersection path for both objects (since the coordinates are the same). However, for two Rectangles (etc.) that overlap along some border, and that overlap at resolution x, the display paths are different. The intersection of the interiors of both Rectangles is actually non-empty; it is precisely the line segment of overlap. Consider increasing the pen size; for every increase of 1 pixel in width, you get an extra pixel inside each rectangle, leading to misalignment. When you scale these two rectangles up to 300dpi, roundoff error occurs. Since the (x,y) coordinates of both paths differ, the rounding might be different for both paths. Furthermore, the pen size may turn out to be something like 2.49, which is rounded down to 2 pixels. This results in very serious misalignment after the scaling. The result is that you get a thick line at the border of the two rectangles, i.e. On 72dpi device: Scaled for 300dpi device: +---+ +---+ | | | | +-+-+---+ -> +-+=+---+ | | | | +-----+ +-----+ Don Gillies | University of Illinois at Urbana-Champaign gillies@cs.uiuc.edu | Digital Computer Lab, 1304 W. Springfield, Urbana IL --