summaryrefslogtreecommitdiff
path: root/doc/cairo.txt
blob: 17b1152e83c50a2e6f1885f57da34d236422eca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
The cairo bindings follows the C API pretty closely.

Naming
======

The module name is called 'cairo' and usually imported into
the namespace as 'Cairo'.

gjs> const Cairo = imports.cairo;

Methods are studlyCaps, similar to other JavaScript apis, eg

cairo_move_to is wrapped to Cairo.Context.moveTo()
cairo_surface_write_to_png to Cairo.Context.writeToPNG().

Abbrevations such as RGB, RGBA, PNG, PDF, SVG are always
upper-case.

Enums are set in the cairo namespace, the enum names are capitalized:

CAIRO_FORMAT_ARGB32 is mapped to Cairo.Format.ARGB32 etc.

Surfaces (cairo_surface_t)
==========================

Prototype hierarchya

* Surface (abstract)
  * ImageSurface
  * PDFSurface
  * SVGSurface
  * PostScriptSurface

The native surfaces (win32, quartz, xlib) are not supported at this point.

Methods manipulating a surface are present in the surface class.
Creating an ImageSurface from a PNG is done by calling a static method:

gjs> let surface = Cairo.ImageSurface.createFromPNG("filename.png");


Context (cairo_t)
=================

cairo_t is mapped as Cairo.Context.

You will either get a context from a third-party library such
as Clutter/Gtk/Poppler or by calling the cairo.Context constructor.


gjs> let cr = new Cairo.Context(surface);

gjs> let cr = Gdk.cairo_create(...);

All introspection methods taking or returning a cairo_t will automatically
create a Cairo.Context.

Patterns (cairo_pattern_t)
==========================

Prototype hierarchy

* Pattern
  * Gradient
    * LinearGradient
    * RadialGradient
  * SurfacePattern
  * SolidPattern

You can create a linear gradient by calling the constructor:

Constructors:

gjs> let pattern = new Cairo.LinearGradient(0, 0, 100, 100);

gjs> let pattern = new Cairo.RadialGradient(0, 0, 10, 100, 100, 10);

gjs> let pattern = new Cairo.SurfacePattern(surface);

gjs> let pattern = new Cairo.SolidPattern.createRGB(0, 0, 0);

gjs> let pattern = new Cairo.SolidPattern.createRGBA(0, 0, 0, 0);

TODO:
* context: wrap the remaning methods
* surface methods
* image surface methods
* matrix
* version
* iterating over cairo_path_t

Fonts & Glyphs are not wrapped, use PangoCairo instead.
* glyphs
* text cluster
* font face
* scaled font
* font options