When you fill the current path, Quartz acts as if each subpath contained in the path were closed. It then uses these closed subpaths and calculates the pixels to fill. There are two ways Quartz can calculate the fill area. Simple paths such as ovals and rectangles have a well-defined area. But if your path is composed of overlapping segments or if the path includes multiple subpaths, such as the concentric circles shown in Figure 3-12, there are two rules you can use to determine the fill area.
The default fill rule is called the nonzero winding number rule. To determine whether a specific point should be painted, start at the point and draw a line beyond the bounds of the drawing. Starting with a count of 0, add 1 to the count every time a path segment crosses the line from left to right, and subtract 1 every time a path segment crosses the line from right to left. If the result is 0, the point is not painted. Otherwise, the point is painted. The direction that the path segments are drawn affects the outcome.Figure 3-12 shows two sets of inner and outer circles that are filled using the nonzero winding number rule. When each circle is drawn in the same direction, both circles are filled. When the circles are drawn in opposite directions, the inner circle is not filled.
You can opt to use the even-odd rule. To determine whether a specific point should be painted, start at the point and draw a line beyond the bounds of the drawing. Count the number of path segments that the line crosses. If the result is odd, the point is painted. If the result is even, the point is not painted. The direction that the path segments are drawn doesn’t affect the outcome. As you can see in Figure 3-12, it doesn’t matter which direction each circle is drawn, the fill will always be as shown.
Figure
3-12 Concentric circles filled using different fill rules
Quartz provides the functions shown in Table 3-5 for filling the current path. Some are convenience functions for stroking rectangles or ellipses.
Function |
Description |
---|---|
|
Fills the current path using the even-odd rule. |
|
Fills the current path using the nonzero winding number rule. |
|
Fills the area that fits inside the specified rectangle. |
|
Fills the areas that fits inside the specified rectangles. |
|
Fills an ellipse that fits inside the specified rectangle. |
|
Fills the current path if you
pass |
nonzero winding number rule
非零就画原则 路径从左向右就+1,从右向左-1,如果结果非零就画,反之不画
even-odd rule(奇偶规则)
路径被穿过的次数,总计次数为奇数就画,偶数就不画
Filling a Path 模式,布布扣,bubuko.com
原文:http://www.cnblogs.com/sanjianghuiliu/p/3665293.html