O'Reilly logo

Learning Cocoa with Objective-C, 2nd Edition by James Duncan Davidson, Apple Computer Inc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. Printing

In the past, code to handle printing has been difficult to write. Many factors, such as margins, page orientation, and paper size, come into play. The differences in drawing models (between screen drawing and drawing to the printer) have made things even more challenging. Cocoa provides a clean printing interface that uses the same drawing model used to draw to the screen. In addition, just as Cocoa supports the use of calibrated color when drawing to the screen, ColorSync provides advanced color management when printing to paper.

As we saw in Chapter 7, when a view object receives a drawRect: message, it responds by drawing itself into the current graphics context. Usually, this context is a frame buffer, and the drawRect: message results in the view drawing its contents to the screen. The same machinery is used during printing, but the current graphics context is set to be the printer.

Remember (as discussed in Chapter 7) that the drawRect: method is never called directly to make a view appear on the screen; it is called only when the display message is sent to the view. The same methodology applies to printing; the drawRect: method is called when a print: message is sent to the view. Calling print: on a view causes the AppKit to display a print panel that asks the user which printer she wishes to use (along with page setup information). When the user clicks the Print button of the print panel, a sequence of drawRect: messages—one for each page—is sent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required