Up: cl-cffi-gtk4 API documentation

Package cairo

Cairo is a software library used to provide a vector graphics-based, device-independent API for software developers. It is designed to provide primitives for 2-dimensional drawing across a number of different backends. Cairo is designed to use hardware acceleration when available. This is the API documentation of a Lisp binding to Cairo.

About This Package

Drawing
Fonts
Surfaces
Utilities

Drawing


The Cairo drawing context

The cairo:context-t structure is the main object used when drawing with Cairo. To draw with Cairo, you create a cairo:context-t instance, set the target surface, and drawing options for the cairo:context-t instance, create shapes with functions like the cairo:move-to and cairo:line-to functions, and then draw shapes with the cairo:stroke or cairo:fill functions.

The cairo:context-t instance can be pushed to a stack via the cairo:save function. They may then safely be changed, without losing the current state. Use the cairo:restore function to restore to the saved state.

Types and functions for Cairo drawing

The cairo:antialias-t enumeration specifies the type of antialiasing to do when rendering text or shapes. ...

The cairo:fill-rule-t enumeration is used to select how paths are filled. ...

The cairo:line-cap-t enumeration specifies how to render the endpoints of the path when stroking. ...

The cairo:line-join-t enumeration specifies how to render the junction of two lines when stroking. ...

The cairo:operator-t enumeration is used to set the compositing operator for all Cairo drawing operations. ...

The cairo:context-t structure contains the current state of the rendering device, including coordinates of yet to be drawn shapes. ...

The cairo:with-context macro allocates a new cairo:context-t instance for the given target and executes the body that uses the Cairo context. ...

Creates a new Cairo context with all graphics state parameters set to default values and with target as a target surface. ...

Increases the reference count on the Cairo context by one. ...

Returns the current reference count of the Cairo context. ...

Decreases the reference count on the Cairo context by one. ...

Checks whether an error has previously occurred for the Cairo context. ...

Makes a copy of the current state of cr and saves it on an internal stack of saved states for cr. ...

Restores cr to the state saved by a preceding call to the cairo:save function and removes that state from the stack of saved states. ...

Gets the target surface for the Cairo context as passed to the cairo:create function. ...

Temporarily redirects drawing to an intermediate surface known as a group. ...

Temporarily redirects drawing to an intermediate surface known as a group. ...

Terminates the redirection begun by a call to the cairo:push-group or cairo:push-group-with-content function and returns a new pattern containing the results of all drawing operations performed to the group. ...

Terminates the redirection begun by a call to the cairo:push-group or cairo:push-group-with-content function and installs the resulting pattern as the source pattern in the given Cairo context. ...

Gets the current destination surface for the Cairo context. ...

Sets the source pattern within the Cairo context to an opaque color. ...

Sets the source pattern within the Cairo context to a translucent color. ...

The cairo:source function gets the current source pattern for cr. ...

This is a convenience function for creating a pattern from surface and setting it as the source in cr with the cairo:source function. ...

The cairo:antialias function gets the current shape antialiasing mode of the rasterizer used for drawing shapes. ...

The cairo:dash function gets the current dash list to be used by the cairo:stroke function. ...

This function returns the length of the dash list in cr, 0 if dashing is not currently in effect. ...

The cairo:fill-rule function gets the current fill rule within the Cairo context. ...

The cairo:line-cap function gets the current line cap style within the Cairo context. ...

The cairo:line-join funcion gets the current line join style within the Cairo context. ...

The cairo:line-width function returns the current line width value within the Cairo context. ...

The cairo:hairline function returns whether or not hairline mode is set within the Cairo context. ...

The cairo:miter-limit function gets the current miter limit within the Cairo context. ...

The cairo:operator function gets the current compositing operator for a Cairo context to be used for all drawing operations. ...

The cairo:tolerance function gets the current tolerance value used when converting paths into trapezoids. ...

Establishes a new clip region by intersecting the current clip region with the current path as it would be filled by the cairo:fill function and according to the current fill rule, see the cairo:fill-rule function. ...

Establishes a new clip region by intersecting the current clip region with the current path as it would be filled by the cairo:fill function and according to the current fill rule. ...

Computes a bounding box in user coordinates covering the area inside the current clip. ...

Tests whether the given point is inside the area that would be visible through the current clip, that is, the area that would be filled by a call to the cairo:paint function. ...

Reset the current clip region to its original, unrestricted state. ...

Gets the current clip region as a list of rectangles in user coordinates. ...

A drawing operator that fills the current path according to the current fill rule, each sub-path is implicitly closed before being filled. ...

A drawing operator that fills the current path according to the current fill rule, each sub-path is implicitly closed before being filled. ...

Computes a bounding box in user coordinates covering the area that would be affected, the "inked" area, by a cairo:fill operation given the current path and fill parameters. ...

Tests whether the given point is inside the area that would be affected by a cairo:fill operation given the current path and filling parameters. ...

A drawing operator that paints the current source using the alpha channel of pattern as a mask. ...

A drawing operator that paints the current source using the alpha channel of surface as a mask. ...

A drawing operator that paints the current source everywhere within the current clip region. ...

A drawing operator that paints the current source everywhere within the current clip region using a mask of constant alpha value alpha. ...

A drawing operator that strokes the current path according to the current line width, line join, line cap, and dash settings. ...

A drawing operator that strokes the current path according to the current line width, line join, line cap, and dash settings. ...

Computes a bounding box in user coordinates covering the area that would be affected, the "inked" area, by a cairo:stroke operation given the current path and stroke parameters. ...

Tests whether the given point is inside the area that would be affected by a cairo:stroke operation given the current path and stroking parameters. ...

Emits the current page for backends that support multiple pages, but does not clear it, so, the contents of the current page will be retained for the next page too. ...

Emits and clears the current page for backends that support multiple pages. ...


Paths

The cairo:path-data-type-t enumeration is used to describe the type of one portion of a path when represented as a cairo:path-t instance. ...

The cairo:path-data-t structure is used to represent the path data inside a cairo:path-t instance. ...

The data structure for holding a path. ...

Accessor of the status slot of the cairo:path-t structure. ...

Accessor of the data slot of the cairo:path-t structure. ...

Accessor of the numdata slot of the cairo:path-t structure. ...

Creates a copy of the current path and returns it to the user as a cairo:path-t instance. ...

Gets a flattened copy of the current path and returns it to the user as a cairo:path-t instance. ...

Immediately releases all memory associated with path. ...

Creates a list with the path information from a cairo:path-t instance. ...

Append path onto the current path. ...

Returns whether a current point is defined on the current path. ...

Gets the current point of the current path, which is conceptually the final point reached by the path so far. ...

Clears the current path. ...

Begin a new sub-path. ...

Adds a line segment to the path from the current point to the beginning of the current sub-path, the most recent point passed to the cairo:move-to function, and closes this sub-path. ...

Computes a bounding box in user-space coordinates covering the points on the current path. ...

Begin a new sub-path. ...

Begin a new sub-path. ...

Adds a line to the path from the current point to position (x,y) in user-space coordinates. ...

Relative-coordinate version of the cairo:line-to function. ...

Adds a cubic Bezier spline to the path from the current point to position (x3,y3) in user-space coordinates, using (x1,y1) and (x2,y2) as the control points. ...

Relative-coordinate version of the cairo:curve-to function. ...

Adds a closed sub-path rectangle of the given size to the current path at position (x,y) in user-space coordinates. ...

Adds a circular arc of the given radius to the current path. ...

Adds a circular arc of the given radius to the current path. ...

Adds closed paths for the glyphs to the current path. ...

Adds closed paths for text to the current path. ...


Introduction to pattern

The cairo:pattern-t structure is the paint with which Cairo draws. The primary use of patterns is as the source for all Cairo drawing operations, although they can also be used as masks, that is, as the brush too. A Cairo pattern is created by using one of the many constructors, of the form cairo:pattern-create-type or implicitly through the cairo:set-source-type functions.

Types and functions for pattern

The cairo:extend-t enumeration is used to describe how pattern color/alpha will be determined for areas "outside" the natural area, of the pattern for example, outside the surface bounds or outside the gradient geometry. ...

The cairo:filter-t enumeration is used to indicate what filtering should be applied when reading pixel values from patterns. ...

The cairo:pattern-type-t enumeration is used to describe the type of a given pattern. ...

The cairo:pattern-t structure represents a source when drawing onto a surface. ...

Increases the reference count on pattern by one. ...

Returns the current reference count of pattern. ...

Decreases the reference count on pattern by one. ...

Checks whether an error has previously occurred for this pattern. ...

This function returns the type of a pattern. ...

The cairo:pattern-extend function gets the current extend mode for a pattern. ...

The cairo:pattern-filter function gets the current filter for pattern. ...

The cairo:pattern-matrix function gets the transformation matrix of the pattern. ...

Adds an opaque color stop to a gradient pattern. ...

Adds a translucent color stop to a gradient pattern. ...

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

Gets the color and offset information at the given index for a gradient pattern. ...

Creates a new cairo:pattern-t instance corresponding to an opaque color. ...

Creates a new cairo:pattern-t instance corresponding to a translucent color. ...

Gets the color for a solid color pattern. ...

Create a new cairo:pattern-t instance for the given surface. ...

Gets the surface of a surface pattern. ...

Create a new linear gradient cairo:pattern-t instance along the line defined by (x0,y0) and (x1,y1). ...

Gets the gradient endpoints for a linear gradient. ...

Creates a new radial gradient cairo:pattern-t instance between the two circles defined by x0,y0,r0) and (x1,y1,r1). ...

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

Create a new mesh pattern. ...

Begin a patch in a mesh pattern. ...

Indicates the end of the current patch in a mesh pattern. ...

Define the first point of the current patch in a mesh pattern. ...

Adds a line to the current patch from the current point to position (x,y) in pattern-space coordinates. ...

Adds a cubic Bézier spline to the current patch from the current point to position (x3,y3) in pattern-space coordinates, using (x1,y1) and (x2,y2) as the control points. ...

Gets the control point point of patch index for a mesh pattern. ...

Set an internal control point of the current patch. ...

Gets the color information in corner corner of patch index for a mesh pattern. ...

Sets the color of a corner of the current patch in a mesh pattern. ...

Sets the color of a corner of the current patch in a mesh pattern. ...

Gets the number of patches specified in the given mesh pattern. ...

Gets the path defining the patch patch-num for a mesh pattern. ...


Indroduction to Regions

Regions are a simple graphical data type representing an area of integer aligned rectangles. They are often used on raster surfaces to track areas of interest, such as change or clip areas.

Types and functions for Regions

Used as the return value for the cairo:region-contains-rectangle function. ...

The cairo:region-t structure represents a set of integer aligned rectangles. ...

Allocates a new empty region instance. ...

Allocates a new cairo:region-t instance containing the given rectangle. ...

Allocates a new cairo:region-t instance containing the union of all given rectangles. ...

Allocates a new region instance copying the area from region. ...

Increases the reference count on region by one. ...

Destroys a cairo:region-t instance. ...

Checks whether an error has previous occurred for this region instance. ...

Gets the bounding rectangle of region as a list of the coordinates. ...

Returns the number of rectangles contained in region. ...

Returns the nth rectangle from the region as a list with the coordinates of the rectangle. ...

Checks whether region is empty. ...

Checks whether (x,y) is contained in region. ...

Checks whether the given rectangle is inside, outside or partially contained in region. ...

Compares whether region1 is equivalent to region2. ...

Translates the region by (dx, dy). ...

Computes the intersection of region with other and places the result in region. ...

Computes the intersection of region with the given rectangle and places the result in region. ...

Subtracts other from region and places the result in region. ...

Subtracts rectangle from region and places the result in region. ...

Computes the union of region with other and places the result in region. ...

Computes the union of region with rectangle and places the result in region. ...

Computes the exclusive difference of region with other and places the result in region. ...

Computes the exclusive difference of region with rectangle and places the result in region. ...


Introduction to Transformations

The current transformation matrix, CTM, is a two-dimensional affine transformation that maps all coordinates and other drawing instruments from the user space into the surface's canonical coordinate system, also known as the device space.

Functions for Transformations

Modifies the current transformation matrix (CTM) by translating the user-space origin by (tx,ty). ...

Modifies the current transformation matrix (CTM) by scaling the x and y user-space axes by sx and sy respectively. ...

Modifies the current transformation matrix (CTM) by rotating the user-space axes by angle radians. ...

Modifies the current transformation matrix (CTM) by applying matrix as an additional transformation. ...

The cairo:matrix function gets the current transformation matrix (CTM). ...

Resets the current transformation matrix (CTM) by setting it equal to the identity matrix. ...

Transform a coordinate from user space to device space by multiplying the given point by the current transformation matrix (CTM). ...

Transform a distance vector from user space to device space. ...

Transform a coordinate from device space to user space by multiplying the given point by the inverse of the current transformation matrix (CTM). ...

Transform a distance vector from device space to user space. ...


Introduction to Text

The functions with text in their name form Cairo's toy text API. The toy API takes UTF-8 encoded text and is limited in its functionality to rendering simple left-to-right text with no advanced features. That means for example that most complex scripts like Hebrew, Arabic, and Indic scripts are out of question. No kerning or correct positioning of diacritical marks either. The font selection is pretty limited too and does not handle the case that the selected font does not cover the characters in the text. This set of functions are really that, a toy text API, for testing and demonstration purposes. Any serious application should avoid them.

The functions with glyphs in their name form Cairo's low-level text API. The low-level API relies on the user to convert text to a set of glyph indexes and positions. This is a very hard problem and is best handled by external libraries, like the pangocairo library that is part of the Pango text layout and rendering library. Pango is available from the Pango library.

Types and functions for Text

Specifies variants of a font face based on their slant. ...

Specifies variants of a font face based on their weight. ...

The cairo:glyph-t structure holds information about a single glyph when drawing or measuring text. ...

Selects a family and style of font from a simplified description as a family name, slant and weight. ...

Sets the current font matrix to a scale by a factor of size, replacing any font matrix previously set with the cairo:set-font-size or cairo:font-matrix functions. ...

The cairo:font-matrix function stores the current font matrix into matrix and returns the cairo:matrix-t instance. ...

The cairo:font-options function retrieves font rendering options for the Cairo context. ...

The cairo:font-face function gets the current font face for a Cairo context. ...

The cairo:scaled-font function gets the current scaled font for the Cairo context. ...

A drawing operator that generates the shape from a string of UTF-8 characters, rendered according to the current font face, font size (font matrix), and font options. ...

A drawing operator that generates the shape from a list of glyphs, rendered according to the current font face, font size (font matrix), and font options. ...

Gets the font extents for the currently selected font. ...

Gets the extents for a string of text. ...

Gets the extents for a list of glyphs. ...

The cairo:with-toy-font-face macro allocates a new cairo:font-face-t instance and executes the body that uses the toy font face. ...

Creates a font face from a triplet of family, slant, and weight. ...

Gets the family name of a toy font face. ...

Gets the slant of a toy font face. ...

Gets the weight of a toy font face. ...

Fonts


Indroduction to Font Faces

Base class for font faces. The cairo:font-face-t structure represents a particular font at a particular weight, slant, and other characteristic but no size, transformation, or size.

Font faces are created using font-backend-specific constructors, typically of the form cairo:backend-font-face-create, or implicitly using the toy text API by way of the cairo:select-font-face function. The resulting face can be accessed using the cairo:font-face function.

Type and functions for Font Faces

The cairo:font-type-t enumeration is used to describe the type of a given font face or scaled font. ...

The cairo:font-face-t structure specifies all aspects of a font other than the size or font matrix. ...

Increases the reference count on face by one. ...

Returns the current reference count of the font face. ...

Decreases the reference count on face by one. ...

Checks whether an error has previously occurred for this font face. ...

This function returns the type of the backend used to create a font face. ...


Indroduction to Scaled Fonts

The cairo:scaled-font-t structure represents a realization of a font face at a particular size and transformation and a certain set of font options.

Types and functions for Scaled Fonts

The cairo:font-extents-t structure stores metric information for a font. ...

The cairo:text-extents-t structure stores the extents of a single glyph or a string of glyphs in user-space coordinates. ...

The cairo:scaled-font-t structure is a font scaled to a particular size and device resolution. ...

The cairo:with-scaled-font macro allocates a new cairo:scaled-font-t instance for the given arguments and executes the body that uses the Cairo context. ...

Creates a cairo:scaled-font-t instance from a font face and matrices that describe the size of the font and the environment in which it will be used. ...

Increases the reference count on font by one. ...

Returns the current reference count of font. ...

Decreases the reference count on font by one. ...

Checks whether an error has previously occurred for this scaled font. ...

This function returns the type of the backend used to create a scaled font. ...

Gets the font face that this scaled font uses. ...

Stores the font options with which font was created into options. ...

Stores the font matrix with which font was created into matrix. ...

Stores the CTM with which font was created into ctm. ...

Stores the scale matrix of font into matrix. ...

Gets the metrics for a scaled font. ...

Gets the extents for a string of text. ...

Gets the extents for glyphs. ...

Converts UTF8 text to a list of glyphs. ...


Introduction to Font Options

The font options specify how fonts should be rendered. Most of the time the font options implied by a surface are just right and do not need any changes, but for pixel-based targets tweaking font options may result in superior output on a particular display.

Types and functions for Font Options

The subpixel order specifies the order of color elements within each pixel on the display device when rendering with an antialiasing mode of :subpixel. ...

Specifies the type of hinting to do on font outlines. ...

Specifies whether to hint font metrics. ...

Specifies if color fonts are to be rendered using the color glyphs or outline glyphs. ...

The cairo:font-options-t structure is an opaque structure holding all options that are used when rendering fonts. ...

Allocates a new font options instance with all options initialized to default values. ...

Allocates a new font options object copying the option values from original. ...

Destroys a cairo:font-options-t instance created with the cairo:font-options-create or cairo:font-options-copy function. ...

Checks whether an error has previously occurred for this font options instance. ...

Merges non-default options from other into options, replacing existing values. ...

Compute a hash for the font options instance. ...

Compares two font options instances for equality. ...

The cairo:font-options-antialias function gets the antialiasing mode for the font options instance. ...

The cairo:font-options-subpixel-order function gets the subpixel order for the font options instance. ...

The cairo:font-options-hint-style function gets the hint style for font outlines for the font options instance. ...

The cairo:font-options-hint-metrics function gets the metrics hinting mode for the font options instance. ...

The cairo:font-options-variations function gets the OpenType font variations for the font options instance. ...

The cairo:font-options-color-mode function gets the color mode for the font options instance. ...

The cairo:font-options-color-palette function gets the current OpenType color font palette for the font options instance. ...

The cairo:font-options-custom-palette-color function gets the custom palette color for the color index for the font options instance. ...

Surfaces


Introduction to Cairo Devices

Devices are the abstraction Cairo employs for the rendering system used by a cairo:surface-t instance. You can get the device of a surface using the cairo:surface-device function.

Devices are created using custom functions specific to the rendering system you want to use. See the documentation for the surface types for those functions.

An important function that devices fulfill is sharing access to the rendering system between Cairo and your application. If you want to access a device directly that you used to draw to with Cairo, you must first call the cairo:device-flush function to ensure that Cairo finishes all operations on the device and resets it to a clean state.

Cairo also provides the cairo:device-acquire and cairo:device-release functions to synchronize access to the rendering system in a multithreaded environment. This is done internally, but can also be used by applications.

Putting this all together, a function that works with devices should look something like this:
(defun my-device-modifying-function (device)
  (let (status)
    ;; Ensure the device is properly reset
    (cairo:device-flush device)
    ;; Try to aquire the device
    (unless (eq :success
                (setf status
                      (cairo:device-aquire device)))
      (warn "Failed to aquire the device: ~a" (cairo:status-to-string status))
      (return-from my-device-modifying-function))

;; Do the custom operations on the device here. ;; But do not call any Cairo functions that might acquire devices.

;; Release the device when done. (cairo:device-release device)))
Note: Please refer to the documentation of each backend for additional usage requirements, guarantees provided, and interactions with existing surface API of the device functions for surfaces of that type.

Types and functions for Cairo Devices

The cairo:device-type-t enumeration is used to describe the type of a given device. ...

The cairo:device-t structure represents the driver interface for drawing operations to a cairo:surface-t instance. ...

Increases the reference count on device by one. ...

Returns the current reference count of the device. ...

Decreases the reference count on device by one. ...

Checks whether an error has previously occurred for this device. ...

This function returns the type of the device. ...

This function finishes the device and drops all references to external resources. ...

Finish any pending operations for the device and also restore any temporary modifications Cairo has made to the state of the device. ...

Acquires the device for the current thread. ...

Releases a device previously acquired using the cairo:device-acquire function. ...


Introduction to Cairo Surfaces

The cairo:surface-t structure is the abstract type representing all different drawing targets that cairo can render to. The actual drawings are performed using a Cairo context. A Cairo surface is created by using backend-specific constructors, typically of the form cairo:backend-surface-create.

Most surface types allow accessing the surface without using Cairo functions. If you do this, keep in mind that it is mandatory that you call the cairo:surface-flush function before reading from or writing to the surface and that you must use the cairo:surface-mark-dirty function after modifying it.

Example. Directly modifying an image surface
(defun modify-image-surface (surface)
  (let ((data (cairo:image-surface-data surface))
        (width (cairo:image-surface-width surface))
        (height (cairo:image-surface-height surface))
        (stride (cairo:image-surface-stride surface)))

;; flush to ensure all writing to the image was done (cairo:surface-flush surface)

;; modify the image (modify-image-data data width height stride)

;; mark the image dirty so Cairo clears its caches (cairo:surface-mark-dirty surface)))
Note that for other surface types it might be necessary to acquire the device of the surface first. See the cairo:device-acquire function for a discussion of devices.

Functions and types for Cairo Surfaces

The cairo:content-t enumeration is used to describe the content that a surface will contain, whether color information, alpha information (translucence vs. opacity), or both. ...

The cairo:surface-type-t enumeration is used to describe the type of a given surface. ...

The cairo:surface-t structure represents an image, either as the destination of a drawing operation or as source when drawing onto another surface. ...

The cairo:with-surface macro allocates a new cairo:surface-t instance, initializes the Cairo surface with the given values and executes the body that uses the Cairo surface. ...

The cairo:with-context-for-surface macro allocates a new cairo:context-t instance for a surface, initializes the Cairo context with the given values and executes the body that uses the Cairo context. ...

Create a new surface that is as compatible as possible with an existing surface. ...

Create a new image surface that is as compatible as possible for uploading to and the use in conjunction with an existing surface. ...

Create a new surface that is a rectangle within the target surface. ...

Increases the reference count on surface by one. ...

Returns the current reference count of surface. ...

Decreases the reference count on surface by one. ...

Checks whether an error has previously occurred for this surface. ...

This function returns the type of the backend used to create the surface. ...

This function finishes the surface and drops all references to external resources. ...

Do any pending drawing for the surface and also restore any temporary modifications Cairo has made to the state of the surface. ...

This function returns the device for a surface. ...

Retrieves the default font rendering options for the surface. ...

This function returns the content type of surface which indicates whether the surface contains color and/or alpha information. ...

Tells Cairo that drawing has been done to surface using means other than Cairo, and that Cairo should reread any cached areas. ...

Like the cairo:surface-mark-dirty function, but drawing has been done only to the specified rectangle, so that Cairo can retain cached contents for other parts of the surface. ...

The cairo:surface-device-offset functions returns the device offset. ...

The cairo:surface-device-scale function returns the device scale. ...

The cairo:surface-fallback-resolution function returns the fallback resolution, or default fallback resolution if never set. ...

Emits the current page for backends that support multiple pages, but does not clear it, so that the contents of the current page will be retained for the next page. ...

Emits and clears the current page for backends that support multiple pages. ...


Introduction to Image Surfaces

Image surfaces provide the ability to render to memory buffers either allocated by Cairo or by the calling code. The supported image formats are those defined in the cairo:format-t enumeration.

Types and functions for Image Surfaces

The cairo:format-t enumeration is used to identify the memory format of image data. ...

The cairo:with-image-surface macro allocates a new cairo:surface-t instance, initializes the Cairo surface with the format, width, and height values and executes the body that uses the Cairo surface. ...

The cairo:with-context-for-image-surface macro allocates a new cairo:context-t instance for an image surface, initializes the Cairo context with the format, width, and height values and executes the body that uses the Cairo context. ...

Creates an image surface of the specified format and dimensions. ...

Creates an image surface for the provided pixel data. ...

Get the pointer to the data of the image surface, for direct inspection or modification. ...

Get the format of the image surface. ...

Gets the width of the image surface in pixels. ...

Gets the height of the image surface in pixels. ...

Get the stride of the image surface in bytes. ...

This function provides a stride value that will respect all Cairo alignment requirements of the accelerated image-rendering code within Cairo. ...


Introduction to PDF Surfaces

The PDF surface is used to render Cairo graphics to Adobe PDF files and is a multi-page vector surface backend.

The following mime types are supported: CAIRO_MIME_TYPE_JPEG, CAIRO_MIME_TYPE_JP2, CAIRO_MIME_TYPE_UNIQUE_ID, CAIRO_MIME_TYPE_JBIG2, CAIRO_MIME_TYPE_JBIG2_GLOBAL, CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID, CAIRO_MIME_TYPE_CCITT_FAX, CAIRO_MIME_TYPE_CCITT_FAX_PARAMS.

JBIG2 Images
JBIG2 data in PDF must be in the embedded format as described in ISO/IEC 11544. Image specific JBIG2 data must be in CAIRO_MIME_TYPE_JBIG2. Any global segments in the JBIG2 data (segments with page association field set to 0) must be in CAIRO_MIME_TYPE_JBIG2_GLOBAL. The global data may be shared by multiple images. All images sharing the same global data must set CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID to a unique identifier. At least one of the images must provide the global data using CAIRO_MIME_TYPE_JBIG2_GLOBAL. The global data will only be embedded once and shared by all JBIG2 images with the same CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID.

CCITT Fax Images
The CAIRO_MIME_TYPE_CCITT_FAX mime data requires a number of decoding parameters These parameters are specified using CAIRO_MIME_TYPE_CCITT_FAX_PARAMS. CAIRO_MIME_TYPE_CCITT_FAX_PARAMS mime data must contain a string of the form "param1=value1 param2=value2 ...".
Columns
An integer specifying the width of the image in pixels. [required]
Rows
An integer specifying the height of the image in scan lines. [required]
K
An integer identifying the encoding scheme used. < 0 is 2 dimensional Group 4, = 0 is Group 3 1 dimensional, > 0 is mixed 1 and 2 dimensional encoding. Default is 0. [optional]
EndOfLine
If true end-of-line bit patterns are present. Default is false. [optional]
EncodedByteAlign
If true the end of line is padded with 0 bits so the next line begins on a byte boundary. Default is false. [optional]
EndOfBlock
If true the data contains an end-of-block pattern. Default is true. [optional]
BlackIs1
If true 1 bits are black pixels. Default is false. [optional]
DamagedRowsBeforeError
An integer specifying the number of damages rows tolerated before an error occurs. Default is 0. [optional]
Boolean values may be "true" or "false", or 1 or 0.

These parameters are the same as the CCITTFaxDecode parameters in the PostScript Language Reference and Portable Document Format (PDF). Refer to these documents for further details.

An example CAIRO_MIME_TYPE_CCITT_FAX_PARAMS string is:
"Columns=10230 Rows=40000 K=1 EndOfLine=true EncodedByteAlign=1 BlackIs1=false"      

Types and functions for PDF surfaces

The cairo:pdf-outline-flags-t flags is used by the cairo:pdf-surface-add-outline function to specify the attributes of an outline item. ...

The cairo:pdf-metadata-t enumeration is used by the cairo:pdf-surface-set-metadata function to specify the metadata to set. ...

The cairo:pdf-version-t enumeration is used to describe the version number of the PDF specification that a generated PDF file will conform to. ...

The cairo:with-pdf-surface macro allocates a new PDF cairo:surface-t instance for the given path, width, and height values and executes the body that uses the PDF surface. ...

The cairo:with-context-for-pdf-surface macro allocates a new cairo:context-t instance for a PDF surface, initializes the Cairo context with the path, width, and height values and executes the body that uses the Cairo context. ...

Creates a PDF surface of the specified size in points to be written to filename. ...

Restricts the generated PDF file to the given version. ...

Used to retrieve the list of supported versions. ...

Gets the string representation of the given version ID. ...

Changes the size of a PDF surface for the current (and subsequent) pages. ...

Add an item to the document outline hierarchy with the name utf8 that links to the location specified by link. ...

Set document metadata. ...

Set custom document metadata. ...

Sets the page label for the current page. ...

Set the thumbnail image size for the current and all subsequent pages. ...


Introduction to PNG Support

The PNG functions allow reading PNG images into image surfaces, and writing any surface to a PNG file.

It is a toy API. It only offers very simple support for reading and writing PNG files, which is sufficient for testing and demonstration purposes. Applications which need more control over the generated PNG file should access the pixel data directly, using the cairo:image-surface-data function or a backend-specific access function, and process it with another library, for example GdkPixbuf or libpng.

Functions for PNG support

Creates a new image surface and initializes the contents to the given PNG file. ...

Writes the contents of the image surface to a new file as a PNG image. ...


Indroduction to PostScript Surfaces

The PostScript surface is used to render Cairo graphics to Adobe PostScript files and is a multi-page vector surface backend.

The following mime types are supported: CAIRO_MIME_TYPE_JPEG, CAIRO_MIME_TYPE_UNIQUE_ID, CAIRO_MIME_TYPE_CCITT_FAX, CAIRO_MIME_TYPE_CCITT_FAX_PARAMS, CAIRO_MIME_TYPE_CCITT_FAX, CAIRO_MIME_TYPE_CCITT_FAX_PARAMS, CAIRO_MIME_TYPE_EPS, CAIRO_MIME_TYPE_EPS_PARAMS.

Source surfaces used by the PostScript surface that have a CAIRO_MIME_TYPE_UNIQUE_ID mime type will be stored in PostScript printer memory for the duration of the print job. The CAIRO_MIME_TYPE_UNIQUE_ID mime type should only be used for small frequently used sources.

The CAIRO_MIME_TYPE_CCITT_FAX and CAIRO_MIME_TYPE_CCITT_FAX_PARAMS mime types are documented in CCITT Fax Images.

Embedding EPS files
Encapsulated PostScript files can be embedded in the PS output by setting the CAIRO_MIME_TYPE_EPS mime data on a surface to the EPS data and painting the surface. The EPS will be scaled and translated to the extents of the surface the EPS data is attached to.

The CAIRO_MIME_TYPE_EPS mime type requires the CAIRO_MIME_TYPE_EPS_PARAMS mime data to also be provided in order to specify the embeddding parameters. CAIRO_MIME_TYPE_EPS_PARAMS mime data must contain a string of the form "bbox=[llx lly urx ury]" that specifies the bounding box (in PS coordinates) of the EPS graphics. The parameters are: lower left x, lower left y, upper right x, upper right y. Normally the bbox data is identical to the %%BoundingBox data in the EPS file.

Type and functions for PostScript Surfaces

The cairo:ps-level-t enumeration is used to describe the language level of the PostScript Language Reference that a generated PostScript file will conform to. ...

The cairo:with-ps-surface macro allocates a new PostScript cairo:surface-t instance for the given path, width, and height values and executes the body that uses the PostScript surface. ...

Creates a PostScript surface of the specified size in points to be written to path. ...

Restricts the generated PostSript file to level. ...

Used to retrieve the list of supported levels. ...

Get the string representation of the given level ID. ...

The cairo:ps-surface-eps function checks whether the PostScript surface will output Encapsulated PostScript. ...

Changes the size of a PostScript surface for the current and subsequent pages. ...

This function indicates that subsequent calls to the cairo:ps-surface-dsc-comment function should direct comments to the Setup section of the PostScript output. ...

This function indicates that subsequent calls to the cairo:ps-surface-dsc-comment function should direct comments to the PageSetup section of the PostScript output. ...

Emit a comment into the PostScript output for the given surface. ...


Indroduction to Recording Surfaces

A recording surface is a surface that records all drawing operations at the highest level of the surface backend interface, that is, the level of paint, mask, stroke, fill, and text glyphs. The recording surface can then be "replayed" against any target surface by using it as a source surface.

If you want to replay a surface so that the results in target will be identical to the results that would have been obtained if the original operations applied to the recording surface had instead been applied to the target surface, you can use code like this:
(cairo:with-context (context target)
  (cairo:set-source-surface context recording-surface 0.0 0.0)
  (cairo:paint context)
  ...)      
A recording surface is logically unbounded, that is, it has no implicit constraint on the size of the drawing surface. However, in practice this is rarely useful as you wish to replay against a particular target surface with known bounds. For this case, it is more efficient to specify the target extents to the recording surface upon creation.

The recording phase of the recording surface is careful to snapshot all necessary objects, paths, patterns, etc., in order to achieve accurate replay.

Functions for Recording Surfaces

The cairo:with-recording-surface macro allocates a new cairo:surface-t instance and executes the body that uses the Cairo surface. ...

The cairo:with-context-for-recording-surface macro allocates a new cairo:context-t instance, initializes the Cairo context with the given values and executes the body that uses the Cairo context. ...

Creates a recording surface which can be used to record all drawing operations at the highest level, that is, the level of paint, mask, stroke, fill and text glyphs. ...

Measures the extents of the operations stored within the recording surface. ...

Get the extents of the recording surface. ...


Introduction to SVG Surfaces

The SVG surface is used to render Cairo graphics to SVG files and is a multi-page vector surface backend.

Types and functions for SVG surfaces

The cairo:svg-version-t enumeration is used to describe the version number of the SVG specification that a generated SVG file will conform to. ...

The cairo:svg-unit-t enumeration is used to describe the units valid for coordinates and lengths in the SVG specification. ...

Creates a SVG surface of the specified size in points to be written to path. ...

The cairo:svg-surface-document-unit function gets the unit of the SVG surface. ...

Restricts the generated SVG file to version. ...

Used to retrieve the list of supported versions. ...

Gets the string representation of the given version ID. ...


Indroduction to Script Surfaces

The script surface provides the ability to render to a native script that matches the Cairo drawing model. The scripts can be replayed using tools under the util/cairo-script directory, or with the cairo-perf-trace utility.

Types and functions for Script Surfaces

A set of script output variants. ...

The cairo:with-script-surface macro allocates a new cairo:surface-t instance for a newly created cairo:device-t instance of :script type and executes the body that uses the Cairo script surface. ...

Creates an output device for emitting the script, used when creating the individual surfaces. ...

Converts the recorded operations in surface into a script. ...

The cairo:script-mode function queries the script for its current output mode. ...

Creates a new surface that will emit its rendering through script. ...

Creates a proxy surface that will render to target and record the operations to script. ...

Emit a string verbatim into the script. ...

Utilities


Generic matrix operations

The cairo:matrix-t structure holds an affine transformation, such as a scale, rotation, shear, or a combination of those. ...

The cairo:with-matrix macro allocates a new cairo:matrix-t instance, initializes the matrix with the given values and executes the body that uses the matrix. ...

The cairo:with-matrices macro creates new variable bindings and executes the body that use these bindings. ...

Sets the matrix to be the affine transformation given by the xx, yx, xy, yy, x0, y0 arguments. ...

Modifies the matrix to be an identity transformation. ...

Initializes the matrix to a transformation that translates by tx and ty in the x and y dimensions, respectively. ...

Initializes the matrix to a transformation that scales by sx and sy in the x and y dimensions, respectively. ...

Initializes the matrix to a transformation that rotates by angle. ...

Converts the matrix to a list of double floats. ...

Applies a translation by tx, ty to the transformation in the matrix. ...

Applies scaling by sx and sy to the transformation in the matrix. ...

Applies rotation by angle to the transformation in the matrix. ...

Changes the matrix to be the inverse of its original value. ...

Multiplies the affine transformations in a and b together, ...

Transforms the distance vector (dx,dy) by matrix. ...

Transforms the point (dx,dy) by matrix. ...


Introduction to Error handling

Cairo uses a single status type to represent all kinds of errors. A status value of :success represents no error and has an integer value of zero. All other status values represent an error.

Cairo's error handling is designed to be easy to use and safe. All major Cairo objects retain an error status internally which can be queried anytime by the users using cairo*-status calls. In the mean time, it is safe to call all Cairo functions normally even if the underlying object is in an error status. This means that no error handling code is required before or after each individual Cairo function call.

Types and functions for Error handling

The cairo:status-t enumeration is used to indicate errors that can occur when using Cairo. ...

Provides a human readable description of a Cairo status value. ...


Introduction to Version Information

Cairo provides the ability to examine the version at either compile-time or run-time and in both a human readable form as well as an encoded form suitable for direct comparison. Cairo also provides the cairo:version-encode function to perform the encoding.

Functions for Version Information

This function encodes the given Cairo version into an integer. ...

Returns the version of the Cairo library encoded in a single integer. ...

Returns the version of the Cairo library as a human readable string of the form "x.y.z". ...

Exported Symbol Index

antialias, Function
append-path, Function
arc, Function
arc-negative, Function
clip, Function
clip-extents, Function
clip-preserve, Function
close-path, Function
copy-clip-rectangle-list, Function
copy-page, Function
copy-path, Function
copy-path-flat, Function
create, Function
current-point, Function
curve-to, Function
dash, Function
dash-count, Function
destroy, Function
device-acquire, Function
device-destroy, Function
device-finish, Function
device-flush, Function
device-reference, Function
device-reference-count, Function
device-release, Function
device-status, Function
device-to-user, Function
device-to-user-distance, Function
device-type, Function
fill, Function
fill-extents, Function
fill-preserve, Function
fill-rule, Function
font-extents, Function
font-face, Function
font-face-destroy, Function
font-face-reference, Function
font-face-reference-count, Function
font-face-status, Function
font-face-type, Function
font-matrix, Function
font-options, Function
font-options-antialias, Function
font-options-color-mode, Function
font-options-color-palette, Function
font-options-copy, Function
font-options-create, Function
font-options-custom-palette-color, Function
font-options-destroy, Function
font-options-equal, Function
font-options-hash, Function
font-options-hint-metrics, Function
font-options-hint-style, Function
font-options-merge, Function
font-options-status, Function
font-options-subpixel-order, Function
font-options-variations, Function
format-stride-for-width, Function
glyph-extents, Function
glyph-path, Function
group-target, Function
hairline, Function
has-current-point, Function
identity-matrix, Function
image-surface-create, Function
image-surface-create-for-data, Function
image-surface-create-from-png, Function
image-surface-data, Function
image-surface-format, Function
image-surface-height, Function
image-surface-stride, Function
image-surface-width, Function
in-clip, Function
in-fill, Function
in-stroke, Function
line-cap, Function
line-join, Function
line-to, Function
line-width, Function
mask, Function
mask-surface, Function
matrix, Function
matrix-init, Function
matrix-init-identity, Function
matrix-init-rotate, Function
matrix-init-scale, Function
matrix-init-translate, Function
matrix-invert, Function
matrix-multiply, Function
matrix-rotate, Function
matrix-scale, Function
matrix-to-float, Function
matrix-transform-distance, Function
matrix-transform-point, Function
matrix-translate, Function
mesh-pattern-begin-patch, Function
mesh-pattern-control-point, Function
mesh-pattern-corner-color-rgba, Function
mesh-pattern-curve-to, Function
mesh-pattern-end-patch, Function
mesh-pattern-line-to, Function
mesh-pattern-move-to, Function
mesh-pattern-patch-count, Function
mesh-pattern-path, Function
mesh-pattern-set-control-point, Function
mesh-pattern-set-corner-color-rgb, Function
mesh-pattern-set-corner-color-rgba, Function
miter-limit, Function
move-to, Function
new-path, Function
new-sub-path, Function
operator, Function
paint, Function
paint-with-alpha, Function
path-data, Accessor
path-data-to-list, Function
path-destroy, Function
path-extents, Function
path-numdata, Accessor
path-status, Accessor
pattern-add-color-stop-rgb, Function
pattern-add-color-stop-rgba, Function
pattern-color-stop-count, Function
pattern-color-stop-rgba, Function
pattern-create-for-surface, Function
pattern-create-linear, Function
pattern-create-mesh, Function
pattern-create-radial, Function
pattern-create-rgb, Function
pattern-create-rgba, Function
pattern-destroy, Function
pattern-extend, Function
pattern-filter, Function
pattern-linear-points, Function
pattern-matrix, Function
pattern-radial-circles, Function
pattern-reference, Function
pattern-reference-count, Function
pattern-rgba, Function
pattern-status, Function
pattern-surface, Function
pattern-type, Function
pdf-surface-add-outline, Function
pdf-surface-create, Function
pdf-surface-restrict-to-version, Function
pdf-surface-set-custom-metadata, Function
pdf-surface-set-metadata, Function
pdf-surface-set-page-label, Function
pdf-surface-set-size, Function
pdf-surface-set-thumbnail-size, Function
pdf-version-to-string, Function
pdf-versions, Function
pop-group, Function
pop-group-to-source, Function
ps-level-to-string, Function
ps-levels, Function
ps-surface-create, Function
ps-surface-dsc-begin-page-setup, Function
ps-surface-dsc-begin-setup, Function
ps-surface-dsc-comment, Function
ps-surface-eps, Function
ps-surface-restrict-to-level, Function
ps-surface-set-size, Function
push-group, Function
push-group-with-content, Function
recording-surface-create, Function
recording-surface-extents, Function
recording-surface-ink-extents, Function
rectangle, Function
reference, Function
reference-count, Function
region-contains-point, Function
region-contains-rectangle, Function
region-copy, Function
region-create, Function
region-create-rectangle, Function
region-create-rectangles, Function
region-destroy, Function
region-equal, Function
region-extents, Function
region-intersect, Function
region-intersect-rectangle, Function
region-is-empty, Function
region-num-rectangles, Function
region-rectangle, Function
region-reference, Function
region-status, Function
region-subtract, Function
region-subtract-rectangle, Function
region-translate, Function
region-union, Function
region-union-rectangle, Function
region-xor, Function
region-xor-rectangle, Function
rel-curve-to, Function
rel-line-to, Function
rel-move-to, Function
reset-clip, Function
restore, Function
rotate, Function
save, Function
scale, Function
scaled-font, Function
scaled-font-create, Function
scaled-font-ctm, Function
scaled-font-destroy, Function
scaled-font-extents, Function
scaled-font-font-face, Function
scaled-font-font-matrix, Function
scaled-font-font-options, Function
scaled-font-glyph-extents, Function
scaled-font-reference, Function
scaled-font-reference-count, Function
scaled-font-scale-matrix, Function
scaled-font-status, Function
scaled-font-text-extents, Function
scaled-font-text-to-glyphs, Function
scaled-font-type, Function
script-create, Function
script-from-recording-surface, Function
script-mode, Function
script-surface-create, Function
script-surface-create-for-target, Function
script-write-comment, Function
select-font-face, Function
set-font-size, Function
set-source-rgb, Function
set-source-rgba, Function
set-source-surface, Function
show-glyphs, Function
show-page, Function
show-text, Function
source, Function
status, Function
status-to-string, Function
stroke, Function
stroke-extents, Function
stroke-preserve, Function
surface-content, Function
surface-copy-page, Function
surface-create-for-rectangle, Function
surface-create-similar, Function
surface-create-similar-image, Function
surface-destroy, Function
surface-device, Function
surface-device-offset, Function
surface-device-scale, Function
surface-fallback-resolution, Function
surface-finish, Function
surface-flush, Function
surface-font-options, Function
surface-mark-dirty, Function
surface-mark-dirty-rectangle, Function
surface-reference, Function
surface-reference-count, Function
surface-show-page, Function
surface-status, Function
surface-type, Function
surface-write-to-png, Function
svg-surface-create, Function
svg-surface-document-unit, Function
svg-surface-restrict-to-version, Function
svg-version-to-string, Function
svg-versions, Function
target, Function
text-extents, Function
text-path, Function
tolerance, Function
toy-font-face-create, Function
toy-font-face-family, Function
toy-font-face-slant, Function
toy-font-face-weight, Function
transform, Function
translate, Function
user-to-device, Function
user-to-device-distance, Function
version, Function
version-encode, Function
version-string, Function
with-context, Macro
with-context-for-image-surface, Macro
with-context-for-pdf-surface, Macro
with-context-for-recording-surface, Macro
with-context-for-surface, Macro
with-image-surface, Macro
with-matrices, Macro
with-matrix, Macro
with-pdf-surface, Macro
with-ps-surface, Macro
with-recording-surface, Macro
with-scaled-font, Macro
with-script-surface, Macro
with-surface, Macro
with-toy-font-face, Macro
antialias-t, CEnum
color-mode-t, CEnum
content-t, CEnum
context-t, CStruct
device-t, CStruct
device-type-t, CEnum
extend-t, CEnum
fill-rule-t, CEnum
filter-t, CEnum
font-extents-t, CStruct
font-face-t, CStruct
font-options-t, CStruct
font-slant-t, CEnum
font-type-t, CEnum
font-weight-t, CEnum
format-t, CEnum
glyph-t, CStruct
hint-metrics-t, CEnum
hint-style-t, CEnum
line-cap-t, CEnum
line-join-t, CEnum
matrix-t, CStruct
operator-t, CEnum
path-data-t, CStruct
path-data-type-t, CEnum
path-t, CStruct
pattern-t, CStruct
pattern-type-t, CEnum
pdf-metadata-t, CEnum
pdf-outline-flags-t, Bitfield
pdf-version-t, CEnum
ps-level-t, CEnum
region-overlap-t, Enum
region-t, CStruct
scaled-font-t, CStruct
script-mode-t, CEnum
status-t, CEnum
subpixel-order-t, CEnum
surface-t, CStruct
surface-type-t, CEnum
svg-unit-t, CEnum
svg-version-t, CEnum
text-extents-t, CStruct