Graphics Primitives
Everything seen on a classic Mac OS screen is drawn by QuickDraw, but the library itself is quite low level. The primitive objects it can draw are:
- Lines
- Rectangles
- Rounded (and oval) cornered rectangles
- Ovals (including circles and ellipses)
- Arcs (and wedges), both circular and oval
- Polygons (arbitrary closed shapes built from a list of points joined by lines)
- Regions (arbitrary sets of pixels—see below)
- Bitmaps and Pixmaps
- Text
Each of these objects (except text) may be drawn using a "pen", which can have any rectangular dimensions, pattern or color. Note that, because the pen is rectangular and axis-aligned, diagonal lines will end up thicker than horizontal or vertical ones. Shapes may be drawn filled or framed, using any pattern or color. A filled Arc forms a wedge. Text may be drawn in any installed font, in a variety of stylistic variations, and at any size and color. Text is scaled in a variety of ways depending on how it is stored - TrueType fonts will scale smoothly to any size, whereas bitmap fonts do not usually scale well.
An important feature of QuickDraw was support for transfer modes, which governed how a destination pixel value was related to its previous value and the color of the object being drawn.
The set of attributes of the pen and text drawing are associated with the GrafPort.
Regions are a key data structure in QuickDraw. They define an arbitrary set of pixels, rather like a bitmap, but in a compressed form which can be very rapidly manipulated in complex ways. Regions can be combined (union), subtracted (difference), and XORed to form other Regions. They can be used within a GrafPort for clipping, or drawn filled or framed like any other shape. A series of framed shapes and connected lines may be combined into a Region. A Region need not consist of a contiguous set of pixels - disconnected regions are possible and common. Although regions could allow powerful graphic manipulations they are limited by the current implementation that restricts the maximum region data storage size to a sixteen bit value and so are not practical as a general-purpose drawing composition tool and practical use at high resolution is also restricted. Regions underpin the rest of QuickDraw, permitting clipping to arbitrary shapes, essential for the implementation of multiple overlapping windows. Invented by Bill Atkinson, Regions were patented as a separate invention by Apple.
A region is specified (after initial creation) by an opening of the region, drawing various QuickDraw shapes, and closing the region. Hidden routines construct the region as the QuickDraw commands are executed. Bitmaps may also be converted to regions, and bitmaps may be made from regions by "painting" or "filling" the region into a graphics port.
The internal structure of a region, other than the storage length and its bounding rectangle, is opaque - there are no Apple-published documents available, though the mechanism is outlined in the patent. Regions are implemented using both vertical and horizontal compression. A region is stored as a series of horizontal scan lines ("rasters"), each of which contains a vertical coordinate followed by a list of horizontal inversion coordinates. Each inversion point can be thought of as toggling inclusion in the region for all the points after it: the first point turns the region on, the second turns it off, and so on. Further compression is achieved by storing each line differentially: each line contains only the differences from the previous line rather than a full set of inversion points. Finally, identical adjacent scan lines are efficiently encoded by simply skipping them. In this way, a commonly used region, the rounded corner rectangle, is efficiently encoded, and complex operations such as region composition and image clipping may be done without requiring either extensive processor cycles or large amounts of memory. (The original systems executing QuickDraw code used processors operating at 8 megahertz clock rates and systems had but 128 kilobytes of writable memory.)
Because regions are bound to a specific orientation, a ninety degree rotation of a region would require both detailed reverse engineering of the structure and extensive coding. A general rotation is impractical when compared to rotating the original source boundary description and simply creating a new region. However, the API includes conversion routines to and from BitMaps. (Bitmaps may also be rotated using well known methods, but with various degrees of image degradation depending upon angle chosen, the storage and processor cycles available to the operation, and the complexity of the algorithm.)
Apple has recently (in the Carbon API) defined regions as an opaque structure under some program compilation options.
Read more about this topic: QuickDraw