Graphics Contexts

Graphics contexts are a fundamental part of the drawing infrastructure in Cocoa applications. As the name suggests, a graphics context provides the context for subsequent drawing operations. It identifies the current drawing destination (screen, printer, file, and so on), the coordinate system and boundaries for the underlying canvas, and any graphics attributes associated with the destination.

Graphics Context是一个drawing系统中很重要的概念,context就是上下文了,可是猛一看,我又对drawing不熟,context都包含什么呢?drawing的目标,屏幕、打印机、文件、PDF等都是,坐标系统,底层Canvas的边界以及跟drawing 目标相关的任何属性。

在Cocoa应用中,NSGraphicsContext几乎可以表示所有的drawing destination(除了OpenGL需要用NSOpenGLContext外)。

The primary job of any graphics context object is to maintain information about the current state of the drawing environment. In Quartz, the graphics context object is associated with a window, bitmap, PDF file, or other output device and maintains information for that device. The same is true for a Cocoa graphics context, but because Cocoa drawing is view-based, some additional changes are made to the drawing environment before your view’s drawRect: method is called.

The current state of the drawing environment information ranges from the global rendering settings to the attributes used to render the current path and is the same state information saved by Quartz.当调用saveGraphicsState时就是把下面的信息做了一个Copy。

Table 2-1  Graphics state information

Attribute

Description

Current transformation matrix (CTM)

Maps points in the view’s coordinate system to points in the destination device's coordinate system. Cocoa modifies the CTM before calling your view’sdrawRect: method. You can use an NSAffineTransform object to modify the CTM further to change the drawing origin, scale the canvas, or rotate the coordinate system. For more information, see “Coordinate Systems and Transforms.”

Clipping area

Specifies the area of the canvas that can be painted by drawing calls. Cocoa modifies the clipping region to the visible area of your view before calling itsdrawRect: method. You can use an NSBezierPath object to further clip the visible area. For more information, see “Setting the Clipping Region.”

Line width

Specifies the width of paths. The default line width is 1.0 but you can modify this value using an NSBezierPath object. For more information, see “Line Width.”

Line join style

Specifies how two connected lines are joined together. The default join style is NSMiterLineJoinStyle but you can modify this value using anNSBezierPath object. For more information, see “Line Join Styles.”

Line cap style

Specifies the appearance of an open end point on a path. The default line cap style is NSButtLineCapStyle but you can modify this value using anNSBezierPath object. For more information, see “Line Cap Styles.”

Line dash style

Defines a broken pattern for lines, including the initial phase for the style. There is no default dash style, resulting in solid lines. You modify dash styles for a path using an NSBezierPath object. For more information, see “Setting Path Attributes.”

Line miter limit

Determines when lines should be joined with a bevel instead of a miter. Applies only when the line join style is set to NSMiterLineJoinStyle. The length of the miter is divided by the line width. If the resulting value is greater than the miter limit, a bevel is used. The default value is 10.0 but you can modify this value using an NSBezierPath object. For more information, see “Miter Limits.”

Flatness value

Specifies the accuracy with which curves are rendered. (It is also the maximum error tolerance, measured in pixels.) Smaller numbers result in smoother curves at the expense of more calculations. The interpretation of this value may vary slightly on different rendering devices. The default value is 0.6 but you can modify this value using an NSBezierPath object. For more information, see “Line Flatness.”

Stroke color

Specifies the color used for rendering paths. This color applies only to the path line itself, not the area the path encompasses. You can specify colors using any of the system-supported color spaces. This value includes alpha information. Color information is managed by the NSColor class. For more information, see “Setting Colors and Patterns.”

Fill color

Specifies the color used to fill the area enclosed by a path. You can specify colors using any of the system-supported color spaces. This value includes alpha information. Color information is managed by the NSColor class. For more information, see “Setting Colors and Patterns.”

Shadow

Specifies the shadow attributes to apply to rendered content. You set shadows using the NSShadow class. For more information, see “Adding Shadows to Drawn Paths.”

Rendering intent

Specifies the technique used to map in-gamut colors to the gamut of the current color space. Cocoa does not support setting this attribute directly. Instead, you must use Quartz. For more information, see “Mapping Physical Colors to a Color Space.”

Font name

Specifies the font to use when drawing text. You modify font information using the NSFont class. For more information on drawing text, see “Text Attributes.”

Font size

Specifies the font size to use when drawing text. You modify font information using the NSFont class. For more information on drawing text, see “Text Attributes.”

Font character spacing

Specifies the character spacing to use when drawing text. (This attribute is supported only indirectly by Cocoa.) For more information on drawing text, see“Text Attributes.”

Text drawing mode

Specifies how to render the text. (This attribute is supported only indirectly by Cocoa.) For more information on drawing text, see “Text Attributes.”

Imageinterpolation quality

Specifies the process used to interpolate images during rendering. You use the NSGraphicsContext class to change this setting. For more information, see “Image Size and Resolution”

Compositing operation

Specifies the process used to composite source and destination material together. (The compositing operations supported by Cocoa are related to the Quartz blend modes but differ in their usage and behavior.) You use the NSGraphicsContext class to set the default value for this setting. Some rendering methods and functions may let you specify a different option. For more information, see “Setting Compositing Options.”

Global alpha

Specifies a global alpha (transparency) value to apply in addition to the alpha value for a given color. Cocoa does not support this attribute directly. If you want to set it, you must use the CGContextSetAlpha function in Quartz.

Anti-aliasing setting

Specifies whether paths use aliasing to smooth lines as they cross pixel boundaries. You use the NSGraphicsContext class to change this setting. For more information, see “Setting the Anti-aliasing Options.”

关于线程和Graphic Context

在Cocoa应用中,每个线程都有一个关联于某个Window的Graphic Context。可以使用[NSGraphicsContext currentContext]获得。它与哪个window关联呢?

Reference:

1. https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40003290-CH201-SW1

Cocoa Drawing的更多相关文章

  1. Cocoa Drawing Guide学习part1——基础和图形上下文 (转)

    原文:http://noark9.github.io/2013/12/28/cocoa-drawing-guide-study-part-1/ 简介 cocoa drawing由AppKit提供并且也 ...

  2. 10个迷惑新手的Cocoa&Objective-c开发问题

    本文转载至  http://blog.csdn.net/lvxiangan/article/details/27964733     language background run­time thre ...

  3. iOS多线程编程指南(一)关于多线程编程(转)

    原文:http://www.dreamingwish.com/article/ios-multi-threaded-programming-a-multi-threaded-programming.h ...

  4. IOS多线程编程:概述

    什么是多线程 多线程是一个比较轻量级的方法来实现单个应用程序内多个代码执行路径.从技术角度来看,一个线程就是一个需要管理执行代码的内核级和应用级数据结构组合.内核级结构协助调度线程事件,并抢占式调度一 ...

  5. IOS开发 Application Kit框架的线程安全

    以下部分介绍了Application Kit框架的线程安全. 非线程安全类 以下这些类和函数通常是非线程安全的.大部分情况下,你可以在任何线程使用这些类,只要你在同一时间只有一个线程使用它们.查看这些 ...

  6. iOS多线程编程指南

    iOS多线程编程指南(拓展篇)(1) 一.Cocoa 在Cocoa上面使用多线程的指南包括以下这些: (1)不可改变的对象一般是线程安全的.一旦你创建了它们,你可以把这些对象在线程间安全的传递.另一方 ...

  7. Mac Technology Overview

    [Mac Technology Overview]https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual ...

  8. Framework、Cocoa、Xcode

    什么是Cocoa? NeXTSTEP(以Unix作为内核的操作系统)内置的许多库(libraries)和工具,让程序员以一种优雅的方式与窗口管理器进行交互,这些libraries叫做Framework ...

  9. .Net Core上用于代替System.Drawing的类库

    目前.Net Core上没有System.Drawing这个类库,想要在.Net Core上处理图片得另辟蹊径. 微软给出了将来取代System.Drawing的方案,偏向于使用一个单独的服务端进行各 ...

随机推荐

  1. 第三章 Python容器:列表、元组、字典与集合

      数据结构的分类依据?基本的"数组"在python中是列表, 数据结构的作用?容器,盛放数据,是由原子组成的分子.可以将一群数据进行整合.拆分.重排. 3.2 列表 列表是啥?顺 ...

  2. IE6 IE7 hasLayout bug之li间的3px垂直间距

    1. li中仅包含a,span等内联(行内)元素2.触发条件: li元素的layout被触发(通常为设置了宽或高,设置overflow:hidden在IE7下同样触发layout),且a或span元素 ...

  3. robotframework笔记21

    创建输出 当执行测试,创建多个输出文件和所有的 都以某种方式相关测试结果. 本节讨论什么 输出创建.如何配置创建,以及如何 调整他们的内容. 不同的输出文件 本节解释了不同可以创建和输出文件 如何配置 ...

  4. CentOS 6.x安装配置

    简述 VMware可以创建多个虚拟机,每个虚拟机上都可以安装各种类型的操作系统.安装方法也有很多种.下面,主要以ISO镜像安装为例,介绍CentOS 6.x的安装过程及相关的参数设置. 简述 创建虚拟 ...

  5. MySQL学习笔记_2_MySQL创建数据表(上)

    MySQL创建数据表(上) 一.创建数据表的SQL语句模型[弱类型] CREATETABLE [IF NOT EXISTS] 表名称( 字段名1列的类型[属性][索引], 字段名2 列的类型[属性][ ...

  6. lambda表達式

    lambda简介 lambda运算符:所有的lambda表达式都是用新的lambda运算符 " => ",可以叫他,“转到”或者 “成为”.运算符将表达式分为两部分,左边指定 ...

  7. SQL的常用语句

    select * from g_members where id between '16' and '31' order by id desc 倒序排列 select * from g_members ...

  8. SQL语句技巧(上个样式太差了)

      以下并非本人整理,但是看后感觉相当不错,特此分享. 1.应用程序中,保证在实现功能的基础上,尽量减少对数据库的访问次数:通过搜索参数,尽量减少对表的访问行数,最小化结果集,从而减轻网络负担:能够分 ...

  9. PHP函数——is_subclass_of() 函数 判断一个对象是否为一个类的子类

    说明: bool is_subclass_of ( object $object , string $class_name ) 如果对象 object所属类是类 class_name的子类,则返回 T ...

  10. / etc / init.d / iptables: line 268: restorecon: command not found

    When I tried to restart iptables from vps , I got the following error. Iptables encountered such a p ...