From QuickDraw to Quartz 2D
Before launching into an in-depth discussion of the features of Quartz 2D or a set of drawing techniques, this chapter begins by placing the library in context. The Quartz 2D library has a long legacy behind it and understanding that legacy may help you to recognize some of the idiosyncrasies of the library’s imaging model. Moreover, Quartz 2D is a single part in a larger graphics architecture on Mac OS X. This architecture was designed from its inception to take advantage of advances in the graphics hardware of modern personal computers. This chapter begins with a historical perspective of the Mac OS X graphics system and the evolution of technology behind Quartz 2D. We then explore crucial aspects of the graphics technology that is shaping the graphics architecture of the Macintosh.
The Legacy of QuickDraw and the Rise of PDF
The QuickDraw graphics library stands to this day as testament to the original Macintosh computer and its creators. The library was the fundamental technology that made the original Macintosh graphical user interface possible. QuickDraw was brought to life by the ingenuity and skill of software designers such as Bill Atkinson and Andy Herzfeld. Apple created QuickDraw in the late 1970’s and early 1980s, an era in which "real" computer graphics were the province of large, powerful mainframe computers, and personal computers were just making the transition from novelty to necessity.
QuickDraw had very modest beginnings. In various forms, the original code ran on computers like the Apple Lisa and the original Macintosh. The high resolution bitmapped displays of these computers was considered a revolution when compared to the character terminals of the previous computer generation. In spite of their sophistication, however, the computers could only display graphics in black and white.
QuickDraw was flexible enough to produce impressive graphics on both the screen and on printer. The library incorporated a number of revolutionary advances, features that were not found on personal computers prior to the Macintosh. Among these were the support for pixel regions, drawing operations that could be recorded into a meta-file (the infamous PICT file format), the ability to scale the drawings in a meta-file on playback, and drawing primitives for ovals, curves, and rounded rectangles.
The 9-inch black and white display of the original Macintosh quickly became a thing of the past. Computers evolved, as did the sophistication and requirements of applications and users. Apple evolved QuickDraw along with its computers. As displays became capable of reproducing millions of colors and two tone dot-matrix printers evolved into high-resolution, photo quality ink jet printers, QuickDraw both kept up the pace and pushed the envelope of graphics evolution. The era of QuickDraw ended, however, when Apple deprecated the technology in Mac OS X 10.4 Tiger. The QuickDraw library came of age as an important building block for vital graphics technologies like QuickTime and ColorSync. Along the way it not only served the graphics industry, but also took a hand in shaping it.
PostScript and Desktop Publishing
QuickDraw was not the only technology born in 1984 to have a profound impact both the graphics industry and the Mac OS X platform. In the same year, Chuck Geschke and John Warnock incorporated a new company, Adobe Systems Inc. Adobe released the first version of their PostScript graphics system that same year.
The PostScript graphics system grew out of research Adobe’s founders performed while working at Xerox. That research centered around innovative ways to write control software for laser printers. The PostScript system combines a rich graphics model, a simple programming language, and a run-time environment. At the time of its introduction, the system’s ability to repurpose graphics on a broad number of printers with very different capabilities was a clarion call for the graphics industry.
PostScript was unusual because of the device independence inherit in the system. A PostScript program could send the same drawing commands to two printers with very different capabilities, and both would reproduce the same graphic to the best of their abilities. One printer might draw the graphic with a low resolution and in black and white, while the same program on another printer might generate a high-resolution color image. This was in stark contrast to the fixed resolution, device dependent nature of QuickDraw and other graphics libraries.
The paths of QuickDraw and PostScript were destined to converge. Apple and Adobe brought these two technologies together when they developed the LaserWriter printer. In spite of the fact that QuickDraw had one drawing model, and PostScript a completely different one, application developers combined the on-screen drawing with QuickDraw and the printing might of PostScript. This synthesis led to the creation of creative applications such as Aldus PageMaker and Adobe Illustrator. Applications like these freed document editors from the proprietary typesetting systems that had dominated the industry. The Desktop Publishing revolution had arrived.
PostScript on the Screen
The rift between the graphics model of the screen and the graphics model of the printer continued for some time. In fact, this was not limited to the Macintosh platform. Microsoft Windows, for example, used the GDI graphics library when drawing on screen. On many UNIX systems, applications used the XLib library of the X11 windowing system to create graphics on the screen. Both GDI and XLib are graphics libraries very similar to QuickDraw. Each of these environments also supported PostScript as a tool for creating high-quality graphics on the printer.
In this environment, application developers applied their creativity and ingenuity to bridge the gap between libraries and create WYSIWYG applications. It wasn’t long before enterprising developers realized the potential benefit of using PostScript for graphics on the screen as well. In fact, one of the earliest implementations of this idea came when Sun Microsystems created an entire windowing system based on PostScript! That windowing system was called NeWS, the Network extensible Windowing System.
NeWS was unusual because it used PostScript as more than just a graphics library. The windowing system itself was implemented on top of a customized PostScript interpreter. Developers could extend the system or write NeWS applications in PostScript. In spite of the novelty and innovation in NeWS, however, it never gained much of a foothold in the industry. Eventually it faded from view.
The engineers at Sun were not the only group to bring PostScript to the screen. One of the most successful environments to integrate PostScript into its graphics architecture was the NeXT Computer operating system. Steve Jobs started NeXT Inc. shortly after leaving Apple. The computers that company created were revolutionary in a number of ways. The NeXT operating system included an optimized PostScript interpreter. Applications created their graphics in windows by calling routines invoked the PostScript interpreter.
The success of the NeXT graphics library caused other industry leaders to take notice. Adobe collaborated with NeXT to create a standard called Display PostScript for PostScript graphics on the screen. Display PostScript incorporated a small set of extensions to the basic PostScript language. In time, Adobe licensed Display PostScript for use in other computing environments. The X11 applications on some UNIX computers could create windows that contained Display PostScript graphics. Display PostScript, like the NeWS window system, never gained a broad acceptance in the industry. When Apple purchased NeXT Computer, in 1996, it acquired all of its technologies, including its implementation of Display PostScript.
PDF to Quartz 2D
Even though Display PostScript enjoyed limited popularity, the appeal of PostScript continues to this day. There is, however, one evolution that is particularly relevant to the Macintosh and Quartz 2D.
The PostScript system includes both an imaging model and a programming language. While the flexibility of the imaging model continues to this day, the programming language aspects of PostScript have proven to be problematic.
PostScript interpreters run PostScript programs. Like most programs, PostScript code must execute sequentially. This can lead to difficulty when printing documents. For example, if a press operator wants to print page 99 of a 100-page document, the PostScript interpreter must execute the code that draws the first 98 pages. The results of that drawing take time, and the resulting graphics are merely discarded. This is obviously a waste of time and resources.
Furthermore, because PostScript drawings are actually programs, they are susceptible to programming bugs. To continue the example just discussed, a logic error on page 97 might cause the printer to abandon the entire print job. As these problems came to light, Adobe added some features to PostScript. The new features helped to alleviate problems but did not eliminate them. In the end Adobe recognized the limitations of PostScript and took another tack on the problem.
The Portable Document Format (PDF) works around many of the limitations of PostScript. At its heart, PDF is a file format that includes the graphics features of PostScript (with a few minor changes). At the same time, the standard removes most of the programming language aspects of PostScript. A PDF document is not an executable program so much as it is a structured container for drawing commands and related metadata. The file format continues PostScript’s advantages of device and resolution independence. In short, PDF retains the graphical power of PostScript but eliminates some of its less reliable aspects.
Apple evaluated the technologies they purchased for NeXT with a eye toward creating Mac OS X. They looked at the evolution of PostScript and the PDF strategy. Combining these elements with their own unique flair, Apple developed a new graphics library for Mac OS X that combined the richness of the Adobe Imaging Model with alpha channel support in the high-performance graphics library we know today as Quartz 2D.
Understanding this legacy can be an important part of understanding why the Quartz 2D imaging model behaves as it does. For example, Quartz 2D does not provide an easy mechanism for erasing graphics you have already drawn. The reason is that when you are drawing to a printer, the graphics may not be going to a frame buffer, and there is no way to erase graphics. Instead of erasing graphics, in Quartz 2D you create a mask, or clipping area, and draw the graphics you want the user to see relying on the mask to remove parts of the image you don’t want to display. This is a simple example but very illustrative of how the drawing model of the library can affect how it is used.