- 1. ustrokepath
- 1.1. Syntax
- 1.2. Stack Effects
- 1.3. Description
- 1.4. PostScript Level
- 1.5. Examples
- 1.6. Common Use Cases
- 1.7. Common Pitfalls
- 1.8. Error Conditions
- 1.9. Implementation Notes
- 1.10. Graphics State Parameters
- 1.11. Comparison with Other Stroke Operators
- 1.12. Best Practices
- 1.13. Advanced Techniques
- 1.14. Performance Considerations
- 1.15. See Also
1. ustrokepath
Converts a user path stroke to an outline path.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
1 |
|
0 |
|
| Level | Object |
|---|---|
(empty) |
No results (current path is set to outline) |
1.3. Description
ustrokepath replaces the current path with one enclosing the shape that would result if the ustroke operator were applied to the same operands. The path resulting from ustrokepath is suitable as the implicit operand to a subsequent fill, clip, or pathbbox.
In general, this path is not suitable for stroke, as it may contain interior segments or disconnected subpaths produced by ustrokepath's stroke-to-outline conversion process.
In the first form, ustrokepath is equivalent to:
newpath uappend strokepath
In the second form, ustrokepath is equivalent to:
newpath
exch uappend % Interpret userpath
matrix currentmatrix % Save CTM
exch concat % Concat matrix to CTM
strokepath % Compute outline of stroke
setmatrix % Restore original CTM
The matrix parameter allows compensation for non-uniform scaling in the CTM, affecting line width and dash pattern but not the path coordinates.
1.5. Examples
5 setlinewidth
[
50 50 250 250 setbbox
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
] ustrokepath
% Now current path is the stroke outline
fill
/createOffset {
% userpath width createOffset
setlinewidth
ustrokepath
} def
[
0 0 200 200 setbbox
100 100 moveto
100 150 lineto
150 150 lineto
closepath
] 5 createOffset
0.7 setgray
fill
2 1 scale % Non-uniform scale
[
0 0 100 100 setbbox
50 50 moveto
90 50 lineto
]
[0.5 0 0 1 0 0] % Compensate for x scale
ustrokepath
fill % Uniform thickness outline
1.6. Common Use Cases
1.6.1. Creating Outlined Text Effects
/outlineText {
% string width outlineText
/w exch def
/s exch def
/Helvetica-Bold findfont 72 scalefont setfont
% Create text path as user path
/textPath [
newpath
100 100 moveto
s true charpath
pathbbox
setbbox
100 100 moveto
s true charpath
] cvx def
w setlinewidth
textPath ustrokepath
fill
} def
(OUTLINE) 3 outlineText
1.7. Common Pitfalls
| Result Not Suitable for Stroking - The outline path may contain interior segments and is meant for filling or clipping. |
[
0 0 100 100 setbbox
50 50 moveto
90 50 lineto
]
5 setlinewidth
ustrokepath
% Don't do this
stroke % Unpredictable results
% Do this instead
fill % Correct usage
Current Path Is Modified - Unlike ustroke, the current path is replaced with the outline.
|
[
0 0 100 100 setbbox
50 50 moveto
90 50 lineto
]
ustrokepath
% Current path is now the stroke outline
% Original user path is gone
| Matrix Affects Stroke, Not Path Coordinates - The optional matrix only affects stroke rendering parameters. |
[
0 0 100 100 setbbox
50 50 moveto
90 50 lineto
]
[2 0 0 2 0 0] % Does NOT scale path coordinates
ustrokepath % Only affects line width calculation
Use for Path Analysis - ustrokepath makes stroke boundaries explicit for analysis:
|
[
0 0 100 100 setbbox
50 50 moveto
90 50 lineto
]
5 setlinewidth
ustrokepath
% Get bounds of stroked path
pathbbox % Returns bbox of stroke outline
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
User path array is not executable or has insufficient access |
[ |
Path becomes too complex for implementation |
[ |
User path is malformed (missing setbbox, coordinates out of bounds, invalid matrix) |
[ |
Insufficient operands on stack |
[ |
Operand is not a valid user path or matrix |
1.9. Implementation Notes
-
Creates outline paths for each path segment in the user path
-
Line caps create closed paths at endpoints
-
Line joins create appropriate corner fills
-
Dash patterns create separate outline segments
-
Very complex paths may exceed implementation limits
-
The resulting path can be quite complex
1.10. Graphics State Parameters
ustrokepath uses these parameters to create the outline:
-
Line width - from
setlinewidth -
Line cap - from
setlinecap -
Line join - from
setlinejoin -
Miter limit - from
setmiterlimit -
Dash pattern - from
setdash -
Current transformation matrix (CTM)
The graphics state is not automatically saved/restored (unlike ustroke).
1.11. Comparison with Other Stroke Operators
-
Operates on current path
-
Modifies current path in place
-
No automatic state management
-
Traditional path format
-
Operates on user path
-
Automatic gsave/grestore
-
No lasting path changes
-
User path format
-
Operates on user path
-
Sets current path to outline
-
No automatic state management
-
User path format
-
Optional matrix parameter
1.12. Best Practices
1.12.1. Set Line Parameters Before Calling
% Set all stroke parameters first
5 setlinewidth
1 setlinecap
1 setlinejoin
[5 3] 0 setdash
% Then create outline
[
0 0 100 100 setbbox
50 50 moveto
90 50 lineto
] ustrokepath
% Fill or clip the outline
fill
1.12.2. Save State When Needed
gsave
10 setlinewidth
1 setlinecap
[
0 0 100 100 setbbox
50 50 moveto
90 50 lineto
] ustrokepath
0.8 setgray
fill
grestore
1.12.3. Use Matrix for CTM Compensation
% Save current matrix
matrix currentmatrix /origMatrix exch def
% Apply non-uniform scale
3 1 scale
% Create outline with compensation
/path [
0 0 100 50 setbbox
50 25 moveto
90 25 lineto
] def
% Inverse of the scale
[0.333 0 0 1 0 0]
path exch ustrokepath
fill
% Restore original matrix
origMatrix setmatrix
1.13. Advanced Techniques
1.14. Performance Considerations
-
More complex than simple
ustroke -
User path format provides some efficiency
-
Dash patterns significantly increase complexity
-
Round caps/joins create more segments
-
Very wide lines create larger outlines
-
Matrix parameter adds minimal overhead
1.15. See Also
-
ustroke- Stroke user path -
strokepath- Convert stroke to outline (traditional path) -
ufill- Fill user path -
fill- Fill path interior -
clip- Use path for clipping -
setbbox- Set bounding box -
ucache- Enable user path caching -
uappend- Append user path to current path -
pathbbox- Get path bounding box -
setlinewidth- Set line width -
setlinecap- Set line cap -
setlinejoin- Set line join -
setdash- Set dash pattern