X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftag.c;h=5d55fb3e3a9e462992e9c9fe0e886a202bfb6afb;hb=8cbc895c917357a0dea4b8a8b81ff0920eea66e3;hp=94294be889e7970f18128aa3d13ec16793399e91;hpb=c628329ceadd323e389c1349af45fb1e49396f20;p=swftools.git diff --git a/lib/python/tag.c b/lib/python/tag.c index 94294be..5d55fb3 100644 --- a/lib/python/tag.c +++ b/lib/python/tag.c @@ -91,16 +91,6 @@ static void tag_dealloc(PyObject * self) PyObject_Del(self); } //---------------------------------------------------------------------------- -static PyObject* tag_setU8(PyObject * self, PyObject*other) -{ - return NULL; -} -//---------------------------------------------------------------------------- -static PyMethodDef common_tagfunctions[] = -{{"setU8", tag_setU8, METH_VARARGS, "sets a byte to the tag data"}, - {NULL, NULL, 0, NULL} -}; - static int fillTAG(PyObject*self) { TagObject*tag = (TagObject*)self; @@ -119,6 +109,44 @@ static int fillTAG(PyObject*self) } return 1; } +//---------------------------------------------------------------------------- +static PyObject* tag_isShape(PyObject * _self, PyObject*args) +{ + TagObject*self = (TagObject*)_self; + if(!PyArg_ParseTuple(args, "")) return NULL; + if(!fillTAG((PyObject*)self)) return NULL; + return PyInt_FromLong(swf_isShapeTag(self->internals.tag)); +} +static PyObject* tag_isImage(PyObject * _self, PyObject*args) +{ + TagObject*self = (TagObject*)_self; + if(!PyArg_ParseTuple(args, "")) return NULL; + if(!fillTAG((PyObject*)self)) return NULL; + return PyInt_FromLong(swf_isImageTag(self->internals.tag)); +} +static PyObject* tag_isDefiningTag(PyObject * _self, PyObject*args) +{ + TagObject*self = (TagObject*)_self; + if(!PyArg_ParseTuple(args, "")) return NULL; + if(!fillTAG((PyObject*)self)) return NULL; + return PyInt_FromLong(swf_isDefiningTag(self->internals.tag)); +} +static PyObject* tag_getBBox(PyObject * _self, PyObject*args) +{ + TagObject*self = (TagObject*)_self; + if(!PyArg_ParseTuple(args, "")) return NULL; + if(!fillTAG((PyObject*)self)) return NULL; + return f_BBox2(swf_GetDefineBBox(self->internals.tag)); +} +//---------------------------------------------------------------------------- +static PyMethodDef common_tagfunctions[] = +{{"isShape", tag_isShape, METH_VARARGS, "tests whether the tag is a shape tag"}, + {"isImage", tag_isImage, METH_VARARGS, "tests whether the tag is an image"}, + {"isDefiningTag", tag_isDefiningTag, METH_VARARGS, "tests whether the tag is a defining tag"}, + {"getBBox", tag_getBBox, METH_VARARGS, "get's the tags bounding box"}, + {NULL, NULL, 0, NULL} +}; + static PyObject* tag_getattr(PyObject * self, char* a) { TagObject*tag = (TagObject*)self; @@ -137,22 +165,43 @@ static PyObject* tag_getattr(PyObject * self, char* a) char* name = swf_TagGetName(tag->internals.tag); return Py_BuildValue("s", name); } + if(tag->internals.getattr) { + PyObject* ret = tag->internals.getattr(&tag->internals, a); + if(ret) return ret; + } /* search for a tag specific function */ if(tag->internals.tagfunctions) { mylog(" %08x(%d) tag_getattr: tag has specific functions\n", (int)self, self->ob_refcnt); ret = Py_FindMethod(tag->internals.tagfunctions, self, a); - if(!ret) return ret; + if(ret) return ret; + PyErr_Clear(); ret = FindMethodMore(ret, common_tagfunctions, self, a); mylog(" %08x(%d) tag_getattr %s: %08x\n", (int)self, self->ob_refcnt, a, ret); - return ret; + if(ret) return ret; + PyErr_Clear(); } - + ret = Py_FindMethod(common_tagfunctions, self, a); mylog(" %08x(%d) tag_getattr %s: %08x\n", (int)self, self->ob_refcnt, a, ret); return ret; } +static int tag_setattr(PyObject * _self, char* a, PyObject * o) +{ + TagObject*self= (TagObject*)_self; + /* a setattr will almost certainly change the tag data, + so delete the tag */ + if(self->internals.tag) { + swf_DeleteTag(self->internals.tag); + self->internals.tag = 0; + } + if(self->internals.setattr) { + int ret = self->internals.setattr(&self->internals, a, o); + return ret; + } + return 1; +} //---------------------------------------------------------------------------- // Tag Constructors //---------------------------------------------------------------------------- @@ -251,10 +300,14 @@ TAG* tag_getTAG(PyObject*self, TAG*prevTag, PyObject*tagmap) } //int newid = tagmap_obj2id(tag->internals.tagmap, obj); int newid = tagmap_obj2id(tagmap, obj); - if(newid<0) { - PyErr_SetString(PyExc_Exception, setError("Unknown object %08x", obj));return 0; + if(newid>=0) { + mylog(" %08x(%d) tag_getTAG: dependency %d) %d->%08x -> assigning(%08x) id %d", (int)self, self->ob_refcnt, i, id, obj, tagmap, newid); + } else { + /* TODO: this is only needed for sprites, so maybe it should throw an + exception otherwise */ + newid = tagmap_add(tagmap, obj); + mylog(" %08x(%d) tag_getTAG: added dependency %d) %d->%08x -> assigning(%08x) id %d", (int)self, self->ob_refcnt, i, id, obj, tagmap, newid); } - mylog(" %08x(%d) tag_getTAG: dependency %d) %d->%08x -> assigning(%08x) id %d", (int)self, self->ob_refcnt, i, id, obj, tagmap, newid); PUT16(&t->data[positions[i]], newid); } free(positions); @@ -282,7 +335,8 @@ int tag_print(PyObject * self, FILE * fi, int flags) mylog(" %08x(%d) tag_print flags=%08x\n", (int)self, self->ob_refcnt, flags); if(!fillTAG(self)) return -1; - fprintf(fi, "tag-%08x-%d-%s", (int)tag->internals.tag, tag->internals.tag->id, swf_TagGetName(tag->internals.tag)); + //fprintf(fi, "tag-%08x-%d-%s", (int)tag->internals.tag, tag->internals.tag->id, swf_TagGetName(tag->internals.tag)); + fprintf(fi, "%s", swf_TagGetName(tag->internals.tag)); return 0; } //---------------------------------------------------------------------------- @@ -296,4 +350,5 @@ PyTypeObject TagClass = tp_dealloc: tag_dealloc, tp_print: tag_print, tp_getattr: tag_getattr, + tp_setattr: tag_setattr, };