Updating built in Io code to use += instead of x = x + y
[io/quag.git] / addons / Cairo / source / IoCairoSurface.c
blob8643222e3ecc6ce91b0ca78edd44e194dd0aefd1
1 /*#io
2 CairoSurface ioDoc(
3 docCopyright("Daniel Rosengren", 2007)
4 docLicense("BSD revised")
5 docCategory("Graphics")
6 */
8 #include "IoCairoSurface.h"
9 #include "IoCairoSurface_inline.h"
10 #include "IoCairoFontOptions.h"
11 #include "IoNumber.h"
12 #include "tools.h"
14 #include "IoCairoImageSurface.h"
15 #include "IoCairoPSSurface.h"
16 #include "IoCairoPDFSurface.h"
17 #include "IoCairoSVGSurface.h"
20 static IoTag *IoCairoSurface_newTag(void *state)
22 IoTag *tag = IoTag_newWithName_("CairoSurface");
23 IoTag_state_(tag, state);
24 IoTag_cloneFunc_(tag, (IoTagCloneFunc *)IoCairoSurface_rawClone);
25 IoTag_freeFunc_(tag, (IoTagFreeFunc *)IoCairoSurface_free);
26 return tag;
29 IoCairoSurface *IoCairoSurface_proto(void *state)
31 IoObject *self = IoObject_new(state);
32 IoObject_tag_(self, IoCairoSurface_newTag(state));
34 IoState_registerProtoWithFunc_(state, self, IoCairoSurface_proto);
36 IoCairoSurface_addMethods(self);
38 return self;
41 void IoCairoSurface_addMethods(IoCairoSurface *self)
43 IoMethodTable methodTable[] = {
44 {"createSimilar", IoCairoSurface_createSimilar},
46 {"finish", IoCairoSurface_finish},
47 {"flush", IoCairoSurface_flush},
49 {"getFontOptions", IoCairoSurface_getFontOptions},
50 {"getContent", IoCairoSurface_getContent},
52 {"markDirty", IoCairoSurface_markDirty},
53 {"markDirtyRectangle", IoCairoSurface_markDirtyRectangle},
55 {"setDeviceOffset", IoCairoSurface_setDeviceOffset},
56 {"getDeviceOffset", IoCairoSurface_getDeviceOffset},
58 {"setFallbackResolution", IoCairoSurface_setFallbackResolution},
60 {NULL, NULL},
62 IoObject_addMethodTable_(self, methodTable);
65 IoCairoSurface *IoCairoSurface_rawClone(IoCairoSurface *proto)
67 IoObject *self = IoObject_rawClonePrimitive(proto);
68 if (SURFACE(proto))
69 IoObject_setDataPointer_(self, cairo_surface_reference(SURFACE(proto)));
70 return self;
73 IoCairoSurface *IoCairoSurface_newWithRawSurface_(void *state, IoMessage *m, cairo_surface_t *surface)
75 IoObject *self = 0;
76 IoStateProtoFunc *initFunc = 0;
78 checkStatus_(state, m, cairo_surface_status(surface));
80 switch(cairo_surface_get_type(surface))
82 case CAIRO_SURFACE_TYPE_IMAGE:
83 initFunc = IoCairoImageSurface_proto;
84 break;
85 case CAIRO_SURFACE_TYPE_PS:
86 initFunc = IoCairoPSSurface_proto;
87 break;
88 case CAIRO_SURFACE_TYPE_PDF:
89 initFunc = IoCairoPDFSurface_proto;
90 break;
91 case CAIRO_SURFACE_TYPE_SVG:
92 initFunc = IoCairoSVGSurface_proto;
93 break;
94 default:
95 IoState_error_(state, 0, "Unsupported surface type");
98 self = IOCLONE(IoState_protoWithInitFunction_(state, initFunc));
99 IoObject_setDataPointer_(self, surface);
100 return self;
103 void IoCairoSurface_free(IoCairoSurface *self)
105 if (SURFACE(self))
106 cairo_surface_destroy(SURFACE(self));
109 cairo_surface_t *IoCairoSurface_rawSurface(IoCairoSurface *self)
111 return SURFACE(self);
115 /* ------------------------------------------------------------------------------------------------*/
117 IoObject *IoCairoSurface_createSimilar(IoCairoSurface *self, IoObject *locals, IoMessage *m)
119 cairo_content_t content = IoMessage_locals_intArgAt_(m, locals, 0);
120 int w = IoMessage_locals_intArgAt_(m, locals, 1);
121 int h = IoMessage_locals_intArgAt_(m, locals, 2);
123 cairo_surface_t *surface = cairo_surface_create_similar(SURFACE(self), content, w, h);
124 return IoCairoSurface_newWithRawSurface_(IOSTATE, m, surface);
128 IoObject *IoCairoSurface_finish(IoCairoSurface *self, IoObject *locals, IoMessage *m)
130 cairo_surface_finish(SURFACE(self));
131 CHECK_STATUS(self);
132 return self;
135 IoObject *IoCairoSurface_flush(IoCairoSurface *self, IoObject *locals, IoMessage *m)
137 cairo_surface_flush(SURFACE(self));
138 CHECK_STATUS(self);
139 return self;
143 IoObject *IoCairoSurface_getFontOptions(IoCairoSurface *self, IoObject *locals, IoMessage *m)
145 cairo_font_options_t *options = cairo_font_options_create();
146 cairo_surface_get_font_options(SURFACE(self), options);
147 return IoCairoFontOptions_newWithRawFontOptions_(IOSTATE, m, options);
150 IoObject *IoCairoSurface_getContent(IoCairoSurface *self, IoObject *locals, IoMessage *m)
152 return IONUMBER(cairo_surface_get_content(SURFACE(self)));
156 IoObject *IoCairoSurface_markDirty(IoCairoSurface *self, IoObject *locals, IoMessage *m)
158 cairo_surface_mark_dirty(SURFACE(self));
159 CHECK_STATUS(self);
160 return self;
163 IoObject *IoCairoSurface_markDirtyRectangle(IoCairoSurface *self, IoObject *locals, IoMessage *m)
165 double x = IoMessage_locals_doubleArgAt_(m, locals, 0);
166 double y = IoMessage_locals_doubleArgAt_(m, locals, 1);
167 double w = IoMessage_locals_doubleArgAt_(m, locals, 2);
168 double h = IoMessage_locals_doubleArgAt_(m, locals, 3);
170 cairo_surface_mark_dirty_rectangle(SURFACE(self), x, y, w, h);
171 CHECK_STATUS(self);
172 return self;
176 IoObject *IoCairoSurface_setDeviceOffset(IoCairoSurface *self, IoObject *locals, IoMessage *m)
178 double x = IoMessage_locals_doubleArgAt_(m, locals, 0);
179 double y = IoMessage_locals_doubleArgAt_(m, locals, 1);
181 cairo_surface_set_device_offset(SURFACE(self), x, y);
182 CHECK_STATUS(self);
183 return self;
186 IoObject *IoCairoSurface_getDeviceOffset(IoCairoSurface *self, IoObject *locals, IoMessage *m)
188 double x = 0, y = 0;
190 cairo_surface_get_device_offset(SURFACE(self), &x, &y);
191 CHECK_STATUS(self);
192 return IoSeq_newWithX_y_(IOSTATE, x, y);
196 IoObject *IoCairoSurface_setFallbackResolution(IoCairoSurface *self, IoObject *locals, IoMessage *m)
198 double x = IoMessage_locals_doubleArgAt_(m, locals, 0);
199 double y = IoMessage_locals_doubleArgAt_(m, locals, 1);
201 cairo_surface_set_fallback_resolution(SURFACE(self), x, y);
202 CHECK_STATUS(self);
203 return self;