X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftag.c;h=f495499fb78c230a9fb429be6afa62e4be13a6ef;hb=bdad407fb79c2f7be9f3603694ebdeadc645b52d;hp=9a53b58fe33741eee9d5e190c21dd0e95531dd33;hpb=a72d10185525aafd3fb4053573c5f44aa521f3d0;p=swftools.git diff --git a/lib/python/tag.c b/lib/python/tag.c index 9a53b58..f495499 100644 --- a/lib/python/tag.c +++ b/lib/python/tag.c @@ -83,7 +83,7 @@ static void tag_dealloc(PyObject * self) tag->internals.data = 0; } if(tag->internals.tag) { - swf_DeleteTag(tag->internals.tag); + swf_DeleteTag(0, tag->internals.tag); tag->internals.tag = 0; } Py_DECREF(tag->internals.tagmap); @@ -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,75 @@ 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_isFont(PyObject * _self, PyObject*args) +{ + TagObject*self = (TagObject*)_self; + if(!PyArg_ParseTuple(args, "")) return NULL; + if(!fillTAG((PyObject*)self)) return NULL; + int id = self->internals.tag->id; + int isfont=0; + if(id == ST_DEFINEFONT || id == ST_DEFINEFONT2) + isfont = 1; + return PyInt_FromLong(isfont); +} +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_isPlacement(PyObject * _self, PyObject*args) +{ + TagObject*self = (TagObject*)_self; + if(!PyArg_ParseTuple(args, "")) return NULL; + if(!fillTAG((PyObject*)self)) return NULL; + return PyInt_FromLong((self->internals.tag->id == ST_PLACEOBJECT || + self->internals.tag->id == ST_PLACEOBJECT2)); +} +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 PyObject* tag_setBBox(PyObject * _self, PyObject*args) +{ + TagObject*self = (TagObject*)_self; + PyObject*bbox = 0; + if(!PyArg_ParseTuple(args, "O!", &BBoxClass, &bbox)) return NULL; + if(!fillTAG((PyObject*)self)) return NULL; + swf_SetDefineBBox(self->internals.tag, bbox_getSRECT(bbox)); + return PY_NONE; +} +//---------------------------------------------------------------------------- +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"}, + {"isFont", tag_isFont, METH_VARARGS, "tests whether the tag is a font"}, + {"isDefiningTag", tag_isDefiningTag, METH_VARARGS, "tests whether the tag is a defining tag"}, + {"isPlacement", tag_isPlacement, METH_VARARGS, "tests whether the tag is a placement"}, + {"getBBox", tag_getBBox, METH_VARARGS, "get's the tags bounding box"}, + {"setBBox", tag_setBBox, METH_VARARGS, "set's the tags bounding box"}, + {NULL, NULL, 0, NULL} +}; + static PyObject* tag_getattr(PyObject * self, char* a) { TagObject*tag = (TagObject*)self; @@ -137,22 +196,48 @@ static PyObject* tag_getattr(PyObject * self, char* a) char* name = swf_TagGetName(tag->internals.tag); return Py_BuildValue("s", name); } + if(!strcmp(a, "data")) { + if(!fillTAG(self)) + return 0; + return Py_BuildValue("s#", tag->internals.tag->data, tag->internals.tag->len); + } + 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(0, 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,7 +336,14 @@ TAG* tag_getTAG(PyObject*self, TAG*prevTag, PyObject*tagmap) } //int newid = tagmap_obj2id(tag->internals.tagmap, obj); int newid = tagmap_obj2id(tagmap, obj); - mylog(" %08x(%d) tag_getTAG: dependency %d) %d->%08x -> assigning(%08x) id %d", (int)self, self->ob_refcnt, i, id, obj, tagmap, newid); + 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); + } PUT16(&t->data[positions[i]], newid); } free(positions); @@ -279,7 +371,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; } //---------------------------------------------------------------------------- @@ -293,4 +386,5 @@ PyTypeObject TagClass = tp_dealloc: tag_dealloc, tp_print: tag_print, tp_getattr: tag_getattr, + tp_setattr: tag_setattr, };