Passa al contenuto principale

Requests: Pixmaps and Graphics Contexts

CreatePixmap​

pid: PIXMAP
drawable: DRAWABLE
depth: CARD8
width, height: CARD16
Errors: IDChoice, Drawable, Value, Alloc

Creates a pixmap, and assigns the identifier pid to it. Width and height must be non-zero. Depth must be one of the depths supported by root of the specified drawable. The initial contents of the pixmap are undefined.

It is legal to pass an InputOnly window as a drawable to this request.

FreePixmap​

pixmap: PIXMAP
Errors: Pixmap

Deletes the association between the resource id and the pixmap. The pixmap storage will be freed when no other resource references it.

CreateGC​

cid: GCONTEXT
drawable: DRAWABLE
value-mask: BITMASK
value-list: LISTofVALUE
Errors: IDChoice, Drawable, Pixmap, Font, Match, Value, Alloc

Creates a graphics context, and assigns the identifier cid to it. The gcontext can be used with any destination drawable having the same root and depth as the specified drawable.

The value-mask and value-list specify which components are to be explicitly initialized. The context components are:

alu-function: {Clear, And, AndReverse, Copy, AndInverted,
Noop, Xor, Or, Nor, Equiv, Invert,
OrReverse, CopyInverted, OrInverted,
Nand, Set}
plane-mask: CARD32
foreground: CARD32
background: CARD32
line-width: CARD16
line-style: {Solid, OnOffDash, DoubleDash}
cap-style: {NotLast, Butt, Round, Projecting}
join-style: {Miter, Round, Bevel}
fill-style: {Solid, Tiled, OpaqueStippled, Stippled}
fill-rule: {EvenOdd, Winding}
arc-mode: {Chord, PieSlice}
tile: PIXMAP
stipple: PIXMAP
tile-stipple-x-origin: INT16
tile-stipple-y-origin: INT16
font: FONT
subwindow-mode: {ClipByChildren, IncludeInferiors}
graphics-exposures: BOOL
clip-x-origin: INT16
clip-y-origin: INT16
clip-mask: PIXMAP or None
dash-offset: CARD16
dash-list: CARD8

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. That is, the result is ((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 meanings of the alu-functions are​

Clear 0 And src AND dst AndReverse src AND (NOT dst) Copy src AndInverted (NOT src) AND dst NoOp dst Xor src XOR dst Or src OR dst Nor (NOT src) AND (NOT dst) Equiv (NOT src) XOR dst Invert NOT dst OrReverse src OR (NOT dst) CopyInverted NOT src OrInverted (NOT src) OR dst NAnd (NOT src) OR (NOT dst) Set 1 Line-width is measured in pixels and can be greater than or equal to one (a "wide" line) or the special value zero (a "thin" line).

Wide lines are drawn centered on the path described by the graphics request. Unless otherwise specified by the join 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-(wsn/2), y1+(wcs/2)], [x1+(wsn/2), y1-(wcs/2)], [x2-(wsn/2), y2+(wcs/2)], [x2+(wsn/2), y2-(wcs/2)]

where 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 hence 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 is immediately below (y increasing direction). Note that this description is a mathematical model describing the pixels that are drawn for a wide line and does not imply that trigonometry is required to implement such a model. Real or fixed point arithmetic is recommended for computing the corners of the line endpoints for lines greater than one pixel in width.

Thin lines (zero line-width) are "one pixel wide" lines drawn using an unspecified, device dependent algorithm (for example, Bresenham). There are only two constraints on this algorithm. First, if a line is drawn unclipped from [x1,y1] to [x2,y2] and another line is drawn unclipped from [x1+dx, y1+dy] to [x2+dx,y2+dy], then 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. Second, 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.

Note that 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 and join styles, but this property is not guaranteed for thin lines. Also note that "jags" in adjacent wide lines will always line up properly, but this property is not guaranteed for thin lines. A line-width of zero differs from a line-width of one in which pixels are drawn. In general, drawing a thin line will be faster than drawing a wide line of width one, but thin lines may not mix well aesthetically 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 segments of a line are drawn​

Solid:  the full path of the line is drawn
DoubleDash: the full path of the line is drawn, but the
segments defined by the even dashes are
filled differently than the segments defined
by the odd dashes (see fill-style)
OnOffDash: only the segments defined by the even dashes
are drawn, and cap-style applies to each

individual segment (except NotLast is treated as Butt for internal caps)

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

NotLast: equivalent to Butt, except that for a
line-width of zero or one the final endpoint is
not drawn
Butt: square at the endpoint, with no projection beyond
Round: a circular arc with diameter equal to the
line-width, centered on the endpoint; equivalent
to Butt for line-width zero or one
Projecting: square at the end, but the path continues
beyond the endpoint for a distance equal to
half the line-width; equivalent to Butt for
line-width zero or one

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

Miter: the outer edges of the two lines extend to meet at
an angle
Round: a circular arc with diameter equal to the
line-width, centered on the joinpoint
Bevel: Butt endpoint styles, and then the triangular
"notch" filled

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 gcontext (else a Match error). The stipple pixmap must have depth one, and must have the same root as the gcontext (else a Match error). For stipple operations, the stipple pattern is tiled in a single plane, and acts as an additional clip mask to be ANDed with the clip-mask. Any size pixmap can be used for tiling or stippling, although some sizes may be faster to use than others.

The fill-style defines the contents of the source for line, text, and fill requests. For all text and fill requests (PolyText8, PolyText16, PolyFillRectangle, FillPoly, PolyFillArc), for line requests (PolyLine, PolySegment, PolyRectangle, PolyArc) with line-style Solid, and for the even dashes for line requests with line-style OnOffDash or DoubleDash:

Solid: foreground
Tiled: tile
OpaqueStippled: 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
Stippled: foreground masked by stipple

For the odd dashes for line requests with line-style DoubleDash:

Solid: background
Tiled: same as for even dashes
OpaqueStippled: same as for even dashes
Stippled: background masked by stipple

The dash-list value allowed here is actually a simplified form of the more general patterns that can be set with SetDashes.Specifying a value of N here is equivalent to specifying the two element list [N, N] in SetDashes. The value must be non-zero. The meaning of dash-offset and dash-list are explained in the SetDashes request.

The clip-mask restricts writes to the destination drawable; only pixels where the clip-mask has a one bit are drawn. It 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. If a pixmap is specified as the clip-mask, it must have depth one and have the same root as the gcontext (else a Match error). The clip-mask can also be set with the SetClipRectangles request.

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 drawing through subwindow boundaries. The use of IncludeInferiors on a window of one depth with mapped inferiors of differing depth is not illegal, but the semantics isundefined by the core protocol.

The fill-rule defines what pixels are inside (i.e., are drawn) for paths given in FillPoly requests. EvenOdd means a point is inside if an infinite ray with the point as origin crosses the path an odd number of times. For Winding, a point is inside if an infinite ray with the point as origin crosses an unequal number of clockwise and counterclockwise directed path segments. For both rules, 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 along 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 PolyFillArc request.

The graphics-exposures flag controls GraphicsExposure event generation for CopyArea and CopyPlane requests (and any similar requests defined by extensions).

The default component values are​

function: Copy
plane-mask: all ones
foreground: 0
background: 1
line-width: 0
line-style: Solid
cap-style: Butt
join-style: Miter
fill-style: Solid
full-rule: EvenOdd
arc-mode: PieSlice
tile: pixmap of unspecified size filled with forground
pixell (i.e., client specified pixel if any,
else 0)
stipple: pixmap of unspecified size filled with ones
tile-stipple-x-origin: 0
tile-stipple-y-origin: 0
font: <implementation dependent>
subwindow-mode: ClipByChildren
graphics-exposures: True
clip-x-origin: 0
clip-y-origin: 0
clip-mask: None
dash-offset: 0
dash-list: 4 (i.e., the list [4, 4])

Storing a pixmap in a gcontext 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 gcontext. If the pixmap is used simultaneously in a graphics request as both a destination and as a tile or stipple. the results are not defined.

It is quite likely that some amount of gcontext information will be cached in display hardware, and that such hardware can only cache a small number of gcontexts. Given the number and complexity of components, clients should view switching between gcontexts with nearly identical state as significantly more expensive than making minor changes to a single gcontext.

ChangeGC​

gc: GCONTEXT
value-mask: BITMASK
value-list: LISTofVALUE
Errors: GContext, Pixmap, Font, Match, Value, Alloc

Changes components in gc. The value-mask and value-list specify which components are to be changed. The values and restrictions are the same as for CreateGC.

Changing the clip-mask also overrides any previous SetClipRectangles request on the context. Changing the dash-offset or dash-list overrides any previous SetDashes 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.

CopyGC​

src-gc, dst-gc: GCONTEXT
value-mask: BITMASK
Errors: GContext, Value, Match, Alloc

Copies components from src-gc to dst-gc. The value-mask specifies which components to copy, as for CreateGC. The two gcontexts must have the same root and the same depth (else a Match error).

SetDashes​

gc: GCONTEXT
dash-offset: CARD16
dash-list: LISTofCARD8
Errors: GContext, Value, Alloc

Sets the dash-offset and dash-list in gc for dashed line styles. The initial and alternating elements of the dash-list are the "even" dashes, the others are the "odd" dashes. All of the elements must be non-zero. 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 segments combined with a join-style, but is reset to the dash-offset each time a cap-style is applied.

SetClipRectangles​

gc: GCONTEXT
clip-x-origin, clip-y-origin: INT16
rectangles: LISTofRECTANGLE
ordering: {UnSorted, YSorted, YXSorted, YXBanded}
Errors: GContext, Value, Alloc, Match

Changes clip-mask in gc to the specified list of rectangles and sets the clip origin. Output will be 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 non-intersecting, or graphics results will be undefined.

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 server may generate a Match error, but 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 non-decreasing in their Y origin. YXSorted additionally constrains YSorted order in that all rectangles with an equal Y origin are non-decreasing in their X origin. YXBanded additionally constrains YXSorted by requiring that for every possible Y scanline, all rectangles that include that scanline have identical Y origins and Y extents.

FreeGC​

gc: GCONTEXT
Errors: GContext

Deletes the association between the resource id and the gcontext, and destroys the gcontext.