# NSGraphicsContext

richard@brainstorm.co.uk
fedor@gnu.org
Generated at 2026-02-17 21:02:56 +0000

GNUstep drawing context class.

1998,1999 Free Software Foundation, Inc.
NSGraphicsContext

This is an abstract class which provides a framework for a device independant drawing.

In addition, this class provides methods to perform the actual drawing. As a convenience, you can also access these through various function interfaces. One is a Display Postscript interface using PS and DPS operations. Another is a Quartz interface (not yet written).

AppKit/NSGraphicsContext.h
Description forthcoming.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Description forthcoming.
Description forthcoming.
Description forthcoming.
Description forthcoming.
Description forthcoming.
currentContext
Returns the current context. Also see the convienience function GSCurrentContext()
currentContextDrawingToScreen
Returns `YES` if the current context is a display context
graphicsContextWithAttributes:
attributes

Create a graphics context with attributes, which contains key/value pairs which describe the specifics of how the context is to be initialized.

graphicsContextWithBitmapImageRep:
bitmap
Description forthcoming.
graphicsContextWithCGContext:
ctx
flipped:
flipped
Description forthcoming.
graphicsContextWithGraphicsPort:
port
flipped:
flag
Description forthcoming.
graphicsContextWithWindow:
aWindow
Create graphics context with attributes speficied by aWindow's device description.
restoreGraphicsState
Description forthcoming.
saveGraphicsState
Description forthcoming.
setCurrentContext:
context
Set the current context that will handle drawing.
setGraphicsState:
graphicsState
Description forthcoming.
CGContext
Description forthcoming.
attributes
Description forthcoming.
compositingOperation
Description forthcoming.
flushGraphics
Description forthcoming.
focusStack
Description forthcoming.
graphicsPort
Description forthcoming.
imageInterpolation
Description forthcoming.
isDrawingToScreen
Description forthcoming.
isFlipped
Description forthcoming.
methods
Description forthcoming.
patternPhase
Description forthcoming.
restoreGraphicsState
Description forthcoming.
saveGraphicsState
Description forthcoming.
setCompositingOperation:
operation
Description forthcoming.
setFocusStack:
stack
Description forthcoming.
setImageInterpolation:
interpolation
Description forthcoming.
setPatternPhase:
phase
Description forthcoming.
setShouldAntialias:
antialias
Description forthcoming.
shouldAntialias
Description forthcoming.
Software documentation for the NSGraphicsContext(GNUstep) category
AppKit/NSGraphicsContext.h
Description forthcoming.
handleExposeRect:
rect
forDriver:
driver
Description forthcoming.
setDefaultContextClass:
defaultContextClass
Description forthcoming.
focusView
Description forthcoming.
initWithContextInfo:
info
Description forthcoming.
initWithGraphicsPort:
port
flipped:
flag
Description forthcoming.
lockFocusView:
aView
inRect:
rect
Description forthcoming.
resetUsedFonts
Description forthcoming.
setShadow:
shadow
Description forthcoming.
shadow
Description forthcoming.
unlockFocusView:
aView
needsFlush:
flush
Description forthcoming.
useFont:
fontName
Description forthcoming.
usedFonts
Description forthcoming.
Software documentation for the NSGraphicsContext(NSGradient) category
AppKit/NSGraphicsContext.h
Description forthcoming.
drawGradient:
gradient
fromCenter:
startCenter
radius:
startRadius
toCenter:
endCenter
radius:
endRadius
options:
options
Description forthcoming.
drawGradient:
gradient
fromPoint:
startPoint
toPoint:
endPoint
options:
options
Description forthcoming.
Software documentation for the NSGraphicsContext(NSGraphics) category
AppKit/NSGraphicsContext.h
Description forthcoming.
GSReadRect:
rect

Read raw pixels from the device and return the information as a bitmap. Pixels are read from the smallest device-pixel aligned rectangle containing rect (defined in the current graphics state and clipped to the current window, but not against the clipping path). If the resulting device rectangle is degenerate, Size will be (0,0) and Data will be `nil`, but the other entries in the dictionary will be filled in.

If the device does not support the operation, returns `nil`.

The returned dictionary contains at least the following keys:

Data
An NSData-instance with the image data.
Size
An NSValue/NSSize with the size in pixels of the returned image data.
BitsPerSample
An NSValue/unsigned int.
SamplesPerPixel
An NSValue/unsigned int.
ColorSpace
An NSString with the name of the color space the data is in.
HasAlpha
An NSValue/unsigned int. 0 if the returned image does not have an alpha channel, 1 if it does.
Matrix
An NSAffineTransform-instance that contains the transform between current user space and image space for this image.
GSWSetViewIsFlipped:
flipped
This method is used by the backend, but has been rendered obsolete. Do not use it in any code or in any backend implementation as it may disappear at any point.
GSWViewIsFlipped
Returns `YES` if the current focused view is flipped. This is an obsolete method. Use [[NSView focusView] isFlipped] instead
NSBeep
Play the System Beep
NSDrawBitmap:
rect
:
pixelsWide
:
pixelsHigh
:
bitsPerSample
:
samplesPerPixel
:
bitsPerPixel
:
bytesPerRow
:
isPlanar
:
hasAlpha
:
colorSpaceName
:
data
Generic method to render bitmap images. This method shouldn't be used anywhere except in the AppKit itself. It will be replaced by the more flexible GSDrawImage method sometime in the future. (Quartz).
Software documentation for the NSGraphicsContext(Ops) category
AppKit/NSGraphicsContext.h
Description forthcoming.
DPSPrintf:
fmt
:
args
Write the string (with printf substitutions) to a PostScript context. Other output contexts will likely ignore this
DPSWriteData:
buf
:
count
Write the encoded data to a PostScript context. Other output contexts will likely ignore this
DPSarc:
x
:
y
:
r
:
angle1
:
angle2
Description forthcoming.
DPSarcn:
x
:
y
:
r
:
angle1
:
angle2
Description forthcoming.
DPSarct:
x1
:
y1
:
x2
:
y2
:
r
Description forthcoming.
DPSashow:
x
:
y
:
s
Displays a string as in DPSshow, except that ( x,y) is added to the advancement of every glyph. An alternative means of achieving the same effect is to use the -GSSetCharacterSpacing: method. Either approach should be more efficient that using -DPSshow: with appropriate -DPSrmoveto:: operations.
DPSawidthshow:
cx
:
cy
:
c
:
ax
:
ay
:
s
Displays a string as in a combination of DPSashow and DPSwidthshow: (ax,ay) is added to the advancement of every glyph, while ( cx,cy) is also added to the advancement for character c's glyph specifically. Using this method should be more efficient that using -DPSshow: with appropriate -DPSrmoveto:: operations.
DPScharpath:
s
:
b
Appends to the current path a path that is equivalent to the outlines of the glyphs in the string. This results in a path that can be used for stroking, filling or clipping (DPS).
DPSclip
Clip to the current path. (DPS, Quartz).
DPSclosepath
Description forthcoming.
DPScomposite:
x
:
y
:
w
:
h
:
gstateNum
:
dx
:
dy
:
op
Description forthcoming.
DPScompositerect:
x
:
y
:
w
:
h
:
op
Description forthcoming.
DPSconcat:
m
Concatenates the coordinate transform represented by the matrix m with the current coordinate transform. (DPS).
DPScurrentalpha:
a
Returns the current alpha component (DPS).
DPScurrentcmykcolor:
c
:
m
:
y
:
k
Returns the current color according to the CMYK color model (DPS).
DPScurrentflat:
flatness
Returns the current flattness parameter, which controls how curved lines are drawn. (DPS, Quartz).
DPScurrentgray:
gray
Returns the gray-level equivalent in the current color space. The value may depend on the current color space and may be 0 if the current color space has no notion of a gray value (DPS)
DPScurrenthsbcolor:
h
:
s
:
b
Returns the current color according to the HSB color model (DPS).
DPScurrentlinecap:
linecap
Returns the current linecap value. (DPS, Quartz).
DPScurrentlinejoin:
linejoin
Returns the current linejoin value. (DPS, Quartz).
DPScurrentlinewidth:
width
Returns the current line width. (DPS, Quartz).
DPScurrentmiterlimit:
limit
Returns the current linecap value. (DPS, Quartz).
DPScurrentoffset:
x
:
y
Description forthcoming.
DPScurrentpoint:
x
:
y
Returns the current point. (DPS, Quartz).
DPScurrentrgbcolor:
r
:
g
:
b
Returns the current color according to the RGB color model (DPS).
DPScurrentstrokeadjust:
b
Returns the strokeadjust value. (DPS).
DPScurveto:
x1
:
y1
:
x2
:
y2
:
x3
:
y3
Description forthcoming.
DPSdissolve:
x
:
y
:
w
:
h
:
gstateNum
:
dx
:
dy
:
delta
Description forthcoming.
DPSeoclip
Description forthcoming.
DPSeofill
Description forthcoming.
DPSfill
Fill the current path. (DPS, Quartz).
DPSflattenpath
Description forthcoming.
DPSgrestore
Pops a previously saved gstate from the gstate stack and makes it current. Drawing information in the previously saved gstate becomes the current information. (DPS, Quartz).
DPSgsave
Saves (pushes) a copy of the current gstate information onto the gstate stack. This saves drawing information contained in the gstate, such as the current path, ctm and colors. (DPS, Quartz).
DPSinitclip
Description forthcoming.
DPSinitgraphics
Description forthcoming.
DPSinitmatrix
Sets the coordinate transform matrix to the initial values for the particular context
DPSlineto:
x
:
y
Description forthcoming.
DPSmoveto:
x
:
y
Description forthcoming.
DPSnewpath
Description forthcoming.
DPSpathbbox:
llx
:
lly
:
urx
:
ury
Description forthcoming.
DPSrcurveto:
x1
:
y1
:
x2
:
y2
:
x3
:
y3
Description forthcoming.
DPSrectclip:
x
:
y
:
w
:
h
Description forthcoming.
DPSrectfill:
x
:
y
:
w
:
h
Description forthcoming.
DPSrectstroke:
x
:
y
:
w
:
h
Description forthcoming.
DPSreversepath
Description forthcoming.
DPSrlineto:
x
:
y
Description forthcoming.
DPSrmoveto:
x
:
y
Description forthcoming.
DPSrotate:
angle
Rotate the coordinate system. (DPS).
DPSscale:
x
:
y
Scale the coordinate system. (DPS).
DPSsetalpha:
a
Sets the alpha drawing component. For this and other color setting commands that have no differentiation between fill and stroke colors, both the fill and stroke alpha are set (DPS).
DPSsetcmykcolor:
c
:
m
:
y
:
k
Sets the current colorspace to Device CMYK and the current color based on the indicated values. For this and other color setting commands that have no differentiation between fill and stroke colors, both the fill and stroke colors are set (DPS).
DPSsetdash:
pat
:
size
:
offset
Set the pattern for line dashes like the Postscript setdash operator. (DPS, Quartz).
DPSsetflat:
flatness
Sets the current flattness parameter, which controls how curved lines are drawn. (DPS, Quartz).
DPSsetgray:
gray
Sets the current colorspace to Device Gray and the current gray value (DPS).
DPSsetgstate:
gst
Makes the gstate indicated by the tag gst the current gstate. Note that the gstate is copied, so that changes to either gstate do not affect the other. (DPS, Quartz).
DPSsethalftonephase:
x
:
y
Description forthcoming.
DPSsethsbcolor:
h
:
s
:
b
Sets the current colorspace to Device RGB and the current color based on the indicated values (DPS).
DPSsetlinecap:
linecap
Set the current linecap value. (DPS, Quartz).
DPSsetlinejoin:
linejoin
Set the current linejoin value. (DPS, Quartz).
DPSsetlinewidth:
width
Set the current line width. (DPS, Quartz).
DPSsetmiterlimit:
limit
Set the current meter limit value. (DPS, Quartz).
DPSsetoffset:
x
:
y
Description forthcoming.
DPSsetrgbcolor:
r
:
g
:
b
Sets the current colorspace to Device RGB and the current color based on the indicated values (DPS).
DPSsetstrokeadjust:
b
Description forthcoming.
DPSshfill:
shaderDictionary
Description forthcoming.
DPSshow:
s
Display the string s using the current font (DPS).
DPSstroke
Description forthcoming.
DPStranslate:
x
:
y
Translate the coordinate system. (DPS).
DPSwidthshow:
x
:
y
:
c
:
s
Displays a string as in DPSshow, except that, for character c only, the glpyh x and y advancement is determined by the values (x,y), instead of by the glyph itself. This is often used to adjust the length of a line of text by changing the width of the space character. Using this method should be more efficient than using -DPSshow: with appropriate -DPSrmoveto:: operations.
DPSxshow:
s
:
numarray
:
size
Displays a string as in DPSshow, except that the glyph x advancement is determined by the values in numarray, one for each glyph, instead of by the glyphs themselves. size should be equal to the length of s in glyphs. Using this method should be more efficient than using -DPSshow: with appropriate -DPSrmoveto:: operations.
DPSxyshow:
s
:
numarray
:
size
Displays a string as in DPSshow, except that the glyph x and y advancement is determined by the values in numarray, one x and one y for each glyph, in alternating order, instead of by the glyphs themselves. size should be equal to the length of s in glyphs. Using this method should be more efficient than using -DPSshow: with appropriate -DPSrmoveto:: operations.
DPSyshow:
s
:
numarray
:
size
Displays a string as in DPSshow, except that the glyph y advancement is determined by the values in numarray, one for each glyph, instead of by the glyphs themselves. size should be equal to the length of s in glyphs. Using this method should be more efficient than using -DPSshow: with appropriate -DPSrmoveto:: operations.
GSConcatCTM:
ctm
Concatenates the matrix ctm onto the current coordinate transform matrix. (Quartz).
GSCurrentCTM
Returns the current coordinate transform matrix. (Quartz).
GSCurrentDevice:
device
:
x
:
y
This is a private method used between the window server and the context. It should not be used in any application. Typically used by the window server to find out what window the context is drawing graphics to. The device pointer is an opaque type that contains information about the window. The x and y pointers indicate the offset of the origin of the window from the lower left-hand corner
GSDefineGState
Creates a copy of the current gstate and associates it with a tag, which is given in the return value. This tag can later be used in -DPSsetgstate: to set the gstate as being current again. (DPS, Quartz).
GSDrawImage:
rect
:
imageref
Generic method to draw an image into a rect. The image is defined by imageref, an opaque structure. Support for this method hasn't been implemented yet, so it should not be used anywhere.
GSGetTextCTM

Returns the transfer function for transforming text from text space to user space. See -GSSetTextCTM: for additiona information. (Quartz).

GSGetTextPosition
Returns the location at which text will be drawn. In text-space coordinates. (Quartz).
GSRectClipList:
rects
:
count
Append the array of rects to the current clip path (DPS, Quartz).
GSRectFillList:
rects
:
count
Draw and fill the array of rects. (DPS, Quartz)
GSReplaceGState:
gst
Replaces the gstate refered to by the tag gst with the current gstate. The former gstate is destroyed. (DPS, Quartz).
GSSendBezierPath:
path
Set the bezier path as the current path
GSSetCTM:
ctm
Sets the coordinate transform matrix which describes how graphics will be transformed into device coordinates. (Quartz).
GSSetCharacterSpacing:
extra
Use this method to set the additional spacing between characters (glyphs). This spacing is added to the normal spacing for each character. Units are in text-space coordinate system. (Quartz).
GSSetDevice:
device
:
x
:
y
This is a private method used between the window server and the context. It should not be used in any application. Typically called by the window server to tell the context what window it should draw graphics to. The device pointer is an opaque type that contains information about the window. The x and y values tell the context that it should put the origin of the transform matrix at the indicated x and y values from the lower left-hand corner of the window
GSSetFillColor:
values
Sets the current color for fill operations. The values array should have n components, where n corresponds to the number of color components required to specify the color in the current colorspace (Quartz).
GSSetFillColorspace:
spaceref

Sets the colorspace for fill operations based on values in the supplied dictionary dict.

For device colorspaces (GSDeviceGray, GSDeviceRGB, GSDeviceCMYK), only the name of the colorspace needs to be set using the GSColorSpaceName key.

Other colorspaces will be documented later (Quartz).

GSSetFont:
fontref
Set the current font for drawing glyphs. (DPS, Quartz).
GSSetFontSize:
size
Set the font size of the current NSFont used for drawing glyphs. (DPS, Quartz).
GSSetPatterColor:
image
Description forthcoming.
GSSetStrokeColor:
values
Sets the current color for stroke operations. The values array should have n components, where n corresponds to the number of color components required to specify the color in the current colorspace (Quartz).
GSSetStrokeColorspace:
spaceref
Sets the colorspace for stroke operations based on the values in the supplied dictionary. See -GSSetFillColorspace: for a description of the values that need to be supplied (Quartz).
GSSetTextCTM:
ctm

Set the transfer function for transforming text from text space to user space. This transform is only applied to text objects and is in addition to the normal coordinate transform matrix. When drawing text, this transform is applied before the normal CTM.

The text matrix can be changed by either modifying it directly, or just by drawing text, in which case the tx and ty offset veriables are modified to point to the location of the next character that could be rendered (Quartz).

GSSetTextDrawingMode:
mode
Set the current text drawing mode. The mode can be one of several values that fill/stroke the text or add it to the current clipping path. (Quartz).
GSSetTextPosition:
loc
Set the location at which text will be drawn, in text-space coordinates. This routine updates the current text coordinate matrix. (Quartz).
GSShowGlyphs:
glyphs
:
length
Paints the glyphs using the current font. (Quartz).
GSShowGlyphsWithAdvances:
glyphs
:
advances
:
length
Paints the glyphs with the specified advances using the current font. (Quartz).
GSShowText:
string
:
length
Paints text represented by the characters in string in the current font. (Quartz).
GSUndefineGState:
gst
Disassociates the tag gst with it's gstate and destroys the gstate object. The tag will no longer be valid and should not be used to refer to the gstate again. (DPS, Quartz).
GScomposite:
gstateNum
toPoint:
aPoint
fromRect:
srcRect
operation:
op
fraction:
delta
Description forthcoming.
GSdraw:
gstateNum
toPoint:
aPoint
fromRect:
srcRect
operation:
op
fraction:
delta
Draws a gstate in a way that fully respects the destination transform, unlike the GSComposite operator which ignores the rotation and the scaling effect on the content. Note: For the GScomposite operator, the scaling and rotation affects the destination point but not the content.
appendBezierPathWithPackedGlyphs:
packedGlyphs
path:
aPath
Description forthcoming.
supportsDrawGState
Returns whether the backend supports a GSDraw operator. By default, returns `NO`.
When a GSContext backend subclass overrides this method to return `YES`, the backend must also implement -drawGState:fromRect:toPoint:op:fraction: in its GSState subclass. When `YES` is returned, -[NSImage drawXXX] methods that involves rotation, scaling etc. will delegate as much as possible the image drawing to the backend, rather than trying to emulate the resulting image in Gui by using intermediate images to rotate and scale the content, and then composite the result with -GScomposite:toPoint:fromRect:operation:fraction:. Backends which doesn't implement -compositeGState:fromRect:toPoint:op:fraction: can draw rotated or scaled images, but the semantic won't exactly match the NSImage documentation in non-trivial cases.
Software documentation for the NSGraphicsContext(Printing) category
AppKit/NSGraphicsContext.h
Description forthcoming.
beginPage:
ordinalNum
label:
aString
bBox:
pageRect
fonts:
fontNames
Description forthcoming.
beginPrologueBBox:
boundingBox
creationDate:
dateCreated
createdBy:
anApplication
fonts:
fontNames
forWhom:
user
pages:
numPages
title:
aTitle
Description forthcoming.
beginSetup
Description forthcoming.
beginTrailer
Description forthcoming.
endDocumentPages:
pages
documentFonts:
fontNames
Description forthcoming.
endHeaderComments
Description forthcoming.
endPageSetup
Description forthcoming.
endPrologue
Description forthcoming.
endSetup
Description forthcoming.
endSheet
Description forthcoming.
endTrailer
Description forthcoming.
printerProlog
Description forthcoming.
showPage
Description forthcoming.