1. strokepath

Converts the stroke of the current path to an outline path.

1.1. Syntax

- strokepath → -

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

No operands required

Table 2. After
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.4. PostScript Level

Level 1 and later

1.5. Examples

Converting stroke to fillable path
newpath
100 100 moveto
200 200 lineto

10 setlinewidth
strokepath  % Convert to outline

% Now can fill instead of stroke
fill
Creating outlined text
/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
Double-stroke effect
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.6.2. Text Effects

/outlineText {
  % string outlineText
  /Helvetica-Bold findfont 60 scalefont setfont
  newpath
  100 150 moveto
  true charpath

  % Convert to outline
  3 setlinewidth
  strokepath

  % Fill outline
  fill
} def

(TEXT) outlineText

1.6.3. Complex Path Manipulation

% Create complex stroked shape for clipping
newpath
100 100 50 0 360 arc

10 setlinewidth
strokepath

% Use as clipping path
clip
newpath

% Draw clipped content
% ...

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.8. Error Conditions

Error Condition

[limitcheck]

Path becomes too complex for implementation

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

Line Width
  • Determines the offset distance from original path

  • Wider lines create larger outlines

Line Cap
  • Butt cap (0): Square ends at path endpoints

  • Round cap (1): Semicircular extensions

  • Square cap (2): Square extensions

Line Join
  • Miter join (0): Sharp corners (subject to miter limit)

  • Round join (1): Rounded corners

  • Bevel join (2): Beveled corners

Dash Pattern
  • Creates separate outline segments for each dash

  • Gaps in dash pattern become gaps in outline

  • More complex resulting path

Miter Limit
  • 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.11.2. Use for Advanced Effects

% Create "hollow" stroke
newpath
100 150 moveto
200 150 lineto

% Outer stroke
15 setlinewidth
gsave
  strokepath
  gsave
    fill
  grestore

  % Inner "knockout"
  5 setlinewidth
  strokepath
  1 setgray
  fill
grestore

1.11.3. Combine with Clipping

% Use stroked outline as clip
newpath
150 150 75 0 360 arc

10 setlinewidth
strokepath
clip
newpath

% Draw clipped graphics
% ...

1.12. Comparison with stroke

stroke operator
  • Paints the stroke directly to page

  • Consumes the path

  • Cannot be further manipulated

  • Faster for simple rendering

strokepath operator
  • 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.14.1. Creating Parallel Paths

/parallelPath {
  % offset parallelPath - creates parallel path
  2 mul setlinewidth
  strokepath
} def

newpath
100 100 moveto
200 100 lineto
200 200 lineto

5 parallelPath  % 5 units offset on each side

1.14.2. Variable Width Strokes

% Simulate variable width by combining paths
newpath
100 150 moveto
150 150 lineto

2 setlinewidth
strokepath

gsave fill grestore

150 150 moveto
200 150 lineto

10 setlinewidth
strokepath

fill

1.15. See Also


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.