1. Graphics State
Graphics state operations control the rendering parameters that affect how graphics are drawn on the page. The graphics state includes color, line characteristics, transformations, clipping paths, and many other attributes.
2. Overview
The graphics state is a collection of parameters that control:
-
Color: Current color (gray, RGB, CMYK, HSB)
-
Line attributes: Width, cap style, join style, miter limit, dash pattern
-
Transformations: Current transformation matrix (CTM)
-
Clipping: Current clipping path
-
Font: Current font and text parameters
-
Device: Current output device
Each parameter has a current value that affects subsequent graphics operations.
4. Command Categories
4.1. State Save and Restore
| Command | Description |
|---|---|
Push copy of graphics state onto graphics state stack |
|
Restore graphics state from top of stack |
|
Restore to bottommost save level |
|
Create gstate object (Level 2) |
|
Set graphics state from gstate object (Level 2) |
|
Copy current state to gstate object (Level 2) |
4.2. Line Attributes
| Command | Description |
|---|---|
Set line width for stroking |
|
Set line cap style (butt, round, square) |
|
Set line join style (miter, round, bevel) |
|
Set miter limit for sharp corners |
|
Set dash pattern for lines |
|
Get current line width |
|
Get current line cap |
|
Get current line join |
|
Get current miter limit |
|
Get current dash pattern |
4.3. Color Operations
| Command | Description |
|---|---|
Set gray level (0=black, 1=white) |
|
Set RGB color |
|
Set CMYK color (Level 2) |
|
Set HSB color |
|
Get current gray value |
|
Get current RGB color |
|
Get current CMYK color (Level 2) |
|
Get current HSB color |
5. Common Patterns
6. Important Considerations
6.1. State Hierarchy
Graphics state changes affect all subsequent operations until:
-
Another state change occurs
-
grestorerestores previous state -
initgraphicsresets to defaults -
Page is complete (showpage)
7. Common Pitfalls
Color Space - Color operators may switch color space (e.g., setgray) → DeviceGray.
|
Dash Pattern Reset - Empty dash array [] resets to solid lines.
|
| Bracket Graphics with gsave/grestore - Always wrap state changes: |
gsave
% Temporary changes
grestore