Cairo.Pattern

Entities

Simple Types

Subprograms

Description

------------------------------ Pattern creation functions -- ------------------------------

Add_Color_Stop_Rgb

procedure Add_Color_Stop_Rgb
  (Pattern : Cairo_Pattern;
   Offset  : Gdouble;
   Red     : Gdouble;
   Green   : Gdouble;
   Blue    : Gdouble)

Adds an opaque color stop to a gradient pattern. The offset specifies the location along the gradient's control vector. For example, a linear gradient's control vector is from (X0,Y0) to (X1,Y1) while a radial gradient's control vector is from any point on the start circle to the corresponding point on the end circle.

The color is specified in the same way as in Cairo.Set_Source_Rgb.

If two (or more) stops are specified with identical offset values, they will be sorted according to the order in which the stops are added, (stops added earlier will compare less than stops added later). This can be useful for reliably making sharp color transitions instead of the typical blend.

Note: If the pattern is not a gradient pattern, (eg. a linear or radial pattern), then the pattern will be put into an error status with a status of Cairo_Status_Pattern_Type_Mismatch.

Parameters
Pattern

a Cairo_Pattern

Offset

an Offset in the range [0.0 .. 1.0]

Red

Red component of color

Green

Green component of color

Blue

Blue component of color

Add_Color_Stop_Rgba

procedure Add_Color_Stop_Rgba
  (Pattern : Cairo_Pattern;
   Offset  : Gdouble;
   Red     : Gdouble;
   Green   : Gdouble;
   Blue    : Gdouble;
   Alpha   : Gdouble)

Adds a translucent color stop to a gradient pattern. The offset specifies the location along the gradient's control vector. For example, a linear gradient's control vector is from (x0,y0) to (x1,y1) while a radial gradient's control vector is from any point on the start circle to the corresponding point on the end circle.

The color is specified in the same way as in Cairo_Set_Source_Rgba.

If two (or more) stops are specified with identical offset values, they will be sorted according to the order in which the stops are added, (stops added earlier will compare less than stops added later). This can be useful for reliably making sharp color transitions instead of the typical blend.

Note: If the pattern is not a gradient pattern, (eg. a linear or radial pattern), then the pattern will be put into an error status with a status of Cairo_Status_Pattern_Type_Mismatch.

Parameters
Pattern

a Cairo_Pattern

Offset

an Offset in the range [0.0 .. 1.0]

Red

Red component of color

Green

Green component of color

Blue

Blue component of color

Alpha

Alpha component of color

Cairo_Extend

type Cairo_Extend is
  (Cairo_Extend_None,
   Cairo_Extend_Repeat,
   Cairo_Extend_Reflect,
   Cairo_Extend_Pad
  );
Enumeration Literal
Cairo_Extend_None

Pixels outside of the source pattern are fully transparent

Cairo_Extend_Repeat

The pattern is tiled by repeating

Cairo_Extend_Reflect

The pattern is tiled by reflecting at the edges (Implemented for surface patterns since 1.6)

Cairo_Extend_Pad

Cairo_Filter

type Cairo_Filter is
  (Cairo_Filter_Fast,
   Cairo_Filter_Good,
   Cairo_Filter_Best,
   Cairo_Filter_Nearest,
   Cairo_Filter_Bilinear,
   Cairo_Filter_Gaussian
  );
Enumeration Literal
Cairo_Filter_Fast

A high-performance filter, with quality similar to Cairo_Filter_Nearest

Cairo_Filter_Good

A reasonable-performance filter, with quality similar to Cairo_Filter_Bilinear

Cairo_Filter_Best

The highest-quality available, performance may not be suitable for interactive use.

Cairo_Filter_Nearest

Nearest-neighbor filtering

Cairo_Filter_Bilinear

Linear interpolation in two dimensions

Cairo_Filter_Gaussian

Cairo_Pattern_Type

type Cairo_Pattern_Type is
  (Cairo_Pattern_Type_Solid,
   Cairo_Pattern_Type_Surface,
   Cairo_Pattern_Type_Linear,
   Cairo_Pattern_Type_Radial
  );
Enumeration Literal
Cairo_Pattern_Type_Solid

The pattern is a solid (uniform) color. It may be opaque or translucent.

Cairo_Pattern_Type_Surface

The pattern is a based on a surface (an image).

Cairo_Pattern_Type_Linear

The pattern is a linear gradient.

Cairo_Pattern_Type_Radial

Create_For_Surface

function Create_For_Surface
  (Surface : Cairo_Surface)
   return    Cairo_Pattern

Create a new Cairo_Pattern for the given surface.

This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use Cairo.Pattern.Status.

Parameters
Surface

the Surface

Return Value

the newly created Cairo_Pattern if successful, or an error pattern in case of no memory. The caller owns the returned object and should call Cairo.Pattern.Destroy when finished with it.

Create_Linear

function Create_Linear
  (X0   : Gdouble;
   Y0   : Gdouble;
   X1   : Gdouble;
   Y1   : Gdouble)
   return Cairo_Pattern

Create a new linear gradient Cairo_Pattern along the line defined by (X0, Y0) and (X1, Y1). Before using the gradient pattern, a number of color stops should be defined using Cairo.Pattern.Add_Color_Stop_Rgb or Cairo.Pattern.Add_Color_Stop_Rgba.

Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with Cairo.Pattern.Set_Matrix.

This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use Cairo.Pattern.Status.

Parameters
X0

x coordinate of the start point

Y0

y coordinate of the start point

X1

x coordinate of the end point

Y1

y coordinate of the end point

Return Value

the newly created Cairo_Pattern if successful, or an error pattern in case of no memory. The caller owns the returned object and should call Cairo.Pattern.Destroy when finished with it.

Create_Radial

function Create_Radial
  (Cx0     : Gdouble;
   Cy0     : Gdouble;
   Radius0 : Gdouble;
   Cx1     : Gdouble;
   Cy1     : Gdouble;
   Radius1 : Gdouble)
   return    Cairo_Pattern

Creates a new radial gradient Cairo_Pattern between the two circles defined by (Cx0, Cy0, Radius0) and (Cx1, Cy1, Radius1). Before using the gradient pattern, a number of color stops should be defined using Cairo.Pattern.Add_Color_Stop_Rgb or Cairo.Pattern.Add_Color_Stop_Rgba.

Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with Cairo.Pattern.Set_Matrix.

This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use Cairo.Pattern.Status.

Parameters
Cx0

X coordinate for the center of the start circle

Cy0

Y coordinate for the center of the start circle

Radius0

radius of the start circle

Cx1

X coordinate for the center of the end circle

Cy1

Y coordinate for the center of the end circle

Radius1

radius of the end circle

Return Value

the newly created Cairo_Pattern if successful, or an error pattern in case of no memory. The caller owns the returned object and should call Cairo.Pattern.Destroy when finished with it.

Create_Rgb

function Create_Rgb
  (Red   : Gdouble;
   Green : Gdouble;
   Blue  : Gdouble)
   return  Cairo_Pattern

Creates a new Cairo_Pattern corresponding to an opaque color. The color components are floating point numbers in the range 0 to 1. If the values passed in are outside that range, they will be clamped.

This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use Cairo.Pattern.Status.

Parameters
Red

Red component of the color

Green

Green component of the color

Blue

Blue component of the color

Return Value

the newly created Cairo_Pattern if successful, or an error pattern in case of no memory. The caller owns the returned object and should call Cairo.Pattern.Destroy when finished with it.

Create_Rgba

function Create_Rgba
  (Red   : Gdouble;
   Green : Gdouble;
   Blue  : Gdouble;
   Alpha : Gdouble)
   return  Cairo_Pattern

Creates a new Cairo_Pattern corresponding to a translucent color. The color components are floating point numbers in the range 0 to

  1. If the values passed in are outside that range, they will be

clamped.

This function will always return a valid pointer, but if an error occurred the pattern status will be set to an error. To inspect the status of a pattern use Cairo.Pattern.Status.

Parameters
Red

Red component of the color

Green

Green component of the color

Blue

Blue component of the color

Alpha

Alpha component of the color

Return Value

the newly created Cairo_Pattern if successful, or an error pattern in case of no memory. The caller owns the returned object and should call Cairo.Pattern.Destroy when finished with it.

Destroy

procedure Destroy (Pattern : Cairo_Pattern)

Decreases the reference count on pattern by one. If the result is zero, then pattern and all associated resources are freed. See Cairo.Pattern.Reference.

Parameters
Pattern

a Cairo_Pattern

Get_Color_Stop_Count

function Get_Color_Stop_Count
  (Pattern : Cairo_Pattern;
   Count   : access Gint)
   return    Cairo_Status

Gets the number of color stops specified in the given gradient pattern.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

Count

return value for the number of color stops, or NULL

Return Value

Cairo_Status_Success, or Cairo_Status_Pattern_Type_Mismatch if pattern is not a gradient pattern.

Get_Color_Stop_Rgba

function Get_Color_Stop_Rgba
  (Pattern : Cairo_Pattern;
   Index   : Gint;
   Offset  : access Gdouble;
   Red     : access Gdouble;
   Green   : access Gdouble;
   Blue    : access Gdouble;
   Alpha   : access Gdouble)
   return    Cairo_Status

Gets the color and offset information at the given index for a gradient pattern. Values of index are 0 to 1 less than the number returned by Cairo.Pattern.Get_Color_Stop_Count.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

Index

Index of the stop to return data for

Offset

return value for the Offset of the stop, or null

Red

return value for Red component of color, or null

Green

return value for Green component of color, or null

Blue

return value for Blue component of color, or null

Alpha

return value for Alpha component of color, or null

Return Value

Cairo_Status_Success, or Cairo_Status_Invalid_Index if index is not valid for the given pattern. If the pattern is not a gradient pattern, Cairo_Status_Pattern_Type_Mismatch is returned.

Get_Extend

function Get_Extend (Pattern : Cairo_Pattern) return Cairo_Extend

Gets the current extend mode for a pattern. See Cairo_Extend for details on the semantics of each extend strategy.

Parameters
Pattern

a Cairo_Pattern

Return Value

the current extend strategy used for drawing the pattern.

Get_Filter

function Get_Filter (Pattern : Cairo_Pattern) return Cairo_Filter

Gets the current filter for a pattern. See Cairo_Filter for details on each filter.

Parameters
Pattern

a Cairo_Pattern

Return Value

the current filter used for resizing the pattern.

Get_Linear_Points

function Get_Linear_Points
  (Pattern : Cairo_Pattern;
   X0      : access Gdouble;
   Y0      : access Gdouble;
   X1      : access Gdouble;
   Y1      : access Gdouble)
   return    Cairo_Status

Gets the gradient endpoints for a linear gradient.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

X0

return value for the x coordinate of the first point, or null

Y0

return value for the y coordinate of the first point, or null

X1

return value for the x coordinate of the second point, or null

Y1

return value for the y coordinate of the second point, or null

Return Value

Cairo_Status_Success, or Cairo_Status_Pattern_Type_Mismatch if pattern is not a linear gradient pattern.

Get_Matrix

procedure Get_Matrix
  (Pattern : Cairo_Pattern;
   Matrix  : access Cairo_Matrix)

Stores the pattern's transformation matrix into matrix.

Parameters
Pattern

a Cairo_Pattern

Matrix

return value for the Matrix

Get_Radial_Circles

function Get_Radial_Circles
  (Pattern : Cairo_Pattern;
   X0      : access Gdouble;
   Y0      : access Gdouble;
   R0      : access Gdouble;
   X1      : access Gdouble;
   Y1      : access Gdouble;
   R1      : access Gdouble)
   return    Cairo_Status

Gets the gradient endpoint circles for a radial gradient, each specified as a center coordinate and a radius.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

X0

return value for the x coordinate of the center of the first circle, or null

Y0

return value for the y coordinate of the center of the first circle, or null

R0

return value for the radius of the first circle, or null

X1

return value for the x coordinate of the center of the second circle, or null

Y1

return value for the y coordinate of the center of the second circle, or null

R1

return value for the radius of the second circle, or null

Return Value

Cairo_Status_Success, or Cairo_Status_Pattern_Type_Mismatch if pattern is not a radial gradient pattern.

Get_Reference_Count

function Get_Reference_Count (Pattern : Cairo_Pattern) return Guint

Returns the current reference count of pattern.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

Return Value

the current reference count of pattern. If the object is a nil object, 0 will be returned.

Get_Rgba

function Get_Rgba
  (Pattern : Cairo_Pattern;
   Red     : access Gdouble;
   Green   : access Gdouble;
   Blue    : access Gdouble;
   Alpha   : access Gdouble)
   return    Cairo_Status

Gets the solid color for a solid color pattern.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

Red

return value for Red component of color, or null

Green

return value for Green component of color, or null

Blue

return value for Blue component of color, or null

Alpha

return value for Alpha component of color, or null

Return Value

Cairo_Status_Success, or Cairo_Status_Pattern_Type_Mismatch if the pattern is not a solid color pattern.

Get_Surface

function Get_Surface
  (Pattern : Cairo_Pattern;
   Surface : Cairo_Surface)
   return    Cairo_Status

Gets the surface of a surface pattern. The reference returned in surface is owned by the pattern; the caller should call Cairo.Surface.Reference if the surface is to be retained.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

Surface

return value for Surface of pattern, or null

Return Value

Cairo_Status_Success, or Cairo_Status_Pattern_Type_Mismatch if the pattern is not a surface pattern.

Get_Type

function Get_Type (Pattern : Cairo_Pattern) return Cairo_Pattern_Type

This function returns the type a pattern. See Cairo_Pattern_Type for available types.

@since 1.2

Parameters
Pattern

a Cairo_Pattern

Return Value

The type of pattern.

Get_User_Data

function Get_User_Data
  (Pattern : Cairo_Pattern;
   Key     : access Cairo_User_Data_Key) return System.Address

Return user data previously attached to pattern using the specified key. If no user data has been attached with the given key this function returns System.Null_Address.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

Key

the address of the Cairo_User_Data_Key the user data was attached to

Return Value

the user data previously attached or System.Null_Address.

Reference

function Reference (Pattern : Cairo_Pattern) return Cairo_Pattern

Increases the reference count on pattern by one. This prevents pattern from being destroyed until a matching call to Cairo.Pattern.Destroy is made.

The number of references to a Cairo_Pattern can be get using Cairo.Pattern.Get_Reference_Count.

Parameters
Pattern

a Cairo_Pattern

Return Value

the referenced Cairo_Pattern.

Set_Extend

procedure Set_Extend (Pattern : Cairo_Pattern; Extend : Cairo_Extend)

Sets the mode to be used for drawing outside the area of a pattern. See Cairo_Extend for details on the semantics of each extend strategy.

The default extend mode is Cairo_Extend_None for surface patterns and Cairo_Extend_PAd for gradient patterns.

Parameters
Pattern

a Cairo_Pattern

Extend

a Cairo_Extend describing how the area outside of the pattern will be drawn

Set_Filter

procedure Set_Filter (Pattern : Cairo_Pattern; Filter : Cairo_Filter)

Sets the filter to be used for resizing when using this pattern. See Cairo_Filter for details on each filter.

Note that you might want to control filtering even when you do not have an explicit Cairo_Pattern object, (for example when using Cairo_Set_Source_Surface). In these cases, it is convenient to use Cairo_Get_Source to get access to the pattern that cairo creates implicitly. For example:

Cairo_Set_Source_Surface (Cr, Image, X, Y); Cairo.Pattern.Set_Filter (Cairo_Get_Source (Cr), Cairo_Filter_Nearest);

Parameters
Pattern

a Cairo_Pattern

Filter

a Cairo_Filter describing the Filter to use for resizing the pattern

Set_Matrix

procedure Set_Matrix
  (Pattern : Cairo_Pattern;
   Matrix  : access Cairo_Matrix)

Sets the pattern's transformation matrix to matrix. This matrix is a transformation from user space to pattern space.

When a pattern is first created it always has the identity matrix for its transformation matrix, which means that pattern space is initially identical to user space.

Important: Please note that the direction of this transformation matrix is from user space to pattern space. This means that if you imagine the flow from a pattern to user space (and on to device space), then coordinates in that flow will be transformed by the inverse of the pattern matrix.

For example, if you want to make a pattern appear twice as large as it does by default the correct code to use is:

Cairo.Matrix.Init_Scale (Matrix, 0.5, 0.5); Cairo.Pattern.Set_Matrix (Pattern, Matrix);

Meanwhile, using values of 2.0 rather than 0.5 in the code above would cause the pattern to appear at half of its default size.

Also, please note the discussion of the user-space locking semantics of Cairo_Set_Source.

Parameters
Pattern

a Cairo_Pattern

Matrix

a Cairo_Matrix

Set_User_Data

function Set_User_Data
  (Pattern   : Cairo_Pattern;
   Key       : access Cairo_User_Data_Key;
   User_Data : System.Address;
   Destroy   : Cairo_Destroy_Func) return Cairo_Status

Attach user data to pattern. To remove user data from a surface, call this function with the key that was used to set it and Null_Address for data.

@since 1.4

Parameters
Pattern

a Cairo_Pattern

Key

the address of a Cairo_User_Data_Key to attach the user data to

User_Data

the user data to attach to the Cairo_Pattern

Destroy

a Cairo_Destroy_Func which will be called when the Cairo_Context is destroyed or when new user data is attached using the same key.

Return Value

Cairo_Status_Success or Cairo_Status_No_Memory if a slot could not be allocated for the user data.

Status

function Status (Pattern : Cairo_Pattern) return Cairo_Status

Checks whether an error has previously occurred for this pattern.

Parameters
Pattern

a Cairo_Pattern

Return Value

Cairo_Status_Success, Cairo_Status_No_Memory, or Cairo_Status_Pattern_Type_Mismatch.