In a drawing environment the graphics state defines the global framework within which graphics operations execute. A well-designed graphics state model helps to create a stable, consistent drawing environment and makes it easier to use a graphics API.
Quartz doesn’t maintain any global graphics state as QuickDraw does. Instead, the drawing state is maintained for each graphics context. Graphics contexts have attributes that are fixed at creation time, and parameters that you can modify while drawing. For example, in a bitmap context the pixel data is an attribute and the fill color is a parameter.
Every graphics context has a graphics state stack that you can use to save and restore snapshots of the current drawing state using the functions CGContextSaveGState and CGContextRestoreGState. There is no way in Quartz for you to get the current setting for a graphics state parameter. If you want that information, you need to track the settings yourself. Perhaps a better approach is to think in terms of bracketing your code with calls to save and restore the graphics state. Quartz provides “set” functions for changing each graphic state parameter. Graphics state parameters are discussed in detail in various chapters in Quartz 2D Programming Guide. Start with the Graphics State section in the overview chapter, which includes a cross reference to the chapter that’s appropriate for a particular graphics state parameter.
The graphic state parameters include the following:
Current transformation matrix (CTM)
Clipping area
Line characteristics: width, join, cap, dash, miter limit
Anti-aliasing setting
Color: fill and stroke setting
Global alpha value (transparency)
Rendering intent
Color space: fill and stroke settings
Text settings: font, font size, character spacing, text drawing mode
Blend mode
Last updated: 2006-09-05