3 docCopyright("Daniel Rosengren", 2007)
4 docLicense("BSD revised")
5 docCategory("Graphics")
8 #include "IoCairoPath.h"
9 #include "IoCairoPathElement.h"
14 #define DATA(self) ((IoCairoPathData *)IoObject_dataPointer(self))
15 #define PATH(self) (DATA(self)->path)
18 void *IoMessage_locals_cairoPathArgAt_(IoMessage
*self
, void *locals
, int n
)
20 IoObject
*arg
= IoMessage_locals_valueArgAt_(self
, locals
, n
);
21 if (!ISCAIROPATH(arg
))
22 IoMessage_locals_numberArgAt_errorForType_(self
, locals
, n
, "CairoPath");
27 static IoTag
*IoCairoPath_newTag(void *state
)
29 IoTag
*tag
= IoTag_newWithName_("CairoPath");
30 IoTag_state_(tag
, state
);
31 IoTag_cloneFunc_(tag
, (IoTagCloneFunc
*)IoCairoPath_rawClone
);
32 IoTag_freeFunc_(tag
, (IoTagFreeFunc
*)IoCairoPath_free
);
36 IoCairoPath
*IoCairoPath_proto(void *state
)
38 IoObject
*self
= IoObject_new(state
);
39 IoObject_tag_(self
, IoCairoPath_newTag(state
));
41 IoState_registerProtoWithFunc_(state
, self
, IoCairoPath_proto
);
44 IoMethodTable methodTable
[] = {
45 {"foreach", IoCairoPath_foreach
},
49 IoObject_addMethodTable_(self
, methodTable
);
55 IoCairoPath
*IoCairoPath_rawClone(IoCairoPath
*proto
)
57 IoObject
*self
= IoObject_rawClonePrimitive(proto
);
60 DATA(proto
)->refCount
+= 1;
61 IoObject_setDataPointer_(self
, DATA(proto
));
66 IoCairoPath
*IoCairoPath_newWithRawPath_(void *state
, cairo_path_t
*path
)
68 IoCairoPath
*self
= 0;
70 checkStatus_(state
, 0, path
->status
);
72 self
= IOCLONE(IoState_protoWithInitFunction_(state
, IoCairoPath_proto
));
73 IoObject_setDataPointer_(self
, calloc(1, sizeof(IoCairoPathData
)));
74 DATA(self
)->path
= path
;
75 DATA(self
)->refCount
= 1;
79 void IoCairoPath_free(IoCairoPath
*self
)
84 DATA(self
)->refCount
-= 1;
85 if (DATA(self
)->refCount
> 0)
88 cairo_path_destroy(PATH(self
));
93 cairo_path_t
*IoCairoPath_rawPath(IoCairoPath
*self
)
99 /* ------------------------------------------------------------------------------------------------*/
101 IoObject
*IoCairoPath_foreach(IoCairoPath
*self
, IoObject
*locals
, IoMessage
*m
)
103 cairo_path_t
*path
= PATH(self
);
104 IoList
*elementList
= IoList_new(IOSTATE
);
107 for (i
= 0; i
< path
->num_data
; i
+= path
->data
[i
].header
.length
)
108 IoList_rawAppend_(elementList
, IoCairoPathElement_newWithPath_dataOffset_(IOSTATE
, self
, i
));
110 return IoList_foreach(elementList
, locals
, m
);