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
- CairoPdfSurface
- CairoPsSurface
- CairoSvgSurface
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:
| Property | Data type | Description |
|---|---|---|
| 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:
| Method | Return type | Description |
|---|---|---|
| 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 )
- Width : Width of the page in millimetres
- Height: Height of the page in millimetres
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:
- Path: File path for the writable PDF file. If you enter NULL as the path, a PDF surface is created on which you can draw - without creating a temporary file.
- Width: Width of the surface in millimetres
- Height: Height of the surface in millimetres
- Version: Optional argument. If it is specified, PDF version 1.4 or 1.5 is agreed for the generated PDF file.
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:
- Path: File path for the writable SVG file. If you enter NULL as the path, an SVG surface is created on which you can draw - without creating a temporary file.
- Width: Width of the surface in millimetres
- Height: Height of the surface in millimetres
- Version: If the optional argument is specified, the generated SVG file is set to version 1.1 or 1.2.
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:
- Path: file path for the writable PostScript file. If you enter NULL as the path, a PostScript surface is generated on which you can draw (immediately) - without creating a temporary file.
- Width: Width of the surface in millimetres
- Height: Height of the surface in millimetres
- Encapsulated: If the optional argument was specified and has the value True, then an encapsulated PostScript file (EPS) is created.
- Level: If the optional argument is specified, the generated PostScript file is of level 2 or 3.
