Page: 1 2 3 4 5 6 7 8

Chapter 7


Graphics Context Functions

A number of resources are used when performing graphics operations in X. Most information about performing graphics (for example, foreground color, background color, line style, and so on) is stored in resources called graphics contexts (GC). Most graphics operations (see Chapter 8) take a GC as an argument. Although in theory the X protocol permits sharing of GCs between applications, it is expected that applications will use their own GCs when performing operations. Sharing of GCs is highly discouraged because the library may cache GC state.

Graphics operations can be performed to either windows or pixmaps, which collectively are called drawables. Each drawable exists on a single screen. A GC is created for a specific screen and drawable depth and can only be used with drawables of matching screen and depth.

This chapter discusses how to:

7.1. Manipulating Graphics Context/State

Most attributes of graphics operations are stored in Graphic Contexts (GCs). These include line width, line style, plane mask, foreground, background, tile, stipple, clipping region, end style, join style, and so on. Graphics operations (for example, drawing lines) use these values to determine the actual drawing operation. Extensions to X may add additional components to GCs. The contents of a GC are private to Xlib.

Xlib implements a write-back cache for all elements of a GC that are not resource IDs to allow Xlib to implement the transparent coalescing of changes to GCs. For example, a call to XSetForeground of a GC followed by a call to XSetLineAttributes results in only a single-change GC protocol request to the server. GCs are neither expected nor encouraged to be shared between client applications, so this write-back caching should present no problems. Applications cannot share GCs without external synchronization. Therefore, sharing GCs between applications is highly discouraged.

To set an attribute of a GC, set the appropriate member of the XGCValues structure and OR in the corresponding value bitmask in your subsequent calls to XCreateGC. The symbols for the value mask bits and the XGCValues structure are:

/* GC attribute value mask bits */

#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
GCFunction
GCPlaneMask
GCForeground
GCBackground
GCLineWidth
GCLineStyle
GCCapStyle
GCJoinStyle
GCFillStyle
GCFillRule
GCTile
GCStipple
GCTileStipXOrigin
GCTileStipYOrigin
GCFont
GCSubwindowMode
GCGraphicsExposures
GCClipXOrigin
GCClipYOrigin
GCClipMask
GCDashOffset
GCDashList
GCArcMode
(1L<<0)
(1L<<1)
(1L<<2)
(1L<<3)
(1L<<4)
(1L<<5)
(1L<<6)
(1L<<7)
(1L<<8)
(1L<<9)
(1L<<10)
(1L<<11)
(1L<<12)
(1L<<13)
(1L<<14)
(1L<<15)
(1L<<16)
(1L<<17)
(1L<<18)
(1L<<19)
(1L<<20)
(1L<<21)
(1L<<22)

/* Values */

typedef struct {
int function;
unsigned long plane_mask;
unsigned long foreground;
unsigned long background;
int line_width;
int line_style;
int cap_style;
int join_style;
int fill_style;
int fill_rule;
int arc_mode;
Pixmap tile;
Pixmap stipple;
int ts_x_origin;
int ts_y_origin;
Font font;
int subwindow_mode;
Bool graphics_exposures;
int clip_x_origin,
int clip_y_origin;
Pixmap clip_mask;
int dash_offset;
char dashes;
/* logical operation */
/* plane mask */
/* foreground pixel */
/* background pixel */
/* line width (in pixels) */
/* LineSolid, LineOnOffDash, LineDoubleDash */
/* CapNotLast, CapButt, CapRound, CapProjecting */
/* JoinMiter, JoinRound, JoinBevel */
/* FillSolid, FillTiled, FillStippled FillOpaqueStippled*/
/* EvenOddRule, WindingRule */
/* ArcChord, ArcPieSlice */
/* tile pixmap for tiling operations */
/* stipple 1 plane pixmap for stippling */
/* offset for tile or stipple operations */

/* default text font for text operations */
/* ClipByChildren, IncludeInferiors */
/* boolean, should exposures be generated */
/* origin for clipping */

/* bitmap clipping; other calls for rects */
/* patterned/dashed line information */
} XGCValues;

Home


The default GC values are:

ComponentDefault
function
plane_mask
foreground
background
line_width
line_style
cap_style
join_style
fill_style
fill_rule
arc_mode
tile


stipple
ts_x_origin
ts_y_origin
font
subwindow_mode
graphics_exposures
clip_x_origin
clip_y_origin
clip_mask
dash_offset
dashes
GXcopy
All ones
0
1
0
LineSolid
CapButt
JoinMiter
FillSolid
EvenOddRule
ArcPieSlice
Pixmap of unspecified size filled with foreground pixel
(that is, client specified pixel if any, else 0)
(subsequent changes to foreground do not affect this pixmap)
Pixmap of unspecified size filled with ones
0
0
<implementation dependent>
ClipByChildren
True
0
0
None
0
4 (that is, the list [4, 4])

Note that foreground and background are not set to any values likely to be useful in a window.

The function attributes of a GC are used when you update a section of a drawable (the destination) with bits from somewhere else (the source). The function in a GC defines how the new destination bits are to be computed from the source bits and the old destination bits. GXcopy is typically the most useful because it will work on a color display, but special applications may use other functions, particularly in concern with particular planes of a color display. The 16 GC functions, defined in <X11/X.h>, are:

Function NameValueOperation
GXclear
GXand
GXandReverse
GXcopy
GXandInverted
GXnoop
GXxor
GXor
GXnor
GXequiv
GXinvert
GXorReverse
GXcopyInverted
GXorInverted
GXnand
CXset
0x0
0xl
0x2
0x3
0x4
0x5
0x6
0x7
0x8
0x9
0xa
0xb
0xc
0xd
0xe
0xf
0
src AND dst
src AND NOT dst
src
(NOT src) AND dst
dst
src XOR dst
src OR dst
(NOT src) AND (NOT dst)
(NOT src) XOR dst
NOT dst
src OR (NOT dst)
NOT src
(NOT src) OR dst
(NOT src) OR (NOT dst)
1

Many graphics operations depend on either pixel values or planes in a GC. The planes attribute is of type long, and it specifies which planes of the destination are to be modified, one bit per plane. A monochrome display has only one plane and will be the least-significant bit of the word. As planes are added to the display hardware, they will occupy more significant bits in the plane mask.

In graphics operations, given a source and destination pixel, the result is computed bitwise on corresponding bits of the pixels. That is, a Boolean operation is performed in each bit plane. The plane_mask restricts the operation to a subset of planes. A macro constant AllPlanes can be used to refer to all planes of the screen simultaneously. The result is computed by the following:

((src FUNC dst) AND plane-mask) OR (dst AND (NOT plane-mask))

Range checking is not performed on the values for foreground, background, or plane_mask. They are simply truncated to the appropriate number of bits. The line-width is measured in pixels and either can be greater than or equal to one (wide line) or can be the special value zero (thin line).

Wide lines are drawn centered on the path described by the graphics request. Unless otherwise specified by the join-style or cap-style, the bounding box of a wide line with endpoints [x1, y1], [x2, y2] and width w is a rectangle with vertices at the following real coordinates:

[x1-(w*sn/2), y1+(w*cs/2)], [x1+(w*sn/2), y1-(w*cs/2)],
[x2-(w*sn/2), y2+(w*cs/2)], [x2+(w*sn/2), y2-(w*cs/2)]

Here sn is the sine of the angle of the line, and cs is the cosine of the angle of the line. A pixel is part of the line and so is drawn if the center of the pixel is fully inside the bounding box (which is viewed as having infinitely thin edges). If the center of the pixel is exactly on the bounding box, it is part of the line if and only if the interior is immediately to its right (x increasing direction). Pixels with centers on a horizontal edge are a special case and are part of the line if and only if the interior or the boundary is immediately below (y increasing direction) and the interior or the boundary is immediately to the right (x increasing direction).

Thin lines (zero line-width) are one-pixel-wide lines drawn using an unspecified, device dependent algorithm. There are only two constraints on this algorithm.

  1. If a line is drawn unclipped from [x1, y1] to [x2, y2] and if another line is drawn unclipped from [x1+ dx, y1+dy] to [x2+dx, y2+dy], a point [x, y] is touched by drawing the first line if and only if the point [x+dx,y+dy] is touched by drawing the second line.
  2. The effective set of points comprising a line cannot be affected by clipping. That is, a point is touched in a clipped line if and only if the point lies inside the clipping region and the point would be touched by the line when drawn unclipped.

A wide line drawn from [x1, y1] to [x2, y2] always draws the same pixels as a wide line drawn from [x2, y2] to [x1, y1], not counting cap-style and join-style. It is recommended that this property be true for thin lines, but this is not required. A line-width of zero may differ from a linewidth of one in which pixels are drawn. This permits the use of many manufacturers' line drawing hardware, which may run many times faster than the more precisely specified wide lines.

In general, drawing a thin line will be faster than drawing a wide line of width one. However, because of their different drawing algorithms, thin lines may not mix well aesthetically with wide lines. If it is desirable to obtain precise and uniform results across all displays, a client should always use a line-width of one rather than a line-width of zero.

The line-style defines which sections of a line are drawn:

LineSolid
The full path of the line is drawn.
LineDoubleDash
The full path of the line is drawn, but the even dashes are filled differently than the odd dashes (see fill-style) with CapButt style used where even and odd dashes meet.
LineOnOffDash
Only the even dashes are drawn, and cap-style applies to all internal ends of the individual dashes, except CapNotLast is treated as CapButt.

The cap-style defines how the endpoints of a path are drawn:

CapNotLast
This is equivalent to CapButt except that for a line-width of zero the final endpoint is not drawn.
CapButt
The line is square at the endpoint (perpendicular to the slope of the line) with no projection beyond.
CapRound
The line has a circular arc with the diameter equal to the line-width, centered on the endpoint. (This is equivalent to CapButt for line-width of zero).
CapProjecting
The line is square at the end, but the path continues beyond the endpoint for a distance equal to half the line-width. (This is equivalent to CapButt for line-width of zero).

The join-style defines how corners are drawn for wide lines:

JoinMiter
The outer edges of two lines extend to meet at an angle. However, if the angle is less than 11 degrees, then a JoinBevel join-style is used instead.
JoinRound
The corner is a circular arc with the diameter equal to the line-width, centered on the joinpoint.
JoinBevel
The corner has CapButt endpoint styles with the triangular notch filled.

For a line with coincident endpoints (x1=x2, y1=y2), when the cap-style is applied to both end-points, the semantics depends on the line-width and the cap-style:

CapNotLastthinThe results are device- dependent, but the desired effect is that nothing is drawn.
CapButtthinThe results are device- dependent, but the desired effect is that a single pixel is drawn.
CapRoundthinThe results are the same as for CapButt/thin.
CapProjectingthinThe results are the same as for CapButt/thin.
CapButtwideNothing is drawn.
CapRoundwideThe closed path is a circle, centered at the endpoint, and with the diameter equal to the line-width.
CapProjectingwideThe closed path is a square, aligned with the coordinate axes, centered at the endpoint, and with the sides equal to the line-width.

For a line with coincident endpoints (x1=x2, y1=y2), when the join-style is applied at one or both endpoints, the effect is as if the line was removed from the overall path. However, if the total path consists of or is reduced to a single point joined with itself, the effect is the same as when the cap-style is applied at both endpoints.

The tile/stipple represents an infinite two-dimensional plane, with the tile/stipple replicated in all dimensions. When that plane is superimposed on the drawable for use in a graphics operation, the upper-left corner of some instance of the tile/stipple is at the coordinates within the drawable specified by the tile/stipple origin. The tile/stipple and clip origins are interpreted relative to the origin of whatever destination drawable is specified in a graphics request. The tile pixmap must have the same root and depth as the GC, or a BadMatch error results. The stipple pixmap must have depth one and must have the same root as the GC, or a BadMatch error results. For stipple operations where the fill-style is FillStippled but not FillOpaqueStippled, the stipple pattern is tiled in a single plane and acts as an additional clip mask to be ANDed with the clip-mask. Although some sizes may be faster to use than others, any size pixmap can be used for tiling or stippling.

The fill-style defines the contents of the source for line, text, and fill requests. For all text and fill requests (for example, XDrawText, XDrawText16, XFillRectangle, XFillPolygon, and XFillArc); for line requests with line-style LineSolid (for example, XDrawLine, XDrawSegments, XDrawRectangle, XDrawArc); and for the even dashes for line requests with line-style LineOnOffDash or LineDoubleDash, the following apply:

FillSolid
Foreground
FillTiled
Tile
FillOpaqueStippled
A tile with the same width and height as stipple, but with background everywhere stipple has a zero and with foreground everywhere stipple has a one
FillStippled
Foreground masked by stipple

When drawing lines with line-style LineDoubleDash, the odd dashes are controlled by the fill-style in the following manner:

FillSolid
Background
FillTiled
Same as for even dashes
FillOpaqueStippled
Same as for even dashes
FillStippled
Background masked by stipple

Home


Storing a pixmap in a GC might or might not result in a copy being made. If the pixmap is later used as the destination for a graphics request, the change might or might not be reflected in the GC. If the pixmap is used simultaneously in a graphics request both as a destination and as a tile or stipple, the results are undefined.

For optimum performance, you should draw as much as possible with the same GC (without changing its components). The costs of changing GC components relative to using different GCs depend upon the display hardware and the server implementation. It is quite likely that some amount of GC information will be cached in display hardware and that such hardware can only cache a small number of GCs.

The dashes value is actually a simplified form of the more general patterns that can be set with XSetDashes. Specifying a value of N is equivalent to specifying the two-element list [N, N] in XSetDashes. The value must be nonzero, or a BadValue error results.

The clip-mask restricts writes to the destination drawable. If the clip-mask is set to a pixmap, it must have depth one and have the same root as the GC, or a BadMatch error results. If clip-mask is set to None, the pixels are always drawn regardless of the clip origin. The clip-mask also can be set by calling the XSetClipRectangles or XSetRegion functions. Only pixels where the clip-mask has a bit set to 1 are drawn. Pixels are not drawn outside the area covered by the clip-mask or where the clip-mask has a bit set to 0. The clip-mask affects all graphics requests. The clip-mask does not clip sources. The clip-mask origin is interpreted relative to the origin of whatever destination drawable is specified in a graphics request.

You can set the subwindow-mode to ClipByChildren or IncludeInferiors. For ClipByChildren, both source and destination windows are additionally clipped by all viewable InputOutput children. For IncludeInferiors, neither source nor destination window is clipped by inferiors. This will result in including subwindow contents in the source and drawing through subwindow boundaries of the destination. The use of IncludeInferiors on a window of one depth with mapped inferiors of differing depth is not illegal, but the semantics are undefined by the core protocol.

The fill-rule defines what pixels are inside (drawn) for paths given in XFillPolygon requests and can be set to EvenOddRule or WindingRule. For EvenOddRule, a point is inside if an infinite ray with the point as origin crosses the path an odd number of times. For WindingRule, a point is inside if an infinite ray with the point as origin crosses an unequal number of clockwise and counterclockwise directed path segments. A clockwise directed path segment is one that crosses the ray from left to right as observed from the point. A counterclockwise segment is one that crosses the ray from right to left as observed from the point. The case where a directed line segment is coincident with the ray is uninteresting because you can simply choose a different ray that is not coincident with a segment.

For both EvenOddRule and WindingRule, a point is infinitely small, and the path is an infinitely thin line. A pixel is inside if the center point of the pixel is inside and the center point is not on the boundary. If the center point is on the boundary, the pixel is inside if and only if the polygon interior is immediately to its right (x increasing direction). Pixels with centers on a horizontal edge are a special case and are inside if and only if the polygon interior is immediately below (y increasing direction).

The arc-mode controls filling in the XFillArcs function and can be set to ArcPieSlice or ArcChord. For ArcPieSlice, the arcs are pie-slice filled. For ArcChord, the arcs are chord filled.

The graphics-exposure flag controls GraphicsExpose event generation for XCopyArea and XCopyPlane requests (and any similar requests defined by extensions).

To create a new GC that is usable on a given screen with a depth of drawable, use XCreateGC.

GC XCreateGC(display, d, valuemask, values)
   Display *display;
   Drawable d;
   unsigned long valuemask;
   XGCValues *values;
display
Specifies the connection to the X server.
d
Specifies the drawable.
valuemask
Specifies which components in the GC are to be set using the information in the specified values structure. This argument is the bitwise inclusive OR of zero or more of the valid GC component mask bits.
values
Specifies any values as specified by the valuemask.

The XCreateGC function creates a graphics context and returns a GC. The GC can be used with any destination drawable having the same root and depth as the specified drawable. Use with other drawables results in a BadMatch error.

XCreateGC can generate BadAlloc, BadDrawable, BadFont, BadMatch, BadPixmap, and BadValue errors.

To copy components from a source GC to a destination GC, use XCopyGC.

XCopyGC(display, src, valuemask, dest)
  Display *display;
  GC src, dest;
  unsigned long valuemask;
display
Specifies the connection to the X server.
src
Specifies the components of the source GC.
valuemask
Specifies which components in the GC are to be copied to the destination GC.
This argument is the bitwise inclusive OR of zero or more of the valid GC component mask bits.
dest
Specifies the destination GC.

The XCopyGC function copies the specified components from the source GC to the destination GC. The source and destination GCs must have the same root and depth, or a BadMatch error results. The valuemask specifies which component to copy, as for XCreateGC.

XCopyGC can generate BadAlloc, BadGC, and BadMatch errors.

To change the components in a given GC, use XChangeGC.

XChangeGC(display, gc, valuemask, values)
  Display *display;
  GC gc;
  unsigned long valuemask;
  XGCValues *values;
display
Specifies the connection to the X server.
gc
Specifies the GC.
valuemask
Specifies which components in the GC are to be changed using information in the specified values structure. This argument is the bitwise inclusive OR of zero or more of the valid GC component mask bits.
values
Specifies any values as specified by the valuemask.

Home


The XChangeGC function changes the components specified by valuemask for the specified GC. The values argument contains the values to be set. The values and restrictions are the same as for XCreateGC. Changing the clip-mask overrides any previous XSetClipRectangles request on the context. Changing the dash-offset or dash-list overrides any previous XSetDashes request on the context. The order in which components are verified and altered is server-dependent. If an error is generated, a subset of the components may have been altered.

XChangeGC can generate BadAlloc, BadFont, BadGC, BadMatch, BadPixmap, and BadValue errors.

To obtain components of a given GC, use XGetGCValues.

Status XGetGCValues(display, gc, valuemask, values_return)
    Display *display;
    GC gc;
    unsigned long valuemask;
    XGCValues *values_return;
display
Specifies the connection to the X server.
gc
Specifies the GC.
valuemask
Specifies which components in the GC are to be returned in the values_return argument. This argument is the bitwise inclusive OR of zero or more of the valid GC component mask bits.
values_return
Returns the GC values in the specified XGCValues structure.

The XGetGCValues function returns the components specified by valuemask for the specified GC. If the valuemask contains a valid set of GC mask bits (GCFunction, GCPlaneMask, GCForeground, GCBackground, GCLineWidth, GCLineStyle, GCCapStyle, GCJoinStyle, GCFillStyle, GCFillRule, GCTile, GCStipple, GCTileStipXOrigin, GCTileStipYOrigin, GCFont, GCSubwindowMode, GCGraphicsExposures, GCClipXOrigin, GCCLipYOrigin, GCDashOffset, or GCArcMode) and no error occurs, XGetGCValues sets the requested components in values_return and returns a nonzero status. Otherwise, it returns a zero status. Note that the clip-mask and dash-list (represented by the GCClipMask and GCDashList bits, respectively, in the valuemask) cannot be requested. Also note that an invalid resource ID (with one or more of the three most-significant bits set to 1) will be returned for GCFont, GCTile, and GCStipple if the component has never been explicitly set by the client.

To free a given GC, use XFreeGC.

XFreeGC(display, gc)
   Display *display;
   GC gc;
display
Specifies the connection to the X server.
gc
Specifies the GC.

The XFreeGC function destroys the specified GC as well as all the associated storage. XFreeGC can generate a BadGC error.

To obtain the GContext resource ID for a given GC, use XGContextFromGC.

GContext XGContextFromGC(gc)
  GC gc;
gc
Specifies the GC for which you want the resource ID.

Xlib usually defers sending changes to the components of a GC to the server until a graphics function is actually called with that GC. This permits batching of component changes into a single server request. In some circumstances, however, it may be necessary for the client to explicitly force sending the changes to the server. An example might be when a protocol extension uses the GC indirectly, in such a way that the extension interface cannot know what GC will be used. To force sending GC component changes, use XFlushGC.

void XFlushGC(display, gc)
     Display *display;
     GC gc;
display
Specifies the connection to the X server.
gc
Specifies the GC.

Home


7.2. Using GC Convenience Routines

This section discusses how to set the:

7.2.1. Setting the Foreground, Background, Function, or Plane Mask

To set the foreground, background, plane mask, and function components for a given GC, use XSetState.

XSetState(display, gc , foreground, background, function, plane_mask)
   Display *display;
   GC gc;
   unsigned long foreground, background;
   int function;
   unsigned long plane_mask;
display
Specifies the connection to the X server.
gc
Specifies the GC.
foreground
Specifies the foreground you want to set for the specified GC.
background
Specifies the background you want to set for the specified GC.
function
Specifies the function you want to set for the specified GC.
plane_mask
Specifies the plane mask.

XSetState can generate BadAlloc, BadGC, and BadValue errors.

To set the foreground of a given GC, use XSetForeground.

XSetForeground(display, gc,foreground)
   Display *display;
   GC gc;
   unsigned long foreground;
display
Specifies the connection to the X server.
gc
Specifies the GC.
foreground
Specifies the foreground you want to set for the specified GC.

XSetForeground can generate BadAlloc and BadGC errors.

To set the background of a given GC, use XSetBackground.

XSetBackground(display, gc, background)
   Display *display;
   GC gc;
   unsigned long background;
display
Specifies the connection to the X server.
gc
Specifies the GC.
background
Specifies the background you want to set for the specified GC.

XSetBackground can generate BadAlloc and BadGC errors.

To set the display function in a given GC, use XSetFunction.

XSetFunction(display, gc, function)
   Display *display;
   GC gc;
   int function;
display
Specifies the connection to the X server.
gc
Specifies the GC.
function
Specifies the function you want to set for the specified GC.

XSetFunction can generate BadAlloc, BadGC, and BadValue errors.

To set the plane mask of a given GC, use XSetPlaneMask.

XSetPlaneMask(display, gc, plane_mask)
   Display *display;
   GC gc;
   unsigned long plane_mask;
display
Specifies the connection to the X server.
gc
Specifies the GC.
plane_mask
Specifies the plane mask.

XSetPlaneMask can generate BadAlloc and BadGC errors.

Home


7.2.2. Setting the Line Attributes and Dashes

To set the line drawing components of a given GC, use XSetLineAttributes.

XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style)
   Display *display;
   GC gc;
   unsigned int line_width;
   int line_style;
   int cap_style;
   int join_style;
display
Specifies the connection to the X server.
gc
Specifies the GC.
line_width
Specifies the line-width you want to set for the specified GC.
line_style
Specifies the line-style you want to set for the specified GC. You can pass LineSolid, LineOnOffDash, or LineDoubleDash.
cap_style
Specifies the line-style and cap-style you want to set for the specified GC. You can pass CapNotLast, CapButt, CapRound, or CapProjecting.
join_style
Specifies the line join-style you want to set for the specified GC. You can pass JoinMiter, JoinRound, or JoinBevel.

XSetLineAttributes can generate BadAlloc, BadGC, and BadValue errors.

To set the dash-offset and dash-list for dashed line styles of a given GC, use XSetDashes.

XSetDashes(display, gc, dash_offset, dash_list, n)
    Display *display;
    GC gc;
    int dash_offset;
    char dash_list[];
    int n;
display
Specifies the connection to the X server.
gc
Specifies the GC.
dash_offset
Specifies the phase of the pattern for the dashed line-style you want to set for the specified GC.
dash_list
Specifies the dash-list for the dashed line-style you want to set for the specified GC.
n
Specifies the number of elements in dash_list.

The XSetDashes function sets the dash-offset and dash-list attributes for dashed line styles in the specified GC. There must be at least one element in the specified dash_list, or a BadValue error results. The initial and alternating elements (second, fourth, and so on) of the dash_list are the even dashes, and the others are the odd dashes. Each element specifies a dash length in pixels. All of the elements must be nonzero, or a BadValue error results. Specifying an odd-length list is equivalent to specifying the same list concatenated with itself to produce an even-length list.

The dash-offset defines the phase of the pattern, specifying how many pixels into the dash-list the pattern should actually begin in any single graphics request. Dashing is continuous through path elements combined with a join-style but is reset to the dash-offset between each sequence of joined lines.

The unit of measure for dashes is the same for the ordinary coordinate system. Ideally, a dash length is measured along the slope of the line, but implementations are only required to match this ideal for horizontal and vertical lines. Failing the ideal semantics, it is suggested that the length be measured along the major axis of the line. The major axis is defined as the x axis for lines drawn at an angle of between -45 and +45 degrees or between 135 and 225 degrees from the x axis. For all other lines, the major axis is the y axis.

XSetDashes can generate BadAlloc, BadGC, and BadValue errors.

7.2.3. Setting the Fill Style and Fill Rule

To set the fill-style of a given GC, use XSetFillStyle.

XSetFillStyle(display, gc, fill_style)
   Display *display;
   GC gc;
   int fill_style;
display
Specifies the connection to the X server.
gc
Specifies the GC.
fill_style
Specifies the fill-style you want to set for the specified GC. You can pass FillSolid, FillTiled, FillStippled, or FillOpaqueStippled.

XSetFillStyle can generate BadAlloc, BadGC, and BadValue errors.

To set the fill-rule of a given GC, use XSetFillRule.

XSetFillRule(display, gc, fill_rule)
   Display *display;
   GC gc;
   int fill_rule;
display
Specifies the connection to the X server.
gc
Specifies the GC.
fill_rule
Specifies the fill-rule you want to set for the specified GC. You can pass EvenOddRule or WindingRule.

XSetFillRule can generate BadAlloc, BadGC, and BadValue errors.

Home


7.2.4. Setting the Fill Tile and Stipple

Some displays have hardware support for tiling or stippling with patterns of specific sizes. Tiling and stippling operations that restrict themselves to those specific sizes run much faster than such operations with arbitrary size patterns. Xlib provides functions that you can use to determine the best size, tile, or stipple for the display as well as to set the tile or stipple shape and the tile or stipple origin.

To obtain the best size of a tile, stipple, or cursor, use XQueryBestSize.

Status XQueryBestSize(display, class, which_screen, width, height, width_return, height_return)
    Display *display;
    int class;
    Drawable which_screen;
    unsigned int width, height;
    unsigned int *width_return, *height_return;
display
Specifies the connection to the X server.
class
Specifies the class that you are interested in. You can pass TileShape, CursorShape, or StippleShape.
which_screen
Specifies any drawable on the screen.
width, height
Specify the width and height.
width_return, height_return
Return the width and height of the object best supported by the display hardware.

The XQueryBestSize function returns the best or closest size to the specified size. For CursorShape, this is the largest size that can be fully displayed on the screen specified by which_screen. For TileShape, this is the size that can be tiled fastest. For StippleShape, this is the size that can be stippled fastest. For CursorShape, the drawable indicates the desired screen. For TileShape and StippleShape, the drawable indicates the screen and possibly the window class and depth. An InputOnly window cannot be used as the drawable for TileShape or StippleShape, or a BadMatch error results.

XQueryBestSize can generate BadDrawable, BadMatch, and BadValue errors.

To obtain the best fill tile shape, use XQueryBestTile.

Status XQueryBestTile(display, which_screen, width, height, width_return, height_return)
    Display *display;
    Drawable which_screen;
    unsigned int width, height;
    unsigned int *width_return, *height_return;
display
Specifies the connection to the X server.
which_screen
Specifies any drawable on the screen.
width, height
Specify the width and height.
width_return, height_return
Return the width and height of the object best supported by the display hardware.

The XQueryBestTile function returns the best or closest size, that is, the size that can be tiled fastest on the screen specified by which_screen. The drawable indicates the screen and possibly the window class and depth. If an InputOnly window is used as the drawable, a BadMatch error results.

XQueryBestTile can generate BadDrawable and BadMatch errors.

To obtain the best stipple shape, use XQueryBestStipple.

Status XQueryBestStipple(display, which_screen, width, height, width_return, height_return)
    Display *display;
    Drawable which_screen;
    unsigned int width, height;
    unsigned int *width_return, *height_return;
display
Specifies the connection to the X server.
which_screen
Specifies any drawable on the screen.
width, height
Specify the width and height.
width_return, height return
Return the width and height of the object best supported by the display hardware.

The XQueryBestStipple function returns the best or closest size, that is, the size that can be stippled fastest on the screen specified by which_screen. The drawable indicates the screen and possibly the window class and depth. If an InputOnly window is used as the drawable, a BadMatch error results.

XQueryBestStipple can generate BadDrawable and BadMatch errors.

To set the fill tile of a given GC, use XSetTile.

XSetTile(display, gc, tile)
    Display *display;
    GC gc;
    Pixmap tile;
display
Specifies the connection to the X server.
gc
Specifies the GC.
tile
Specifies the fill tile you want to set for the specified GC.

The tile and GC must have the same depth, or a BadMatch error results.

XSetTile can generate BadAlloc, BadGC, BadMatch, and BadPixmap errors.

To set the stipple of a given GC, use XSetStipple.

XSetStipple(display, gc, stipple)
   Display *display;
   GC gc;
   Pixmap stipple;
display
Specifies the connection to the X server.
gc
Specifies the GC.
stipple
Specifies the stipple you want to set for the specified GC.

The stipple must have a depth of one, or a BadMatch error results.

XSetStipple can generate BadAlloc, BadGC, BadMatch, and BadPixmap errors.

To set the tile or stipple origin of a given GC, use XSetTSOrigin.

XSetTSOrigin(display, gc, ts_x_origin, ts_y_origin)
   Display *display;
   GC gc;
   int ts_x_origin, ts_y_origin;
display
Specifies the connection to the X server.
gc
Specifies the GC.
ts_x_origin, ts_y_origin
Specify the x and y coordinates of the tile and stipple origin.

When graphics requests call for tiling or stippling, the parent's origin will be interpreted relative to whatever destination drawable is specified in the graphics request.

XSetTSOrigin can generate BadAlloc and BadGC error.

Home


7.2.5. Setting the Current Font

To set the current font of a given GC, use XSetFont.

XSetFont(display, gc, font)
   Display *display;
   GC gc;
   Font font;
display
Specifies the connection to the X server.
gc
Specifies the GC.
font
Specifies the font.

XSetFont can generate BadAlloc, BadFont, and BadGC errors.

7.2.6. Setting the Clip Region

Xlib provides functions that you can use to set the clip-origin and the clip-mask or set the clipmask to a list of rectangles.

To set the clip-origin of a given GC, use XSetClipOrigin.

XSetClipOrigin(display, gc, clip_x_origin, clip_y_origin)
   Display *display;
   GC gc;
   int clip_x_origin, clip_y_origin;
display
Specifies the connection to the X server.
gc
Specifies the GC.
clip_x_origin, clip_y_origin
Specify the x and y coordinates of the clip-mask origin.

The clip-mask origin is interpreted relative to the origin of whatever destination drawable is specified in the graphics request.

XSetClipOrigin can generate BadAlloc and BadGC errors.

To set the clip-mask of a given GC to the specified pixmap, use XSetClipMask.

XSetClipMask(display, gc, pixmap)
   Display *display;
   GC gc;
   Pixmap pixmap;
display
Specifies the connection to the X server.
gc
Specifies the GC.
pixmap
Specifies the pixmap or None.

If the clip-mask is set to None, the pixels are always drawn (regardless of the clip-origin). XSetClipMask can generate BadAlloc, BadGC, BadMatch, and BadPixmap errors.

To set the clip-mask of a given GC to the specified list of rectangles, use XSetClipRectangles.

XSetClipRectangles(display, gc, clip_x_origin, clip_y_origin, rectangles, n, ordering)
   Display *display;
   GC gc;
   int clip_x_origin, clip_y_origin;
   XRectangle rectangles[];
   int n;
   int ordering;
display
Specifies the connection to the X server.
gc
Specifies the GC.
clip_x_origin, clip_y_origin
Specify the x and y coordinates of the clip-mask origin.
rectangles
Specifies an array of rectangles that define the clip-mask.
n
Specifies the number of rectangles.
ordering
Specifies the ordering relations on the rectangles. You can pass Unsorted, YSorted, YXSorted, or YXBanded.

The XSetClipRectangles function changes the clip-mask in the specified GC to the specified list of rectangles and sets the clip origin. The output is clipped to remain contained within the rectangles. The clip-origin is interpreted relative to the origin of whatever destination drawable is specified in a graphics request. The rectangle coordinates are interpreted relative to the clip-origin. The rectangles should be nonintersecting, or the graphics results will be undefined. Note that the list of rectangles can be empty, which effectively disables output. This is the opposite of passing None as the clip-mask in XCreateGC, XChangeGC, and XSetClipMask.

If known by the client, ordering relations on the rectangles can be specified with the ordering argument. This may provide faster operation by the server. If an incorrect ordering is specified, the X server may generate a BadMatch error, but it is not required to do so. If no error is generated, the graphics results are undefined. Unsorted means the rectangles are in arbitrary order. YSorted means that the rectangles are nondecreasing in their Y origin. YXSorted additionally constrains YSorted order in that all rectangles with an equal Y origin are nondecreasing in their X origin. YXBanded additionally constrains YXSorted by requiring that, for every possible Y scanline, all rectangles that include that scanline have an identical Y origins and Y extents.

XSetClipRectangles can generate BadAlloc, BadGC, BadMatch, and BadValue errors.

Xlib provides a set of basic functions for performing region arithmetic. For information about these functions, see section 16.5.

7.2.7. Setting the Arc Mode, Subwindow Mode, and Graphics Exposure

To set the arc mode of a given GC, use XSetArcMode.

XSetArcMode(display, gc, arc_mode)
   Display *display;
   GC gc;
   int arc_mode;
display
Specifies the connection to the X server.
gc
Specifies the GC.
arc_mode
Specifies the arc mode. You can pass ArcChord or ArcPieSlice.

XSetArcMode can generate BadAlloc, BadGC, and BadValue errors.

To set the subwindow mode of a given GC, use XSetSubwindowMode.

XSetSubwindowMode(display, gc, subwindow_mode)
   Display *display;
   GC gc;
   int subwindow_mode;
display
Specifies the connection to the X server.
gc
Specifies the GC.
subwindow_mode
Specifies the subwindow mode. You can pass ClipByChildren or IncludeInferiors.

XSetSubwindowMode can generate BadAlloc, BadGC, and BadValue errors.

To set the graphics-exposures flag of a given GC, use XSetGraphicsExposures.

XSetGraphicsExposures(display, gc, graphics_exposures)
   Display *display;
   GC gc;
   Bool graphics_exposures;
display
Specifies the connection to the X server.
gc
Specifies the GC.
graphics_exposures
Specifies a Boolean value that indicates whether you want GraphicsExpose and NoExpose events to be reported when calling XCopyArea and XCopyPlane with this GC.

XSetGraphicsExposures can generate BadAlloc, BadGC, and BadValue errors.

Home

Contents Previous Chapter Next Chapter