
I strongly encourage non-Macintosh programmers to pick up this book and find out for themselves what a truly great development platform we have in the Macintosh. Programmers and software managers at Windows, Linux, and Unix shops should seriously consider the Macintosh as an addition to (or replacement for!) their current stable of platforms. In particular, movie studios, animation houses, and special-effects facilities would do well to consider that with Macintosh, a single platform can provide every- thing they need…. —from the foreword by Philip J. Schneider R&D Engineer, Industrial Light + Magic Finally, the book I’ve wanted for years is here! As a graphics pro- grammer, I appreciate the clear explanations of how Quartz has packaged the state of the art for mere mortals. As a Cocoa pro- grammer, I appreciate the clear explanation of which [Quartz] facilities…Cocoa is already leveraging. This will become a well- thumbed resource for all graphics programmers on Mac OS X, whether or not they’re using Cocoa, Carbon, or porting code from another platform. —Dr. Michael B. Johnson Pixar Animation Studios I’ve been using Quartz since the first release of Mac OS X, and this book covers it all! Great advice, good sample code—it’s the book to have if you want to learn everything about Quartz. —Stephane Marcouiller SDE, Microsoft Corporation Not only do the authors of Programming with Quartz have a superb understanding of their subject matter, but they have conveyed their knowledge in a clear, concise, and readable manner. Program- ming with Quartz has saved me quite a bit of time on my first major Quartz project, and its more general lessons on graphics programming techniques and concepts will prove valuable when using any modern graphics API. —Josh Aas Software Engineer, Mozilla Corporation Even after implementing several features using Quartz, I still learned things from this book that I did not know. For example, the chapter on handling PDF images is very thorough in its descriptions and the issues it raises. I wish I had this chapter when I implemented this feature. The book is very well written and covers many complex topics in 2D graphics clearly and at a level appropriate for all programmers. Programming with Quartz contin- ues Apple's tradition of producing excellent documentation for its developers. —Ron Ullmann Macintosh Business Unit, Microsoft Corporation Programming with Quartz 2D and PDF Graphics in Mac OS X David Gelphman Bunny Laden Senior Editor Tim Cox Publishing Services Manager Simon Crump Project Manager Elisabeth Beller Assistant Editor Rick Camp Editorial Assistant Jessica Evans Cover Design Laurie Anderson Cover Image © Digital Vision/Getty Images (photographer, Chris Knapton) Text Design Rebecca Evans Composition Nancy Logan Technical Illustration Dartmouth Publishing, Inc.; Apple Copyeditor Yonie Overton Proofreader Jennifer McClain Indexer Steve Rath Interior and Cover Printer Transcontinental Interglobe © 2006 by Apple Computer, Inc. All rights reserved. Apple, the Apple logo, AppleScript, Aqua, Carbon, Cocoa, ColorSync, LaserWriter, Mac, Mac OS, Macintosh, Panther, PowerBook, Quartz, QuickDraw, QuickTime, and Xcode are trademarks of Apple Computer, Inc., registered in the United States and other coun- tries, used by Morgan Kaufmann with permission. Apple Remote Desktop, Finder, Gadget, and Tiger are trademarks of Apple Computer, Inc. used by Morgan Kaufmann with permission. Designations used by companies to distinguish their products are often claimed as trade- marks or registered trademarks. In all instances in which Morgan Kaufmann Publishers is aware of a claim, the product names appear in initial capital or all capital letters. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration. Morgan Kaufmann Publishers is an imprint of Elsevier. 500 Sansome Street, Suite 400, San Francisco, CA 94111 No part of this publication may be reproduced, stored in a retrieval system, or transmit- ted in any form or by any means—electronic, mechanical, photocopying, scanning, or otherwise—without prior written permission of the publisher. Permissions may be sought directly from Elsevier’s Science & Technology Rights Depart- ment in Oxford, UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, e-mail: [email protected]. You may also complete your request on-line via the Elsevier homepage (http://elsevier.com) by selecting “Customer Support” and then “Obtaining Per- missions.” Library of Congress Cataloging-in-Publication Data Application submitted. ISBN 13: 978-0-12-369473-7 ISBN 10: 0-12-369473-6 For information on all Morgan Kaufmann publications, visit our website at www.mkp.com or www.books.elsevier.com. Printed in Canada 05 06 07 08 09 5 4 3 2 1 Working together to grow libraries in developing countries www.elsevier.com | www.bookaid.org | www.sabre.org To my friend, colleague, and manager of many years, who fosters a great working environment, inspires me with his creativity and hard work, and provides top- notch technical assistance and advice. To Mac developers, who will bring Quartz alive in innovative ways. Contents Foreward xv Preface xix Our Objective xix Outline xx Conventions and Assumptions xxii Source Code xxiii Header Files xxiv Quartz Technologies xxv See Also xxvi Acknowledgments xxviii Chapter 1 Introducing Quartz 2D 1 A Bit of History I 1 Quartz 2D Overview I 8 What Software Can Use Quartz 2D? I 10 Summary I 12 See Also I 12 Chapter 2 Quartz 2D Drawing Basics 15 Quartz Graphics Contexts I 15 Filling a Rectangle I 16 Stroking a Rectangle I 18 The Order of Fill and Stroke Operations I 20 Transforming the Coordinate System I 23 Constructing Quartz Paths 25 Painting with Alpha I 30 Making Dashed Lines I 32 Clipping a Drawing I 36 Drawing PDF Content I 38 More About Graphics Contexts I 41 Summary I 42 See Also I 43 vii viii Contents Chapter 3 Using Quartz 2D in Cocoa 45 Xcode Overview I 46 Creating a Cocoa Xcode Project in Tiger I 46 Creating a View in Interface Builder I 49 Connecting the Interface to the Code I 53 Obtaining a Graphics Context in Cocoa I 55 Writing the Drawing Code I 56 Examining the Drawing Output I 58 Cocoa Framework Drawing and Quartz I 59 Summary I 62 See Also I 62 Chapter 4 Using Quartz 2D in Carbon 65 Creating a Carbon Xcode Project I 66 Setting Up a Carbon Window I 68 Creating an Event Handler I 73 Examining the Drawing Output I 76 Using QDBeginCGContext I 79 Summary I 81 See Also I 82 Chapter 5 The Quartz Coordinate System and Coordinate Transformations 83 User Space and Device Space I 83 Coordinate Transformations I 86 The Current Transformation Matrix I 87 The Mathematics of Affine Transforms I 88 Saving and Restoring a Coordinate System I 91 Affine Transform Convenience Functions I 94 Creating a Skewed Coordinate System I 98 Summary I 100 See Also I 101 Chapter 6 Drawing with Paths 103 Properties of Paths I 104 Path Construction Primitives I 105 Cubic Bézier Curves 106 Contents ix Quadratic Bézier Curves 109 Closing Subpaths 110 Path Construction Convenience Functions I 111 Additional Path Convenience Functions (Tiger) 116 Stroking Paths I 119 Line Width 120 Line Joins 121 Line Caps 123 Line Dash 125 Filling Paths I 126 Clipping with Paths I 129 CGPath Objects (Jaguar) I 131 Anti-aliasing I 134 Path Utility Functions I 137 Aligning User Space Coordinates on Pixel Boundaries (Tiger) 139 Summary I 144 See Also I 144 Chapter 7 Color, Alpha Transparency, and the Quartz Graphics State 147 Color and Color Spaces I 148 A General Approach to Setting Color 150 CGColor Objects (Panther) 152 Calibrated Color Spaces 155 Device Color Spaces 160 Special Color Spaces 161 Creating Color Spaces by Name (Jaguar) 164 Rendering Intents 165 Alpha Transparency I 166 Blend Modes (Tiger) 170 Graphics State Parameters I 173 Summary I 181 See Also I 182 Chapter 8 Data Providers and Data Consumers 185 Data Providers I 186 CGDataProviderCreateWithURL 187 CGDataProviderCreateWithData 188 CGDataProviderCreate 190 CGDataProviderCreateDirectAccess 194 x Contents CGDataProviderCreateWithCFData (Tiger) 196 Guidelines for Using Data Providers 198 Data Consumers I 198 Summary I 202 See Also I 202 Chapter 9 Drawing Images 203 Creating CGImage Objects I 204 Specialized Functions for JPEG and PNG 204 Drawing Images into a Flipped Coordinate System 210 A General Function for Uncompressed Data 211 Alpha Information 212 Pixel Formats 214 Decode Array 215 Interpolation 217 Drawing Uncompressed, Raw Image Data 219 Drawing a Synthetic Image from Data in Memory 222 Drawing a Synthetic Image by Accessing Data Directly 223 Bitmap Images and Universal Binaries (Tiger) 225 Generalized Functions for Compressed Image Data (Tiger) 226 Importing Image Data with QuickTime 238 Guidelines for Image Creation 240 Best Practices for Working with Images I 241 Image Utility Functions I 244 Getting Image Dimensions 244 Getting the Pixel Format 244 Creating an Image from a Bitmap Context 245 Working with Color Spaces 245 Creating Subimages 249 Writing Image Data Using CGImageDestination (Tiger) I 255 Exporting to JPEG Using a QuickTime Exporter I 258 Summary I 259 See Also I 260 Chapter 10 Image Masking 263 Creating an Image Mask I 264 Drawing and Inverting a 1-Bit Image Mask 266 Drawing an 8-Bit-Deep Mask 272 Masking an Image (Tiger) I 273 Masking an Image with an Image Mask 274 Masking an Image with an Image 277 Masking Guidelines 279 Contents xi Using Color as a Mask I (Tiger) 279 Clipping to a Mask (Tiger) I 282 Summary I 287 See Also I 287 Chapter 11
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages28 Page
-
File Size-