Cairo Namespace

A binding to the 2D Cairo Graphics rendering API.


The Mono.Cairo namespace is a binding to the API.

Before Mono 1.2.5, this API only exposed the Cairo 1.0 API, starting with Mono 1.2.5, this release exposes both the Cairo 1.0 and 1.2 APIs regardless of the underlying Cairo implementation available on the underlying system.

If you are planning on using the 1.2 API, you should first check using the Cairo.CairoAPI.Version whether you are running on a system that supports the 1.2 API before making any 1.2 calls or make it a requirement that the system must have a 1.2 Cairo installed. Cairo 1.2 APIs have been flagged in the documentation.

Cairo draws into surfaces, there are many to choose from (in-memory image buffers, PDF surfaces, Postscript surfaces, hardware accelerated surfaces, Xlib surfaces and a handful more). Drawing operations are performed on the Cairo surfaces, for example:

C# Example

// To compile use: mcs test.cs -r:Mono.Cairo
// This generates a file test.png that contains the text
// "Hello, World" rendered with a serif font in blue, on a
// transparent background.
using Cairo;

class X {
	static void Main ()
		// Creates an Image-based surface with with data stored in
		// ARGB32 format.  
		ImageSurface surface = new ImageSurface (Format.ARGB32, 240, 80);

		// Create a context, "using" is used here to ensure that the
		// context is Disposed once we are done
		using (Context ctx = new Cairo.Context (surface)){

			// Select a font to draw with
			ctx.SelectFontFace ("serif", FontSlant.Normal, FontWeight.Bold);
			ctx.SetFontSize (32.0);
			// Select a color (blue)
			ctx.SetSourceRGB (0, 0, 1);
			// Draw
			ctx.MoveTo (10, 50);
			ctx.ShowText ("Hello, World");
			surface.WriteToPng ("test.png");

To compile code that uses Mono.Cairo all you have to do is reference the Mono.Cairo assembly by passing the -r:Mono.Cairo command line option to the compiler or referencing the assembly from MonoDevelop. The code is contained in the "Cairo" namespace.


AntialiasSpecifies the type of antialiasing to do when rendering text or shapes.
CairoAPIProvides information about the CairoAPI.
ColorColor objects holding red, green, blue, and alpha values.
ContentUsed to describe the content that a surface will contain, whether color information, alpha information (translucence vs. opacity), or both.
ContextThis is the main object when drawing with Cairo.
DirectFBSurfaceA DirectFBSurface
DistanceDefines a distance between two points.
ExtendDefines Pattern Extend types.
FillRuleDefines a FillRule.
FilterDefines Filter types on Graphics and Pattern objects.
FontExtentsStores metric information for a font. Values are given in the current user-space coordinate system.
FontFaceA FontFace represents a font at a particular weight, slant, and other characteristics but no size or transformation.
FontOptionsThe FontOptions Class defines how a font should be rendered
FontSlantDefines the possible slants on fonts.
FontTypeDescribes the type of a given font face or scaled font.
FontWeightDefines the weight of the font (normal, bold).
FormatUsed to identify the memory format of image data.
GlitzSurfaceGlitz OpenGL surface support
GlyphThis structure holds information about a single glyph when drawing or measuring text.
GradientBase class for gradients.
GraphicsObsolete version of Cairo.Context, use it instead.
HintMetricsSpecifies whether to hint font metrics.
HintStyleSpecifies the type of hinting to do on font outlines.
ImageSurfaceAn in-memory image surface
LinearGradientExtends Cairo.Gradient by providing a linear gradient along the line defined by (x0, y0) and (x1, y1).
LineCapDefines the various line ending styles.
LineJoinDefines the various line join styles
MatrixDefines the Matrix object for transformations and translations.
NativeMethodsContains references to the native cairo methods
OperatorContains the Cairo Operators
PathThe Cairo Path Class
PatternPatterns allow you to tile or extend images and objects and allow you to draw things like gradients.
PatternTypeDescribes the type of a given pattern.
PdfSurfaceThe PDF surface is used to render cairo graphics to Adobe PDF files.
PointClass defining a point representd by two int values.
PointDClass defining a point represented by two double values for the x and y coordinates.
PSSurfaceThe PostScript surface is used to render cairo graphics to Adobe PostScript files.
RadialGradientExtends Cairo.Gradient to create a new radial gradient between the two circles defined by (cx0, cxy0, radius0) and (cx1, cy1, radius1).
RectangleA representation of a Rectangle.
ScaledFontDocumentation for this section has not yet been entered.
SolidPatternExtends Pattern to create a solid pattern consisting of a solid color and an optional alpha value.
StatusReports the internal status of the Cairo system. When an error occurs, all further calls to acquire the status will report the error.
SubpixelOrderThe subpixel order specifies the order of color elements within each pixel on the display device when rendering with an antialiasing mode of Cairo.Antialias.Subpixel.
SurfaceBase class for surfaces
SurfacePatternDocumentation for this section has not yet been entered.
SurfaceTypeDescribes the type of a given surface.
SvgSurfaceDocumentation for this section has not yet been entered.
SvgVersionDescribes the version number of the SVG specification that a generated SVG file will conform to.
TextExtentsStores the extents of a single glyph or a string of glyphs in user-space coordinates.
Win32SurfaceMicrosoft Windows surface support
XcbSurfaceDocumentation for this section has not yet been entered.
XlibSurfaceX Window System rendering using XLib