Programming with Quartz
2D and PDF Graphics in Mac OS X
- 1st Edition - July 26, 2010
- Authors: David Gelphman, Philip Schneider, Bunny Laden
- Language: English
- eBook ISBN:9 7 8 - 0 - 0 8 - 0 4 5 9 6 3 - 9
Written by members of the development team at Apple, Programming with Quartz is the first book to describe the sophisticated graphics system of Mac OS X. By using the method… Read more
Purchase options
Institutional subscription on ScienceDirect
Request a sales quoteWritten by members of the development team at Apple, Programming with Quartz is the first book to describe the sophisticated graphics system of Mac OS X. By using the methods described in this book, developers will be able to fully exploit the state-of-the-art graphics capabilities of Mac OS X in their applications, whether for Cocoa or Carbon development. This book also serves as an introduction to 2D graphics concepts, including how images are drawn and how color is rendered. It includes guidance for working with PDF documents, drawing bitmap graphics, using Quartz built-in color management, and drawing text. Programming with Quartz is a rich resource for new and experienced Mac OS X developers, Cocoa and Carbon programmers, UNIX developers who are migrating to Mac OS X, and anyone interested in powerful 2D graphics systems.
- This is the definitive guide to the revolutionary graphics system of Mac OS X that uses the Portable Document Format (PDF) as the basis of its imaging model
- It contains the latest on programming with Quartz for Mac OS X version 10.4
- Carefully crafted and extensive code examples show how to accomplish most of the drawing tasks possible with Quartz
Cocoa and Carbon programmers who want to understand and fully exploit the power of the graphics system in Mac OS X and those who are looking to add new drawing capabilities, add support for PDF documents, or improve the quality of the graphics in their applications.
UNIX developers interested in the graphics capabilities of Mac OS X.
Web developers who want to create dynamic content using Quartz.
UNIX developers interested in the graphics capabilities of Mac OS X.
Web developers who want to create dynamic content using Quartz.
Foreword by Philip Schneider
Preface
Our Objective
Outline
Source Code
Header Files
Conventions and Assumptions
Quartz Technologies
Acknowledgements
Chapter 1 Introducing Quartz 2D
A Bit of History
Quartz 2D Overview
What Software Can Use Quartz 2D?
Summary
See Also
Chapter 2 Quartz 2D Drawing Basics
Quartz Graphics Contexts
Filling a Rectangle
Stroking a Rectangle
The Order of Fill and Stroke Operations
Transforming the Coordinate System
Constructing Quartz Paths
Painting with Alpha
Making Dashed Lines
Clipping a Drawing
Drawing PDF Content
More About Graphics Contexts
Summary
See Also
Chapter 3 Using Quartz 2D in Cocoa
Xcode Overview
Creating a Cocoa Xcode Project in Tiger
Creating a View in Interface Builder
Connecting the Interface to the Code
Obtaining a Graphics Context in Cocoa
Writing the Drawing Code
Examining the Drawing Output
Cocoa Framework Drawing and Quartz
Summary
See Also
Chapter 4 Using Quartz 2D in Carbon
Creating a Carbon Xcode Project
Setting Up a Carbon Window
Creating an Event Handler
Examining the Drawing Output
Using QDBeginCGContext
Summary
See Also
Chapter 5 The Quartz Coordinate System and Coordinate Transformations
User Space and Device Space
Coordinate Transformations
The Current Transformation Matrix
The Mathematics of Affine Transforms
Saving and Restoring a Coordinate System
Affine Transform Convenience Functions
Summary
See Also
Chapter 6 Drawing with Paths
Properties of Paths
Path Construction Convenience Functions
Clipping With Paths
CGPath Objects (Jaguar and later only)
Anti-aliasing
Path Utility Functions
See Also
Chapter 7 Color, Alpha Transparency, and the Quartz Graphics State
Color and Color Spaces
Graphics State Parameters
Summary
See Also
Chapter 8 Data Providers and Data Consumers
Data Providers
Data Consumers
Summary
Chapter 9 Drawing Images
Creating CGImage Objects
Image Utility Functions
Exporting to JPEG Using a QuickTime Exporter
Summary
See Also
Chapter 10 Image Masking
Creating an Image Mask
Clipping to a Mask (Tiger)
Summary
See Also
Chapter 11 Text
Text Drawing Parameters
Summary
See Also
Chapter 12 Creating Bits
Bitmap Graphics Context
Summary
See Also
Chapter 13 Opening and Drawing PDF Documents
PDF Document Properties
Opening a PDF Document
Using PDF as a Graphical Interchange
PDF Document Utility Functions
Summary
See Also
Chapter 14 Creating and Examining PDF Documents
Creating New PDF Documents
Adding Content to Existing PDF Documents
Adding Links to PDF Documents (Tiger)
PDF Document Generation Issues
Examining PDF Document Content (Panther, Tiger)
See Also
Chapter 15 Advanced Drawing Features
Drawing with Patterns
See Also
Chapter 16 Supporting PostScript and EPS Data
Overview of the Conversion Process
Quartz Conversion Functions and Callbacks (Panther)
Creating a PDF Data File From PostScript Data
Using Converted PostScript Data in Your Application
PSConverter Advanced Issues
Printing Source EPS Data
Guidelines for Supporting EPS Data in Your Application
Summary
See Also
Chapter 17 Performance and Debugging
Optimizing Performance
See Also
Chapter 18 Creating Quartz Tools and Python Scripts
Python Scripting with Quartz (Panther)
Using Quartz in UNIX Tools
Summary
See Also
Index
Preface
Our Objective
Outline
Source Code
Header Files
Conventions and Assumptions
Quartz Technologies
Acknowledgements
Chapter 1 Introducing Quartz 2D
A Bit of History
Quartz 2D Overview
What Software Can Use Quartz 2D?
Summary
See Also
Chapter 2 Quartz 2D Drawing Basics
Quartz Graphics Contexts
Filling a Rectangle
Stroking a Rectangle
The Order of Fill and Stroke Operations
Transforming the Coordinate System
Constructing Quartz Paths
Painting with Alpha
Making Dashed Lines
Clipping a Drawing
Drawing PDF Content
More About Graphics Contexts
Summary
See Also
Chapter 3 Using Quartz 2D in Cocoa
Xcode Overview
Creating a Cocoa Xcode Project in Tiger
Creating a View in Interface Builder
Connecting the Interface to the Code
Obtaining a Graphics Context in Cocoa
Writing the Drawing Code
Examining the Drawing Output
Cocoa Framework Drawing and Quartz
Summary
See Also
Chapter 4 Using Quartz 2D in Carbon
Creating a Carbon Xcode Project
Setting Up a Carbon Window
Creating an Event Handler
Examining the Drawing Output
Using QDBeginCGContext
Summary
See Also
Chapter 5 The Quartz Coordinate System and Coordinate Transformations
User Space and Device Space
Coordinate Transformations
The Current Transformation Matrix
The Mathematics of Affine Transforms
Saving and Restoring a Coordinate System
Affine Transform Convenience Functions
Summary
See Also
Chapter 6 Drawing with Paths
Properties of Paths
- Path Construction Primitives
- Cubic Bézier Curves
- Quadratic Bézier Curves
Path Construction Convenience Functions
- Additional Path Convenience Functions (Tiger)
- Line Width
- Line Joins
- Line Caps
- Line Dash
Clipping With Paths
CGPath Objects (Jaguar and later only)
Anti-aliasing
Path Utility Functions
- Aligning User Space Coordinates on Pixel Boundaries
See Also
Chapter 7 Color, Alpha Transparency, and the Quartz Graphics State
Color and Color Spaces
- A General Approach to Setting Color
- Calibrated Color Spaces
- Device Color Spaces
- Special Color Spaces
- Creating Color Spaces by Name
- Rendering Intents
- Blend Modes (Tiger)
Graphics State Parameters
Summary
See Also
Chapter 8 Data Providers and Data Consumers
Data Providers
- CGDataProviderCreateWithURL
- CGDataProviderCreateWithData
- CGDataProviderCreate
- CGDataProviderCreateDirectAccess
- CGDataProviderCreateWithCFData (Tiger and later)
Data Consumers
Summary
Chapter 9 Drawing Images
Creating CGImage Objects
- Specialized Functions for JPEG and PNG
- Drawing Images into a Flipped Coordinate System
- A General Function for Uncompressed Data
- Generalized Functions for Compressed Image Data (Tiger and later)
- Importing Image Data With QuickTime
- Guidelines for Image Creation
Image Utility Functions
- Getting Image Dimensions
- Getting the Pixel Format
- Creating an Image from a Bitmap Context
- Working With Color Spaces
- Creating Subimages
Exporting to JPEG Using a QuickTime Exporter
Summary
See Also
Chapter 10 Image Masking
Creating an Image Mask
- Drawing and Inverting a 1-Bit Image Mask
- Drawing an 8-Bit Deep Mask
- Masking an Image with an Image Mask
- Masking an Image with an Image
- Masking Guidelines
Clipping to a Mask (Tiger)
Summary
See Also
Chapter 11 Text
Text Drawing Parameters
- Font and Font Size
- Text Matrix and Text Position
- Text Drawing Modes
- Font Smoothing (Jaguar)
- Character Spacing
- Drawing with Characters
- Drawing with Glyphs
- Using NSString
- Using NSLayoutManager
- Subclassing to Get Additional Control
- Using HIThemeDrawTextBox (Panther)
- Using Multilingual Text Engine
- Using Apple Type Services for Unicode Imaging
Summary
See Also
Chapter 12 Creating Bits
Bitmap Graphics Context
- Supported Pixel Formats
- Creating a Bitmap Graphics Context
- Getting Information About a Bitmap Context
- Using the Bitmap Data from a Bitmap Context
- Creating a CGLayer Object
- Drawing to a CGLayer
- Drawing the Contents of a CGLayer
- Using a CGLayer to Draw a Checkerboard
- Drawing Repeatedly Without Caching
- Drawing Repeatedly With Bitmap Context Caching
- Drawing Repeatedly With CGLayer Caching
- Display Profile Issues
Summary
See Also
Chapter 13 Opening and Drawing PDF Documents
PDF Document Properties
Opening a PDF Document
Using PDF as a Graphical Interchange
- Creating PDF Data From the Pasteboard: Cocoa
- Creating PDF from the Pasteboard: Carbon
- Drawing With CGContextDrawPDFDocument
- Drawing PDF Documents in a Flipped Coordinate System
- Using CGPDFPage Objects (Panther)
- Drawing with PDF Rotation on Jaguar and Earlier
PDF Document Utility Functions
Summary
See Also
Chapter 14 Creating and Examining PDF Documents
Creating New PDF Documents
- Using CGPDFContextCreateWithURL
- Using the Auxiliary Information Dictionary
Adding Content to Existing PDF Documents
Adding Links to PDF Documents (Tiger)
- Creating a Link to a URL
- Creating a Link to Another Page in the Document
PDF Document Generation Issues
Examining PDF Document Content (Panther, Tiger)
- Quartz PDF Introspection
- Scanning the PDF Content Stream (Tiger)
See Also
Chapter 15 Advanced Drawing Features
Drawing with Patterns
- Creating Patterns
- Creating and Drawing Colored Patterns
- Base Space, the Pattern Matrix, and Transforming Patterns
- Pattern Phase
- Creating and Drawing Stencil Patterns
- Drawing Complex Patterns
- Pattern Issues
- Shadow Attributes
- Creating and Drawing With Shadows
- Shadow Offset and Quartz Base Space
- Shadows and Grouped Objects
- Shadows and PDF Documents
- Using Transparency Layers
- Alpha Compositing and Transparency Layers
- Transparency Layers and PDF Documents
- Transparency Layers Compared to CGLayers
- Shading Concepts and the CGFunction
- Axial Shadings
- Radial Shadings
- Radial Shading Geometries
- Transforming Shadings
See Also
Chapter 16 Supporting PostScript and EPS Data
Overview of the Conversion Process
Quartz Conversion Functions and Callbacks (Panther)
Creating a PDF Data File From PostScript Data
Using Converted PostScript Data in Your Application
PSConverter Advanced Issues
Printing Source EPS Data
Guidelines for Supporting EPS Data in Your Application
Summary
See Also
Chapter 17 Performance and Debugging
Optimizing Performance
- The Quartz Compositor
- Quartz Object and Memory Model
- Improving Performance
- Measuring Performance
- Examining the Coordinate System
- Checking the Clipping Area
- Drawing a Debugging Rectangle
- Looking for Console Messages
- Checking for Data Provider Integrity
- Checking for Immutability Violations
- Checking for Improperly Initialized Contexts
- Checking for Out-of-Sync Color Setting
- Drawing Images to a PDF Context
- Releasing a CGPDFContext Object
- Checking Pattern Color Space Usage
- Using PDF Generation as a Debugging Aid
See Also
Chapter 18 Creating Quartz Tools and Python Scripts
Python Scripting with Quartz (Panther)
- Getting Started
Using Quartz in UNIX Tools
- Security Issues
Summary
See Also
Index
- No. of pages: 704
- Language: English
- Edition: 1
- Published: July 26, 2010
- Imprint: Morgan Kaufmann
- eBook ISBN: 9780080459639
DG
David Gelphman
David Gelphman is a senior software engineer on Apple's Graphics and Imaging team. He has over 20 years of experience working with the PostScript and PDF imaging model that is at the heart of Quartz graphics. His computer career began with scientific computing while he was earning his PhD in experimental particle physics at Stanford. Apple's introduction of the Macintosh in 1984 caused him to make a sharp turn into the world of user-friendly computing and he hasn't looked back.While working at Adobe Systems, David co-designed Apple's LaserWriter 8 printer driver and was team lead of the development project. At Adobe he also worked closely with third party developers, taught PostScript programming, wrote a number of technical notes, and contributed to the evolution of the PostScript language. After leaving Adobe he continued to combine software engineering work with documentation for software developers, authoring an article for Apple's develop technical journal in addition to a number of Apple technical notes. Today David writes system software for Mac OS X but continues to be involved with third party documentation and enjoys writing sample code for developers outside of Apple.
Affiliations and expertise
Apple, Cupertino, California, U.S.A.PS
Philip Schneider
24 years of professional programming, primarily focused on modeling tools and geometric algorithms. Employers include Digital Equipment Corporation, Apple, Walt Disney Feature Animation, Digital Domain, and Industrial Light + Magic. Formed and lead groups specializing in these areas as well as in physics simulation.
Film Credits: Oil & Vinegar, 102 Dalmatians, Disney's Magic Lamp, Mickey's Philharmagic, Reign of Fire, Kangaroo Jack, Chicken Little, Indiana Jones and the Kingdom of the Crystal Skull, Pirates of the Caribbean: Dead Man's Chest, Harry Potter and the Goblet of Fire.
ACM Siggraph, IEEE.
M.S. in Computer Science, University of Washington.
Affiliations and expertise
Employers include Digital Equipment Corporation, Apple, Walt Disney Feature Animation, Digital Domain, and Industrial Light + MagicBL
Bunny Laden
Bunny Laden is a senior technical writer for Apple Computer who writes documentation for Mac OS X technologies, including Quartz, Core Image, and Quartz Composer. She has won technical writing awards for a number of Apple documents— QuickTime VR Authoring Studio, Handling Unicode Text With MLTE, Supporting Printing in Your Application—and for the book Learning Carbon (O'Reilly & Associates). In her former life as an academician, she authored articles on a number of topics including music cognition and musical acoustics.
Affiliations and expertise
Apple, Cupertino, California, U.S.A.Read Programming with Quartz on ScienceDirect