1. eofill

Paints the area enclosed by the current path using the even-odd rule.

1.1. Syntax

- eofill → -

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

No operands required

Table 2. After
Level Object

(empty)

No results

1.3. Description

eofill paints the inside of the current path with the current color, using the even-odd rule to determine what points are inside. Except for the choice of insideness rule, the behavior of eofill is identical to that of fill.

The even-odd rule determines whether a point is inside a path by drawing a ray from that point in any direction and counting the number of path segments that the ray crosses. If this number is odd, the point is inside; if even, the point is outside. This rule is useful for creating shapes with holes.

Like fill, eofill implicitly closes any open subpaths before painting and performs a newpath after completion.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Simple even-odd fill
newpath
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath
eofill
Creating a shape with a hole (even-odd rule)
% Outer rectangle (counterclockwise)
newpath
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath

% Inner rectangle (same direction - creates hole)
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath

eofill  % Creates a frame (hole in center)
Star with even-odd fill
/drawStarEO {
  % x y radius drawStarEO
  /r exch def
  /y exch def
  /x exch def

  newpath
  % Five-pointed star with overlapping lines
  x y r add moveto
  0 1 4 {
    144 mul rotate
    x y r add lineto
  } for
  closepath
  eofill
} def

150 150 75 drawStarEO

1.6. Common Use Cases

1.6.1. Creating Frames and Holes

% Circle with hole in center
newpath
200 200 100 0 360 arc
closepath
200 200 50 0 360 arc
closepath
eofill  % Creates donut shape

1.6.2. Complex Self-Intersecting Shapes

% Figure-eight pattern
newpath
100 150 50 0 360 arc
closepath
200 150 50 0 360 arc
closepath
eofill  % Even-odd creates two separate filled circles

1.6.3. Typography Effects

% Letters with counters (holes)
/Helvetica-Bold findfont 120 scalefont setfont
newpath
100 100 moveto
(O) true charpath
eofill  % Counter (hole) in 'O' is preserved

1.7. Common Pitfalls

Different Results from fill - The even-odd rule produces different results than the non-zero winding number rule used by fill.
% Same path, different fill rules
newpath
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
150 150 moveto
180 150 lineto
180 180 lineto
150 180 lineto
closepath

gsave
  fill    % Non-zero: both rectangles filled
grestore
eofill    % Even-odd: inner rectangle is a hole
Path Direction Irrelevant - Unlike fill, the direction paths are drawn doesn’t matter with eofill.
% Clockwise vs counterclockwise doesn't matter
newpath
50 50 moveto
250 50 lineto
250 250 lineto
50 250 lineto
closepath

% Either direction creates same hole
100 100 moveto
200 200 lineto
200 100 lineto
100 200 lineto
closepath

eofill  % Same result regardless of direction
Use for Shapes with Holes - eofill is ideal for shapes with holes, regardless of path direction:
% Multiple concentric circles
newpath
200 200 100 0 360 arc closepath
200 200 75 0 360 arc closepath
200 200 50 0 360 arc closepath
200 200 25 0 360 arc closepath
eofill  % Creates ring pattern

1.8. Error Conditions

Error Condition

[limitcheck]

Path becomes too complex for implementation

1.9. Implementation Notes

  • The even-odd rule counts path crossings to determine inside/outside

  • Path direction does not affect the fill result

  • Multiple overlapping subpaths create alternating filled and unfilled regions

  • Very complex paths may exceed implementation limits

  • The algorithm is generally simpler than the non-zero winding number rule

1.10. Comparing Even-Odd vs Non-Zero Winding

Even-Odd Rule (eofill)
  • Counts crossings: odd = inside, even = outside

  • Path direction doesn’t matter

  • Simple to understand and predict

  • Natural for shapes with holes

  • Alternating fill pattern for overlapping paths

Non-Zero Winding Rule (fill)
  • Counts direction of crossings

  • Path direction matters

  • More complex but more flexible

  • Can create solid fills from complex paths

  • Direction-dependent results

1.11. Best Practices

1.11.1. Choose Appropriate Fill Rule

% For shapes with holes, use eofill
/drawFrame {
  newpath
  0 0 100 0 360 arc closepath
  0 0 75 0 360 arc closepath
  eofill
} def

% For solid complex shapes, use fill
/drawStar {
  newpath
  % ... star path construction ...
  fill
} def

1.11.2. Consistent Path Construction

% Good: clear construction
newpath
% Outer boundary
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
% Inner hole
125 125 moveto
175 125 lineto
175 175 lineto
125 175 lineto
closepath
eofill

1.11.3. Preserve Paths When Needed

newpath
200 200 100 0 360 arc closepath
200 200 50 0 360 arc closepath

gsave
  eofill  % Fill with even-odd
grestore

0.5 setlinewidth
stroke    % Then stroke the path

1.12. Performance Considerations

  • Even-odd rule calculation is generally faster than non-zero winding

  • Number of subpaths affects performance more than their complexity

  • Very large numbers of crossings may slow processing

  • Simple convex shapes fill fastest

1.13. See Also

  • fill - Fill using non-zero winding rule

  • eoclip - Clip using even-odd rule

  • ueofill - Even-odd fill user path (Level 2)

  • stroke - Paint path outline

  • newpath - Clear current path

  • closepath - Close current subpath


Back to top

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