Table of Contents

25.1.9 CairoSurface

The CairoSurface class (gb.cairo) is the parent class of the CairoSurface classes below.

25.1.9.1 Surface classes

Surface is understood as a surface or just a surface for drawing or as an object on which you can draw. The class CairoPdfSurface represents a PDF file, CairoPsSurface a PostScript file and CairoSvgSurface an SVG file whose content is a scalable vector graphic. The three classes CairoPdfSurface, CairoPsSurface and CairoSvgSurface have all the properties and methods of the parent class CairoSurface.

25.1.9.2 Properties

The CairoSurface class has three properties:

PropertyData typeDescription
Path String Returns the path of the generated file.
Resolution Float Returns the resolution of the surface or sets the default resolution to 300 pixels/inch.
Status Integer Checks whether an error occurred for the surface used during drawing and then returns the error status.

Table 25.1.9.2.1 : Properties of the CairoSurface class

An overview of the possible status values can be found in the overview of the constants for the Cairo class under the link → http://gambaswiki.org/wiki/comp/gb.cairo/cairo.

25.1.9.3 Methods

The CairoSurface class has these two methods:

MethodReturn typeDescription
Finish ( )- This function completes all operations for drawing on the surface and frees all references to external resources.
Save ( Path As String ) Integer Saves the content of the drawing area as a PNG file in the specified file path. The function returns an integer - a zero if successful.

Table 25.1.9.3.1 : Methods of the CairoSurface class

Only the CairoPdfSurface class has the additional method CairoPdfSurface.Resize(..). It changes the size of a PDF surface for the current and other pages:

CairoPdfSurface.Resize ( Width As Float, Height As Float )

This function should only be called before drawing operations are carried out on the current page. If necessary, call this function immediately after creating the interface or immediately after completing a page (Cairo.ShowPage() or Cairo.CopyPage()).

25.1.9.4 Creating a PDF interface

You can generate a new CairoPdfSurface like this:

Dim hCairoPdfSurface As CairoPdfSurface 
hCairoPdfSurface = New CairoPdfSurface (Path As String,Width As Float,Height As Float [,Version As String])

A PDF surface with the specified size in millimetres is generated:

25.1.9.5 Creating an SVG interface

This creates a new CairoSvgSurface:

Dim hCairoSvgSurface As CairoSvgSurface
hCairoSvgSurface = New CairoSvgSurface ( Path As String, Width As Float, Height As Float [ , Version As String ] )

An SVG surface with the specified size in millimetres is created:

25.1.9.6 Creating a PostScript interface

A new CairoPsSurface object for drawing is generated as follows

Dim hCairoPsSurface As CairoPsSurface
hCairoPsSurface = New CairoPsSurface ( Path As String, Width As Float, Height As Float [ , Encapsulated As Boolean, Level As String ] )

A PostScript surface with the specified size is generated: