- 1. ufill
- 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. User Path Format
- 1.11. Comparison with Traditional Fill
- 1.12. Best Practices
- 1.13. Performance Considerations
- 1.14. See Also
1. ufill
Interprets a user path definition and fills the resulting path.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
(empty) |
No results |
1.3. Description
ufill interprets a user path definition and fills the resulting path as if by fill. The entire operation is effectively enclosed by gsave and grestore, so ufill has no lasting effect on the graphics state.
ufill is equivalent to:
gsave newpath uappend fill grestore
The userpath operand can be:
-
An ordinary array or packed array (length ≥ 5) containing path construction operators
-
An encoded user path string for efficient representation
User paths must begin with setbbox (optionally preceded by ucache) to define the bounding box.
1.5. Examples
[
50 50 250 250 setbbox
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
] ufill
[
ucache
50 50 250 250 setbbox
150 150 moveto
250 150 lineto
250 250 lineto
150 250 lineto
closepath
] ufill
[
100 100 300 300 setbbox
200 200 50 0 360 arc
closepath
] ufill
1.6. Common Use Cases
1.6.1. Efficient Repeated Fills
% Define reusable user path
/squarePath [
ucache % Enable caching
0 0 100 100 setbbox
10 10 moveto
90 10 lineto
90 90 lineto
10 90 lineto
closepath
] def
% Use multiple times efficiently
0.3 setgray
squarePath ufill
100 100 translate
0.6 setgray
squarePath ufill
1.7. Common Pitfalls
Must Include setbbox - User paths must begin with setbbox (optionally preceded by ucache).
|
% Wrong - no setbbox
[
100 100 moveto
200 200 lineto
] ufill % Error: rangecheck
% Correct
[
50 50 250 250 setbbox
100 100 moveto
200 200 lineto
] ufill
Graphics State Not Modified - ufill automatically saves and restores the graphics state.
|
0.5 setgray
[
0 0 100 100 setbbox
10 10 moveto
90 90 lineto
] ufill
% Gray is still 0.5, path is empty
Use ucache for Repeated Paths - Include ucache as the first element for paths that will be reused:
|
/myPath [
ucache % Cache this path
0 0 100 100 setbbox
% ... path construction ...
] def
% Efficient reuse
myPath ufill
myPath ufill % Uses cached version
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) |
[ |
No operand on stack |
[ |
Operand is not a valid user path |
1.9. Implementation Notes
-
User paths provide more efficient path construction than traditional operators
-
Cached user paths (with
ucache) are stored for reuse -
The bounding box enables optimization of path rendering
-
Coordinates are validated against the bounding box
-
User paths can be encoded as strings for maximum efficiency
1.10. User Path Format
A user path must be an array (or packed array) containing:
-
Optionally,
ucacheas the first element -
setbboxwith four coordinates (required) -
Path construction operators:
moveto,lineto,curveto,arc,arcn,arct,closepath, etc.
[
ucache % Optional
llx lly urx ury setbbox % Required
% Path operators...
x y moveto
x2 y2 lineto
closepath
]
1.11. Comparison with Traditional Fill
gsave
newpath
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
fill
grestore
ufill)[
50 50 250 250 setbbox
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
] ufill
Benefits of user paths:
-
More compact representation
-
Can be cached for efficiency
-
Automatic graphics state management
-
Potential for optimization by interpreter
1.12. Best Practices
1.12.1. Always Include Accurate Bounding Box
% Calculate tight bounding box
/llx 100 def
/lly 100 def
/urx 200 def
/ury 200 def
[
llx lly urx ury setbbox
% Use same coordinates in path
llx lly moveto
urx lly lineto
urx ury lineto
llx ury lineto
closepath
] ufill
1.13. Performance Considerations
-
User paths are generally faster than traditional path construction
-
Cached user paths (
ucache) provide significant performance benefits for reuse -
Encoded user paths (strings) are most efficient but harder to construct
-
Accurate bounding boxes enable better optimization
-
Very complex user paths may still exceed limits