-static PyMethodDef taglist_functions[] =
-{{"foldAll", taglist_foldAll, METH_VARARGS, "fold all sprites (movieclips) in the list"},
- {"unfoldAll", taglist_unfoldAll, METH_VARARGS, "unfold (expand) all sprites (movieclips) in the list"},
- {"optimizeOrder", taglist_optimizeOrder, METH_VARARGS, "Reorder the Tag structure"},
- {NULL, NULL, 0, NULL}
-};
-
-static PyObject* taglist_getattr(PyObject * self, char* a)
-{
- PyObject* ret = Py_FindMethod(taglist_functions, self, a);
- mylog("taglist_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret);
- return ret;
-}
-//----------------------------------------------------------------------------
-static int taglist_length(PyObject * self)
-{
- TagListObject*tags = (TagListObject*)self;
- TAG*tag;
- int l = 0;
- mylog("taglist_length %08x(%d)", (int)self, self->ob_refcnt);
- tag = tags->firstTag;
- while(tag) {
- l++;
- tag = tag->next;
- }
- return l;
-}
-//----------------------------------------------------------------------------
-static PyObject * taglist_concat(PyObject * self, PyObject* list)
-{
- TagObject*tag;
- TagListObject*taglist = (TagListObject*)self;
- mylog("taglist_concat %08x(%d) %08x", (int)self, self->ob_refcnt, list);
-
- if (PyArg_Parse(list, "O!", &TagClass, &tag)) {
- /* copy tag, so we don't have to do INCREF(tag) (and don't
- get problems if the tag is appended to more than one
- taglist) */
- /* TODO: handle IDs */
- mylog("taglist_concat: Tag", (int)self, self->ob_refcnt);
- taglist->lastTag = swf_InsertTag(taglist->lastTag, tag->tag->id);
- swf_SetBlock(taglist->lastTag, tag->tag->data, tag->tag->len);
- if(!taglist->firstTag) {
- taglist->firstTag = taglist->searchTag = taglist->lastTag;
- }
- if(swf_isDefiningTag(tag->tag)) {
- PyObject*id = PyLong_FromLong(taglist->currentID);
- PyDict_SetItem((PyObject*)(taglist->char2id), list, id);
- Py_INCREF(id);
- PyDict_SetItem((PyObject*)(taglist->id2char), id, list);
- Py_INCREF(id);
- }
- Py_INCREF(self);
- return self;
- }
- PyErr_Clear();
- if (PyList_Check(list)) {
- int l = PyList_Size(list);
- int t;
- mylog("taglist_concat: PythonList", (int)self, self->ob_refcnt);
- for(t=0;t<l;t++) {
- PyObject*item = PyList_GetItem(list, t);
- self = taglist_concat(self, item);
- if(!self)
- return 0;
- }
- Py_INCREF(self);
- return self;
- }
- PyErr_SetString(PyExc_Exception, setError("taglist concatenation only works with tags and lists (%08x).", list));
- return 0;
-}
-//----------------------------------------------------------------------------
-staticforward TagObject* TagObject_New();
-static PyObject * taglist_item(PyObject * self, int index)
-{
- TagListObject*taglist = (TagListObject*)self;
- TAG*tag;
- TagObject*tagobject;
- int i = 0;
- mylog("taglist_item %08x(%d) [%d]", (int)self, self->ob_refcnt, index);
-
- if(index<0) {
- PyErr_SetString(PyExc_Exception, setError("Negative Indices not supported."));
- return NULL;
- }
-
- tag = taglist->firstTag;
- while(tag && i<index) {
- tag = tag->next;
- i++;
- }
- if(!tag || i != index) {
- if(index> i+10) {
- PyErr_SetString(PyExc_Exception, setError("No Tag at position %d", index));
- return NULL;
- }
-
- mylog("taglist_item %08x(%d)->IndexError (%d)", (int)self, self->ob_refcnt, index);
-
- Py_INCREF(PyExc_IndexError);
- PyErr_SetObject(PyExc_IndexError, Py_None);
- return NULL;
- }
-
- tagobject = TagObject_New();
- tagobject->tag = tag;
-
- return (PyObject*)tagobject;
-}
-//----------------------------------------------------------------------------
-static void tag_dealloc(PyObject * self)
-{
- TagObject*tag = (TagObject*)self;
- mylog("tag_dealoc %08x(%d)\n", (int)self, self->ob_refcnt);
- if(tag->placeobject) {
- swf_PlaceObjectFree(tag->placeobject);
- tag->placeobject = 0;
- }
- if(tag->font) {
- swf_FontFree(tag->font);
- tag->font = 0;
- }
- if(tag->character) {
- Py_DECREF(tag->character);
- tag->character = 0;
- }
- PyObject_Del(self);
-}
-//----------------------------------------------------------------------------
-static PyObject* tag_setU8(PyObject * self, PyObject*other)
-{
- return NULL;
-}
-//----------------------------------------------------------------------------
-static PyObject* tag_setbackgroundcolor_getrgb(PyObject * self, PyObject*other)
-{
- TagObject*tag = (TagObject*)self;
- int r,g,b;
- r = tag->tag->data[0];
- g = tag->tag->data[1];
- b = tag->tag->data[2];
- return Py_BuildValue("(iii)", r,g,b);
-}
-//----------------------------------------------------------------------------
-
-static struct tagfunctions {
- int id;
- PyMethodDef f[8];
-} tagfunctions[] =
-{
- {
- ST_SETBACKGROUNDCOLOR,
- {{"getRGB", tag_setbackgroundcolor_getrgb, METH_VARARGS, "get's the color set by this tag"},
- {NULL, NULL, 0, NULL}
- }
- }
-};
-static PyMethodDef common_tagfunctions[] =
-{{"setU8", tag_setU8, METH_VARARGS, "sets a byte to the tag data"},
- {NULL, NULL, 0, NULL}
-};
-
-static PyObject* tag_getattr(PyObject * self, char* a)
-{
- TagObject*tag = (TagObject*)self;
- PyObject* ret = NULL;
- int id = tag->tag->id;
- int t;
-
- /* search for a tag specific function */
- for(t=0;t<sizeof(tagfunctions)/sizeof(tagfunctions[0]);t++)
- {
- if(id==tagfunctions[t].id) {
- mylog("tag_getattr: id %d found\n", id);
- ret = Py_FindMethod(tagfunctions[t].f, self, a);
- break;
- }
- }
-
- /* search in the functions common to all tags */
- FindMethodMore(ret, common_tagfunctions, self, a);
-
- mylog("tag_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret);
- return ret;
-}
-//----------------------------------------------------------------------------
-// Tag Contructors
-//----------------------------------------------------------------------------
-static TagObject* TagObject_New()
-{
- TagObject*tag = PyObject_New(TagObject, &TagClass);
- tag->font = 0;
- tag->character = 0;
- tag->placeobject = 0;
- tag->tag = 0;
- return tag;
-}
-
-static PyObject* f_SetBackgroundColor(PyObject* self, PyObject* args, PyObject* kwargs)
-{
- static char *kwlist[] = {"color", NULL};
- int r=0,g=0,b=0;
- TagObject*tag;
- ColorObject*color;
-
- /* 1st try- copy constructor */
- if(!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &ColorClass, &color)) {
- /* 2nd try- color's contructor */
- color = (ColorObject*)f_Color(NULL, args, kwargs);
- }
- if(!color)
- return NULL;
-
- tag = TagObject_New();
- tag->tag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
- swf_SetU8(tag->tag, color->rgba.r);
- swf_SetU8(tag->tag, color->rgba.g);
- swf_SetU8(tag->tag, color->rgba.b);
- mylog("SetBackgroundColor(%02x,%02x,%02x) %08x -> %08x\n", color->rgba.r, color->rgba.g, color->rgba.b, (int)self, tag);
- return (PyObject*)tag;
-}
-//----------------------------------------------------------------------------
-static PyObject* f_DefineFont(PyObject* self, PyObject* args, PyObject* kwargs)
-{
- static char *kwlist[] = {"filename", NULL};
- char*filename = 0;
- TagObject*tag;
- SWFFONT* font;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &filename))
- return NULL;
-
- font = swf_ReadFont(filename);
- mylog("font=%08x",font);
- if(!font) {
- PyErr_SetString(PyExc_Exception, setError("Could not load %s", filename));
- return NULL;
- }
-
- tag = TagObject_New();
- tag->font = font;
- tag->tag = swf_InsertTag(0, ST_DEFINEFONT2);
- tag->font->id = 0xabcd; // swf_SetU16(id);
- swf_FontSetDefine2(tag->tag, tag->font); // TODO: should this be done later, in taglist?
- mylog("DefineFont %08x -> %08x\n", (int)self, (int)tag);
- return (PyObject*)tag;
-}
-//----------------------------------------------------------------------------
-static PyObject* f_Protect(PyObject* self, PyObject* args, PyObject* kwargs)
-{
- static char *kwlist[] = {"password", NULL};
- char*password = 0;
- TagObject*tag;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &password))
- return NULL;
-
- tag = TagObject_New();
- tag->tag = swf_InsertTag(0, ST_PROTECT);
- if(password) {
- swf_SetPassword(tag->tag, password);
- }
- mylog("f_Protect %08x -> %08x\n", (int)self, (int)tag);
- return (PyObject*)tag;
-}
-//----------------------------------------------------------------------------
-static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs)
-{
- static char *kwlist[] = {"font", "text", "size", "color", NULL};
- TagObject*tag;
- char*text = 0;
- int textlen = 0;
- PyObject*unicode16;
- PyObject*unicode8;
- int size = 0;
- RGBA rgba = {0,0,0,255};
- ColorObject*color = 0;
- TagObject*font = 0;
- SRECT r;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!u#i|O!", kwlist, &TagClass, &font, &text, &textlen, &size, &ColorClass, &color))
- return NULL;
-
- unicode16 = PyUnicode_DecodeUTF16(text, textlen*2, NULL, NULL);
- unicode8 = PyUnicode_AsUTF8String(unicode16);
- text = PyString_AS_STRING(unicode8);
-
- if(color)
- rgba = color->rgba;
-
- mylog("DefineText: text = %s", text);
-
- tag = TagObject_New();
- tag ->tag= swf_InsertTag(0, ST_DEFINETEXT2);
- swf_SetU16(tag->tag, /*ID*/0);
- r = swf_SetDefineText(tag->tag, font->font, &rgba, text, size);
- mylog("DefineText %08x -> %08x\n", (int)self, (int)tag);
- return (PyObject*)tag;
-}
-//----------------------------------------------------------------------------
-static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs)
-{
- static char *kwlist[] = {"character", "depth", "matrix", "colortransform", "ratio", "name", "clipdepth", "action", NULL};
- TagObject*tag;
-
- TagObject*character = 0;
- int depth;
- int clipdepth = 0;
- MatrixObject*matrix = 0;
- CXFormObject*cxform = 0;
- int ratio = 0;
- ActionObject*action = 0;
- char* name = 0;
- SWFPLACEOBJECT* po;
- po = malloc(sizeof(SWFPLACEOBJECT));
- memset(po, 0, sizeof(SWFPLACEOBJECT));
-
- swf_GetPlaceObject(0, po);
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!i|O!O!isiO!", kwlist,
- &TagClass, &character,
- &depth,
- &MatrixClass, &matrix,
- &CXFormClass, &cxform,
- &ratio,
- &name,
- &clipdepth,
- &action
- ))
- return NULL;
- po->depth = depth;
- po->id = /*ID*/ 0;
- po->clipdepth = clipdepth;
- po->ratio = ratio;
- po->name = name;
- if(clipdepth) po->matrix = matrix->matrix;
- if(cxform) po->cxform = cxform->cxform;
- if(action) po->actions = action->action;
-
- tag = TagObject_New();
- tag->placeobject = po;
- Py_INCREF(character);
- tag->character = (PyObject*)character;
- tag->tag= swf_InsertTag(0, ST_PLACEOBJECT2);
- swf_SetPlaceObject(tag->tag, po);
- mylog("PlaceObject %08x -> %08x\n", (int)self, (int)tag);
- return (PyObject*)tag;
-}
-//----------------------------------------------------------------------------