Updating built in Io code to use += instead of x = x + y
[io/quag.git] / addons / Cairo / source / IoCairoGlyph.c
blobc47011aa68d1886a2dfe58c31d2c8af879b19562
1 /*#io
2 CairoGlyph ioDoc(
3 docCopyright("Daniel Rosengren", 2007)
4 docLicense("BSD revised")
5 docCategory("Graphics")
6 */
8 #include "IoCairoGlyph.h"
9 #include "IoNumber.h"
11 #define GLYPH(self) ((cairo_glyph_t *)IoObject_dataPointer(self))
14 static IoTag *IoCairoGlyph_newTag(void *state)
16 IoTag *tag = IoTag_newWithName_("CairoGlyph");
17 IoTag_state_(tag, state);
18 IoTag_cloneFunc_(tag, (IoTagCloneFunc *)IoCairoGlyph_rawClone);
19 IoTag_freeFunc_(tag, (IoTagFreeFunc *)IoCairoGlyph_free);
20 return tag;
23 IoCairoGlyph *IoCairoGlyph_proto(void *state)
25 IoObject *self = IoObject_new(state);
26 IoObject_tag_(self, IoCairoGlyph_newTag(state));
28 IoObject_setDataPointer_(self, calloc(1, sizeof(cairo_glyph_t)));
30 IoState_registerProtoWithFunc_(state, self, IoCairoGlyph_proto);
33 IoMethodTable methodTable[] = {
34 {"setIndex", IoCairoGlyph_setIndex},
35 {"index", IoCairoGlyph_index},
37 {"setX", IoCairoGlyph_setX},
38 {"x", IoCairoGlyph_x},
40 {"setY", IoCairoGlyph_setY},
41 {"y", IoCairoGlyph_y},
43 {NULL, NULL},
45 IoObject_addMethodTable_(self, methodTable);
47 return self;
50 IoCairoGlyph *IoCairoGlyph_rawClone(IoCairoGlyph *proto)
52 IoObject *self = IoObject_rawClonePrimitive(proto);
53 IoObject_setDataPointer_(self, cpalloc(IoObject_dataPointer(proto), sizeof(cairo_glyph_t)));
54 return self;
57 IoCairoGlyph *IoCairoGlyph_newWithRawGlyph_(void *state, cairo_glyph_t *glyph)
59 IoCairoGlyph *self = IOCLONE(IoState_protoWithInitFunction_(state, IoCairoGlyph_proto));
60 memcpy(GLYPH(self), glyph, sizeof(cairo_glyph_t));
61 return self;
64 void IoCairoGlyph_free(IoCairoGlyph *self)
66 free(IoObject_dataPointer(self));
70 cairo_glyph_t *IoCairoGlyph_rawGlyph(IoCairoGlyph *self)
72 return GLYPH(self);
76 /* ------------------------------------------------------------------------------------------------*/
78 IoObject *IoCairoGlyph_setIndex(IoCairoGlyph *self, IoObject *locals, IoMessage *m)
80 GLYPH(self)->index = IoMessage_locals_intArgAt_(m, locals, 0);
81 return self;
84 IoObject *IoCairoGlyph_index(IoCairoGlyph *self, IoObject *locals, IoMessage *m)
86 return IONUMBER(GLYPH(self)->index);
90 IoObject *IoCairoGlyph_setX(IoCairoGlyph *self, IoObject *locals, IoMessage *m)
92 GLYPH(self)->x = IoMessage_locals_doubleArgAt_(m, locals, 1);
93 return self;
96 IoObject *IoCairoGlyph_x(IoCairoGlyph *self, IoObject *locals, IoMessage *m)
98 return IONUMBER(GLYPH(self)->x);
102 IoObject *IoCairoGlyph_setY(IoCairoGlyph *self, IoObject *locals, IoMessage *m)
104 GLYPH(self)->y = IoMessage_locals_doubleArgAt_(m, locals, 2);
105 return self;
108 IoObject *IoCairoGlyph_y(IoCairoGlyph *self, IoObject *locals, IoMessage *m)
110 return IONUMBER(GLYPH(self)->y);
114 /* ------------------------------------------------------------------------------------------------*/
116 cairo_glyph_t *rawGlyphsFromList_count_(IoList *glyphList, int *count)
118 int glyphCount = IoList_rawSize(glyphList);
119 cairo_glyph_t *glyphs = 0;
120 int i;
122 if (count)
123 *count = glyphCount;
125 if (glyphCount == 0)
126 return 0;
128 glyphs = malloc(sizeof(cairo_glyph_t) * glyphCount);
129 for (i = 0; i < glyphCount; i++)
131 cairo_glyph_t *glyph = IoCairoGlyph_rawGlyph(IoList_rawAt_(glyphList, i));
132 memcpy(glyphs + i, glyph, sizeof(cairo_glyph_t));
135 return glyphs;