- 1. strokepath
- 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. Interaction with Line Parameters
- 1.11. Best Practices
- 1.12. Comparison with stroke
- 1.13. Performance Considerations
- 1.14. Advanced Techniques
- 1.15. See Also
1. strokepath
Converts the stroke of the current path to an outline path.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
No operands required |
| Level | Object |
|---|---|
(empty) |
No results (current path is modified) |
1.3. Description
strokepath replaces the current path with one enclosing the shape that would result if the stroke operator were applied to the current path. The path resulting from strokepath is suitable as the implicit operand to fill, clip, or pathbbox.
In general, this path is not suitable for stroke, as it may contain interior segments or disconnected subpaths produced by strokepath's stroke-to-outline conversion process.
strokepath uses the current line width, line cap, line join, miter limit, and dash pattern to determine the outline. Unlike stroke, strokepath does not consume the path—it modifies it in place.
1.5. Examples
newpath
100 100 moveto
200 200 lineto
10 setlinewidth
strokepath % Convert to outline
% Now can fill instead of stroke
fill
/Helvetica-Bold findfont 72 scalefont setfont
newpath
100 100 moveto
(OUTLINE) true charpath
2 setlinewidth
strokepath
% Fill with gradient or pattern
0.5 setgray
fill
newpath
50 150 moveto
250 150 lineto
% First, wide stroke
10 setlinewidth
gsave
strokepath
0.8 setgray
fill
grestore
% Then, narrow stroke
2 setlinewidth
0 setgray
stroke
1.6. Common Use Cases
1.6.1. Creating Offset Paths
/offsetPath {
% width offsetPath - creates offset outline
setlinewidth
strokepath
} def
newpath
100 100 moveto
200 100 lineto
200 200 lineto
5 offsetPath % 5-unit offset
fill
1.7. Common Pitfalls
| Result Not Suitable for Stroking - The outline path may contain interior segments and disconnected subpaths. |
newpath
100 100 moveto
200 200 lineto
10 setlinewidth
strokepath
% Don't do this - unpredictable results
stroke % May show interior segments
% Instead, use fill
fill % Correct usage
Path Not Consumed - Unlike stroke, strokepath modifies the path in place.
|
newpath
100 100 moveto
200 200 lineto
strokepath
% Path still exists (but modified)
% Must explicitly clear if needed
newpath
| Affected by Line Parameters - All current line parameters affect the result. |
newpath
100 100 moveto
200 200 lineto
% These all affect strokepath result:
5 setlinewidth
1 setlinecap
1 setlinejoin
[5 3] 0 setdash
strokepath % Outline includes all effects
Use for Path Inspection - strokepath makes the stroke boundary explicit:
|
newpath
100 100 moveto
200 100 lineto
5 setlinewidth
strokepath
% Now can use pathbbox to get stroke bounds
pathbbox % Returns bounding box of stroked path
1.9. Implementation Notes
-
The algorithm creates outlines for each path segment
-
Line caps create closed paths at endpoints
-
Line joins create appropriate corner fills
-
Dash patterns create separate path segments
-
Very complex paths may exceed limits
-
The resulting path may be quite complex
1.10. Interaction with Line Parameters
-
Determines the offset distance from original path
-
Wider lines create larger outlines
-
Butt cap (0): Square ends at path endpoints
-
Round cap (1): Semicircular extensions
-
Square cap (2): Square extensions
-
Miter join (0): Sharp corners (subject to miter limit)
-
Round join (1): Rounded corners
-
Bevel join (2): Beveled corners
-
Creates separate outline segments for each dash
-
Gaps in dash pattern become gaps in outline
-
More complex resulting path
-
Controls when miters convert to bevels
-
Only relevant for miter joins
1.11. Best Practices
1.11.1. Save Graphics State for Parameters
gsave
10 setlinewidth
1 setlinecap
1 setlinejoin
newpath
100 100 moveto
200 200 lineto
strokepath
fill
grestore
1.12. Comparison with stroke
-
Paints the stroke directly to page
-
Consumes the path
-
Cannot be further manipulated
-
Faster for simple rendering
-
Converts stroke to outline path
-
Path remains (but modified)
-
Can be filled, clipped, or analyzed
-
Allows advanced effects
-
Slightly slower
1.13. Performance Considerations
-
More complex than simple
stroke -
Dash patterns significantly increase complexity
-
Round caps/joins create more path segments than butt/miter
-
Very wide lines create large outlines
-
Use sparingly for best performance
1.14. Advanced Techniques
1.15. See Also
-
stroke- Paint stroke directly -
fill- Fill path interior -
clip- Use path for clipping -
ustrokepath- Stroke path for user path (Level 2) -
pathbbox- Get path bounding box -
flattenpath- Convert curves to lines -
setlinewidth- Set line width -
setlinecap- Set line cap style -
setlinejoin- Set line join style -
setmiterlimit- Set miter limit -
setdash- Set dash pattern