1package cairo 2 3// #include <stdlib.h> 4// #include <cairo.h> 5// #include <cairo-gobject.h> 6import "C" 7 8// Translate is a wrapper around cairo_translate. 9func (v *Context) Translate(tx, ty float64) { 10 C.cairo_translate(v.native(), C.double(tx), C.double(ty)) 11} 12 13// Scale is a wrapper around cairo_scale. 14func (v *Context) Scale(sx, sy float64) { 15 C.cairo_scale(v.native(), C.double(sx), C.double(sy)) 16} 17 18// Rotate is a wrapper around cairo_rotate. 19func (v *Context) Rotate(angle float64) { 20 C.cairo_rotate(v.native(), C.double(angle)) 21} 22 23// Transform is a wrapper around cairo_transform. 24func (v *Context) Transform(matrix *Matrix) { 25 C.cairo_transform(v.native(), matrix.native()) 26} 27 28// SetMatrix is a wrapper around cairo_set_matrix. 29func (v *Context) SetMatrix(matrix *Matrix) { 30 C.cairo_set_matrix(v.native(), matrix.native()) 31} 32 33// GetMatrix is a wrapper around cairo_get_matrix. 34func (v *Context) GetMatrix() *Matrix { 35 var matrix C.cairo_matrix_t 36 C.cairo_get_matrix(v.native(), &matrix) 37 return &Matrix{ 38 Xx: float64(matrix.xx), 39 Yx: float64(matrix.yx), 40 Xy: float64(matrix.xy), 41 Yy: float64(matrix.yy), 42 X0: float64(matrix.x0), 43 Y0: float64(matrix.y0), 44 } 45} 46 47// IdentityMatrix is a wrapper around cairo_identity_matrix(). 48// 49// Resets the current transformation matrix (CTM) by setting it equal to the 50// identity matrix. That is, the user-space and device-space axes will be 51// aligned and one user-space unit will transform to one device-space unit. 52func (v *Context) IdentityMatrix() { 53 C.cairo_identity_matrix(v.native()) 54} 55 56// UserToDevice is a wrapper around cairo_user_to_device. 57func (v *Context) UserToDevice(x, y float64) (float64, float64) { 58 C.cairo_user_to_device(v.native(), (*C.double)(&x), (*C.double)(&y)) 59 return x, y 60} 61 62// UserToDeviceDistance is a wrapper around cairo_user_to_device_distance. 63func (v *Context) UserToDeviceDistance(dx, dy float64) (float64, float64) { 64 C.cairo_user_to_device_distance(v.native(), (*C.double)(&dx), (*C.double)(&dy)) 65 return dx, dy 66} 67 68// DeviceToUser is a wrapper around cairo_device_to_user. 69func (v *Context) DeviceToUser(x, y float64) (float64, float64) { 70 C.cairo_device_to_user(v.native(), (*C.double)(&x), (*C.double)(&y)) 71 return x, y 72} 73 74// DeviceToUserDistance is a wrapper around cairo_device_to_user_distance. 75func (v *Context) DeviceToUserDistance(x, y float64) (float64, float64) { 76 C.cairo_device_to_user_distance(v.native(), (*C.double)(&x), (*C.double)(&y)) 77 return x, y 78} 79