O'Reilly logo

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

Quartz 2D Graphics for Mac OS X® Developers

Book Description

A Hands-On Guide and Introduction to Quartz 2D

On Mac OS X, Macintosh developers depend on the graphics and imaging frameworks of the Core Graphics system to implement multimedia features in their applications. With Core Graphics Apple has answered the increasing demands of graphics developers with a powerful collection of tools, including Quartz 2D and Core Image. Quartz 2D is a modern drawing API with a powerful imaging model. Beginning with Mac OS X 10.4, Tiger, Quartz 2D replaces the QuickDraw® graphics library in legacy applications and provides the functionality developers need to take advantage of the latest hardware.

Quartz 2D Graphics for Mac OS X® Developers is a hands-on guide and introduction to Quartz 2D. Differences between the interfaces and features of QuickDraw and Quartz 2D are making the switch challenging for developers. Through in-depth practical coverage, Mac developer and consultant Scott Thompson leads you smoothly through the transition and sets you on the path to developing cutting edge graphics in Core Image.

Through this invaluable guide, you will learn how to

  • Forge connections between Quartz 2D and graphics devices using CGContexts

  • Simplify the drawing process using transformations

  • Draw line art using path-drawing operations on Bezier paths

  • Use pixel data to create images

  • Import and export images from Quartz 2D with Image I/O and QuickTime

  • Generate text and implement special text effects

  • Draw in offscreen environments, such as CGLayers and offscreen bitmaps

  • Create shadings and patterns

  • Create PDFs from Quartz 2D drawings or import PDFs into your drawings

  • If you depend on QuickDraw for your graphics needs, or are interested in a system that pushes the envelope in computer graphics, now is the time to make the switch to Core Graphics (Quartz 2D, Core Image). This is the book that walks you through that change–step-by-step!

    The companion CD-ROM contains projects and source code covered in this book so you can run each sample. The samples demonstrate how to call Quartz 2D from both Carbon and Cocoa applications as well as from Mac OS X’s Python scripting interface.

    Table of Contents

    1. Copyright
      1. Dedication
    2. Preface
    3. 1. Getting Started
      1. About This Book
      2. Formatting Conventions
      3. Accessing Quartz 2D
        1. The Quartz 2D C API
        2. Naming Conventions
        3. Core Graphics Objects
        4. Other Object-Oriented Features
        5. Accessing Quartz 2D from Cocoa
        6. Alternative APIs
          1. The Python Interface
          2. The HTML Canvas Tag
      4. The Core Image API
    4. 2. From QuickDraw to Quartz 2D
      1. The Legacy of QuickDraw and the Rise of PDF
        1. PostScript and Desktop Publishing
        2. PostScript on the Screen
        3. PDF to Quartz 2D
      2. Graphics Programming in the Modern Age
        1. General Purpose Vector Processors for Graphics
        2. The Emergence of the GPU
        3. The Programmable Graphics Card
        4. Managing Hardware Complexity
      3. Mac OS X Graphics Architecture
        1. Kernel and Hardware
        2. OpenGL
        3. Core Graphics
        4. Core Video
        5. Core Image
        6. QuickTime
      4. Other Graphics Libraries
        1. ATSUI and Cocoa Text
        2. QuickDraw
        3. vImage
        4. Java 2D
    5. 3. Introduction to Quartz 2D
      1. Features of Quartz 2D
        1. Device Independence
        2. Resolution Independence
        3. Rich Transformations
        4. Integrated Color Management
        5. Transparency and Antialiasing
        6. Rich Text Support
        7. Performance
      2. The Quartz 2D Drawing Model
        1. Drawing Primitives
        2. The Graphics Context
        3. Where Have the Pixels Gone?
        4. The Painter’s Model
        5. The Crayon Model
      3. A Simple Drawing Example
        1. Creating the CGContext
        2. The First Bit of Drawing
        3. Setting up the Coordinate System
        4. Drawing the Checkerboard
        5. Drawing the Heart
        6. Drawing the Text
        7. Writing a PNG File
    6. 4. The Graphics Context
      1. User Space and the Page
        1. User Space Coordinates
        2. Floating Point Geometry
      2. The Graphics State
        1. The Graphics State Stack
        2. The Current Transformation Matrix (CTM)
        3. Clipping Information
        4. Text Settings
        5. Line Art Settings
        6. Image Settings
        7. General Settings
        8. The Current Path
        9. Color Space Settings
      3. Other Context Functionality
        1. Transparency Layers
        2. Antialiasing and Font Smoothing
        3. Coordinate Transformations
        4. Synchronization and Flushing
      4. Obtaining CGContexts
        1. QuickDraw Ports
        2. HIView Contexts
        3. NSView Contexts
        4. PDF Contexts
        5. Printing Contexts
        6. Bitmap Contexts
    7. 5. Transformations
      1. The Basic Transformations
        1. Affine Transform
        2. Translations
        3. Rotations
        4. Scaling
        5. Inverse Transformations
        6. Concatenating Transformations
        7. The Order Matters
      2. Transformations in the Context
      3. Transformations Unleashed
        1. CGAffineTransforms
        2. NSAffineTransform
        3. Transforming a Path
      4. Drawing with Transformations
      5. Transformations as Matrices
        1. Homogeneous Coordinates
        2. Matrix Representations of Transforms
    8. 6. Line Art—Building Paths
      1. On Paths
        1. Components of a Path
        2. Bezier Curves
        3. Composite Curves
        4. Features of Bezier Curves
      2. Building Paths
        1. Building from Segments
          1. Move To
          2. Line To
          3. Curve To
          4. Quad Curve To
          5. Close Subpath
          6. API Differences
        2. Segment Construction Sample Code
        3. Constructing Common Shapes
          1. Lines
          2. Rectangles
          3. Ellipses (Ovals)
          4. Circular Arcs
        4. Adding Paths
        5. Additional CGContext Functionality
        6. Additional NSBezierPath Functionality
      3. Path Drawing Performance
        1. The Half-Pixel Line “Problem”
        2. Antialiasing in Complex Paths
        3. Drawing Many Lines and Rectangles
        4. NSFrameRect and Friends
    9. 7. Line Art—Drawing
      1. Drawing Basics
        1. Drawing with Quartz 2D
        2. Drawing with NSBezierPath
      2. Fills
        1. Winding Rules
        2. Filling Routines
      3. Strokes
        1. Line Width
        2. End Caps
        3. Line Joins
        4. The Miter Limit
        5. Line Dash
        6. Flatness
    10. 8. Image Basics
      1. What Is an Image?
        1. Image Masks
      2. Introducing CGImage
      3. Drawing CGImages
        1. Resolution Independence
        2. Interpolation Quality
        3. Clipping with an Image—Masking
      4. Creating CGImages
        1. Pixel Format Information
          1. Pixel Color Space
          2. Pixel Alpha Channels
          3. Pixel Format Information
          4. Valid Pixel Types
        2. Image Data Sources
        3. Scaling Pixel Data—The Decode Array
        4. Creating an Image from a Pixel Buffer
        5. Creating from a QuickDraw PixMap
        6. Creating from PNG and JPEG data
        7. Creating Image Masks
        8. Creating from Another Image
        9. Combining an Image and a Mask
      5. Image Performance Issues
        1. Pixel Data Is Immutable
        2. Reuse Your CGImageRefs
        3. Use Resampling and Image Interpolation Correctly
        4. Color Management Issues
        5. Compositing Takes Time
        6. Images and VRAM
        7. Keep It Simple, Then Test It
    11. 9. Importing and Exporting Images
      1. Using QuickTime
        1. Import Image Example
        2. Export Image Example
      2. Image I/O
        1. Import Image Example
        2. Export Image Example
    12. 10. Drawing with Core Image
      1. What Is Core Image?
      2. How Core Image Manipulates Images
      3. Using a Core Image Filter
      4. Combining Filters and Images
      5. Core Image Transitions
      6. Animation, Timers, and Updates
        1. About Timers
        2. Updating the Animation
        3. Animation Speed and Refresh Rates
      7. A Transition Example
    13. 11. Drawing Text with Quartz 2D
      1. The Text Processing Pipeline
        1. Storing Text
        2. Representing Text Visually
        3. ATSUI and Cocoa Text
      2. Drawing Text
        1. Text Matrix
        2. Text Position
        3. Current Font
        4. Text Drawing Modes
      3. Drawing Simple Strings
      4. Drawing with Glyphs
      5. A Drawing Sample
    14. 12. Drawing Offscreen
      1. Using a CGBitmapContext
        1. Creating an Offscreen Bitmap
      2. Working with CGLayers
        1. Using CGLayers
          1. Creating a CGLayer
          2. Drawing into a CGLayer
          3. Drawing the Layer’s Graphic Elsewhere
      3. A Layer Drawing Example
    15. 13. Shadings and Patterns
      1. Shadings
        1. Creating the Color Function
      2. Creating Shadings
        1. Axial Shadings
        2. Radial Shadings
        3. Drawing Shadings
      3. Patterns
        1. Cells, Spacing, and Transformations
        2. Colored and Stencil Patterns
      4. Creating Patterns
        1. The Pattern Cell Callback
        2. Putting It Together
      5. Drawing with Patterns
        1. Pattern Color Spaces
        2. Setting the Current Pattern
        3. Drawing Patterned Graphics
    16. 14. Working with PDF
      1. Drawing PDF Documents
        1. Creating a CGPDFDocument
        2. Retrieving Pages
        3. Drawing Pages
        4. A PDF Drawing Example
      2. Creating PDF Documents
        1. Creating PDF Contexts
        2. Adding Pages
        3. Drawing the PDF
        4. Release the Context
        5. An Example That Creates a PDF
      3. Adding Hyperlinks to PDFs
        1. Internal Links
        2. URL Hyperlinks