Catalog / PostScript Cheatsheet
PostScript Cheatsheet
A quick reference guide to the PostScript page description language, covering fundamental concepts, operators, and syntax for generating graphics and text.
Core Concepts
Stack Operations
PostScript is a stack-based language. Most operators take their arguments from the stack and place their results back onto the stack.
|
Example:
|
Data Types
|
Whole numbers (e.g., |
|
Floating-point numbers (e.g., |
|
|
|
Sequence of characters enclosed in parentheses (e.g., |
|
Ordered collection of objects enclosed in square brackets (e.g., |
|
Collection of key-value pairs. |
Variables and Procedures
Example:
|
Graphics Operations
Path Construction
|
Starts a new path. |
|
Moves the current point to (x, y). Usage: |
|
Draws a line from the current point to (x, y). Usage: |
|
Draws a Bezier curve. Usage: |
|
Closes the current path by drawing a line to the starting point. |
Drawing and Filling
|
Draws a line along the current path. |
|
Fills the area enclosed by the current path. |
|
Fills the path using the even-odd rule. |
Color and Line Attributes
|
Example:
|
Text Operations
Font Handling
|
Loads a font. Usage: |
|
Scales the font. Usage: |
|
Sets the current font. Usage: |
Text Display
|
Displays a string at the current position. Usage: |
|
Calculates the width of a string. Returns width and height. Usage: |
|
Displays the current page and resets the graphics state. |
Text Positioning
Text positioning is done via Example:
|
Control Structures
Conditional Statements
|
Executes a code block if a condition is true. Usage: |
|
Executes one code block if a condition is true, and another if false. Usage: |
Looping
|
Executes a code block a specified number of times. Usage: |
|
Executes a code block indefinitely until explicitly stopped with |
|
Executes a code block for a range of values. Usage: |
Example
This example calculates and prints the square of numbers from 1 to 5. |