Filling a Path

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.

Table 3-5  Functions that fill paths

Function

Description

CGContextEOFillPath

Fills the current path using the even-odd rule.

CGContextFillPath

Fills the current path using the nonzero winding number rule.

CGContextFillRect

Fills the area that fits inside the specified rectangle.

CGContextFillRects

Fills the areas that fits inside the specified rectangles.

CGContextFillEllipseInRect

Fills an ellipse that fits inside the specified rectangle.

CGContextDrawPath

Fills the current path if you pass kCGPathFill (nonzero winding number rule) or kCGPathEOFill (even-odd rule). Fills and strokes the current path if you pass kCGPathFillStroke orkCGPathEOFillStroke.

nonzero winding number rule

非零就画原则  路径从左向右就+1,从右向左-1,如果结果非零就画,反之不画

even-odd rule(奇偶规则)

路径被穿过的次数,总计次数为奇数就画,偶数就不画

Filling a Path 模式的更多相关文章

  1. SQl 2005 For XMl 简单查询(Raw,Auto,Path模式)(1)

    很多人对Xpath可能比较熟悉,但不知道有没有直接操作过数据库,我们都知道 在Sql2005里公支持的几种查询有Raw,Auto模式,页并没有Path和Elements用法等,如果在2000里使用过 ...

  2. Yii 2 修改 URL 模式为 PATH 模式,并隐藏index.php

    在弄yii的url重写,希望能把url改成更好记的形式,同时去掉index.php的部分.转化前后的对比:修改前: http://localhost/index.php?r=site/page?vie ...

  3. SQL SERVER中XML查询:FOR XML指定PATH

    SQL SERVER中XML查询:FOR XML指定PATH 前言 在SQL SERVER中,XML查询能够指定RAW,AUTO,EXPLICIT,PATH.本文用一些实例介绍SQL SERVER中指 ...

  4. SQL Server FOR XML PATH 语句的应用---列转行

    经常在论坛看到高手使用了 for xml path,由于是搜索一下,记录了详细的使用方法.在SQL Server中利用 FOR XML PATH 语句能够把查询的数据生成XML数据,下面是它的一些应用 ...

  5. Path Creation and Path Painting

    [Path Creation and Path Painting] Path creation and path painting are separate tasks. First you crea ...

  6. SqlServer——for xml path

    for xml path 就是将 sql 查询出来的内容以XML的格式显示出来.参考网站MSDN:将 PATH 模式与 FOR XML 一起使用. 先创建测试用的表格: create table SZ ...

  7. Paths_Quartz2D

    Paths中的几个重要元素 Points void CGContextMoveToPoint (    CGContextRef c,    CGFloat x,    CGFloat y ); 指定 ...

  8. Paths(转载)

    Paths中的几个重要元素 Points void CGContextMoveToPoint ( CGContextRef c, CGFloat x, CGFloat y ); 指定一个点成为curr ...

  9. IOS-Quartz2D(Paths元素)

    Paths中的几个重要元素 Points void CGContextMoveToPoint (    CGContextRef c,    CGFloat x,    CGFloat y ); 指定 ...

随机推荐

  1. poj 3635(bfs+优先队列)

    题目链接:http://poj.org/problem?id=3635 思路:本题主要运用的还是贪心思想,由于要求st->ed的最小花费,那么每经过一个城市,能不加油就尽量不加油,用dp[i][ ...

  2. http://blog.sina.com.cn/s/blog_5b9b4abe01017638.html

    http://blog.sina.com.cn/s/blog_5b9b4abe01017638.html

  3. SSH开发实践part1:Spring与Hibernate整合

    1 之前把SSH看完了,现在从头开始进行项目实践.现在讲整个过程中的点滴记录下来,希望对后来者有参考. 2 SSH是一个轻量级的java开发框架,struts负责MVC开发模式中的controller ...

  4. 基于Mongodb的轻量级领域驱动框架(序)

    混园子也有些年头了,从各个大牛那儿学了很多东西.技术这东西和中国的料理一样,其中技巧和经验,代代相传(这不是舌尖上的中国广告).转身回头一望,几年来自己也积累了一些东西,五花八门涉猎到各种方向,今日开 ...

  5. GDB下查看内存命令(x命令)

    http://blog.csdn.net/allenlinrui/article/details/5964046 可以使用examine命令(简写是x)来查看内存地址中的值.x命令的语法如下所示: x ...

  6. 怎么样能让自己的虚拟机上网win7 for linux

    我的电脑是win7 32位 虚拟机是linux 我是通过无线连接互联网的 点无线网络连接 右键 点共享 按照我的方式设置 接下来进入 里面会自动的选择这个 如果没有可以自己按照这个设置 接下来进入虚拟 ...

  7. 在CentOS 7上给一个网卡分配多个IP地址

    有时你也许想要给一个网卡多个地址.你该怎么做呢?另外买一个网卡来分配地址?在小型网络中其实不用这么做.我们现在可以在CentOS/RHEL 7中给一个网卡分配多个ip地址.想知道怎么做么?好的,跟随我 ...

  8. Java Map各遍历方式的性能比较

    1. 阐述 对于Java中Map的遍历方式,很多文章都推荐使用entrySet,认为其比keySet的效率高很多.理由是:entrySet方法一次拿到所有key和value的集合:而keySet拿到的 ...

  9. wamp集成环境开启虚拟主机多站点功能

    方法/步骤   如果不是全白色,说明没有正常启动,先解决这个情况再进行下一步操作. 我们一键安装wamp到D盘,并可以正常启动,状态如下图所示:   在D:\wamp\bin\apache\Apach ...

  10. SPOJ 370 Ones and zeros BFS + 同余剪枝

    题意:给一些n,求出最小的只包含0,1的n的倍数 设两数a, b满足: a < b 并且a % n = b % n. 如果 ( a * 10^x + c ) % n = z , 根据同余定理,( ...