X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftag.c;h=65e19b35ec1419fa7afb61fc5a964d2621bf124f;hb=2206626c3b7fa0997a2472a28b78f3d42bfd2ae7;hp=23cf8f9b3133fb8460eec3a751b9f26b00820b31;hpb=c5a01b369d8e9318a980defffe7d805b682f66b3;p=swftools.git diff --git a/lib/python/tag.c b/lib/python/tag.c index 23cf8f9..65e19b3 100644 --- a/lib/python/tag.c +++ b/lib/python/tag.c @@ -24,7 +24,10 @@ typedef struct { static void tag_dealloc(PyObject * self) { TagObject*tag = (TagObject*)self; - mylog(" %08x(%d) tag_dealoc\n", (int)self, self->ob_refcnt); + if(tag->tag) + mylog("-%08x(%d) tag_dealoc [%s]\n", (int)self, self->ob_refcnt, swf_TagGetName(tag->tag)); + else + mylog("-%08x(%d) tag_dealoc [?]\n", (int)self, self->ob_refcnt); if(tag->placeobject) { swf_PlaceObjectFree(tag->placeobject); tag->placeobject = 0; @@ -139,25 +142,33 @@ PyObject* tag_new() PyObject* tag_new2(TAG*t, PyObject* tagmap) { TagObject*tag = PyObject_New(TagObject, &TagClass); - mylog("+%08x(%d) tag_new tag=%08x\n", (int)tag, tag->ob_refcnt, t); + mylog("+%08x(%d) tag_new2 tag=%08x id=%d (%s)\n", (int)tag, tag->ob_refcnt, t, t->id, swf_TagGetName(t)); tag->font = 0; tag->character = 0; tag->placeobject = 0; - tag->tag = t; tag->tagmap = tagmap_new(); + // copy tag + tag->tag = swf_InsertTag(0, t->id); + swf_SetBlock(tag->tag, t->data, t->len); + t = tag->tag; int num = swf_GetNumUsedIDs(t); - int * positions = malloc(num*sizeof(int)); - swf_GetUsedIDs(t, positions); - int i; - for(i=0;idata[positions[i]]); - PyObject*obj = tagmap_id2obj(tagmap, id); - if(obj==NULL) { - PyErr_SetString(PyExc_Exception, setError("TagID %d not defined", id)); - return NULL; + if(num) { // tag has dependencies + int * positions = malloc(num*sizeof(int)); + swf_GetUsedIDs(t, positions); + int i; + for(i=0;idata[positions[i]]); + PyObject*obj = tagmap_id2obj(tagmap, id); + if(obj==NULL) { + PyErr_SetString(PyExc_Exception, setError("TagID %d not defined", id)); + return NULL; + } + //mylog("+%08x(%d) tag_new2 handling id %d at %d/%d\n", (int)tag, tag->ob_refcnt, id, positions[i], t->len); + //mylog("+%08x(%d) tag_new2 add dependency %d to id %d, object %08x(%d)\n", (int)tag, tag->ob_refcnt, i, id, obj, obj->ob_refcnt); + tagmap_addMapping(tag->tagmap, id, obj); } - tagmap_addMapping(tag->tagmap, id, obj); + free(positions); } return (PyObject*)tag; } @@ -184,7 +195,7 @@ static PyObject* f_SetBackgroundColor(PyObject* self, PyObject* args, PyObject* swf_SetU8(tag->tag, rgba.r); swf_SetU8(tag->tag, rgba.g); swf_SetU8(tag->tag, rgba.b); - mylog(" %08x(%d) SetBackgroundColor(%02x,%02x,%02x)\n", (int)tag, tag->ob_refcnt, rgba.r, rgba.g, rgba.b); + mylog(" %08x(%d) SetBackgroundColor(%02x,%02x,%02x) (colorobj=%08x(%d))\n", (int)tag, tag->ob_refcnt, rgba.r, rgba.g, rgba.b, color, color->ob_refcnt); return (PyObject*)tag; } //---------------------------------------------------------------------------- @@ -199,7 +210,6 @@ static PyObject* f_DefineFont(PyObject* self, PyObject* args, PyObject* kwargs) return NULL; font = swf_LoadFont(filename); - mylog("font=%08x",font); if(!font) { PyErr_SetString(PyExc_Exception, setError("Could not load %s", filename)); return NULL; @@ -213,6 +223,12 @@ static PyObject* f_DefineFont(PyObject* self, PyObject* args, PyObject* kwargs) mylog("+%08x(%d) DefineFont\n", (int)tag, tag->ob_refcnt); return (PyObject*)tag; } +static SWFFONT* fonttag_getSWFFONT(PyObject*self) +{ + PY_ASSERT_TYPE(self, &TagClass); + TagObject*font = (TagObject*)self; + return font->font; +} //---------------------------------------------------------------------------- static PyObject* f_Protect(PyObject* self, PyObject* args, PyObject* kwargs) { @@ -243,7 +259,7 @@ static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs) int size = 0; RGBA rgba = {255,0,0,0}; PyObject*color = 0; - TagObject*font = 0; + PyObject*font = 0; SRECT r; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!u#i|O!", kwlist, &TagClass, &font, &text, &textlen, &size, &ColorClass, &color)) @@ -260,14 +276,18 @@ static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs) tag = (TagObject*)tag_new(); - /* notice: we do modify the (passed) font object here, - for the swf_SetDefineText call, who will write out the font id. */ - font->font->id = tagmap_add(tag->tagmap,(PyObject*)font); // add dependency on font + int font_id = tagmap_add(tag->tagmap, font); // add dependency on font + + fonttag_getSWFFONT(font)->id = font_id; tag ->tag= swf_InsertTag(0, ST_DEFINETEXT2); swf_SetU16(tag->tag, /*ID*/0); - r = swf_SetDefineText(tag->tag, font->font, &rgba, text, size); - mylog("+%08x(%d) DefineText %08x -> %08x\n", (int)tag, tag->ob_refcnt); + r = swf_SetDefineText(tag->tag, fonttag_getSWFFONT(font), &rgba, text, size); + mylog("+%08x(%d) DefineText tag=%08x \n", (int)tag, tag->ob_refcnt); + + //Py_DECREF(unicode16); + //Py_DECREF(unicode8); + //free(text); return (PyObject*)tag; } @@ -299,7 +319,7 @@ static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) &ratio, &name, &clipdepth, - &action + &ActionClass, &action )) return NULL; po->depth = depth; @@ -321,58 +341,60 @@ static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) po->id = tagmap_add(tag->tagmap,(PyObject*)character); swf_SetPlaceObject(tag->tag, po); - mylog("+%08x(%d) PlaceObject %08x\n", (int)tag, tag->ob_refcnt, character); - return (PyObject*)tag; -} + mylog("+%08x(%d) PlaceObject %08x(%d)\n", (int)tag, tag->ob_refcnt, character, character->ob_refcnt); -TAG* tag_getRAWTAG(PyObject*self) -{ - TagObject*tag = (TagObject*)self; - return tag->tag; + return (PyObject*)tag; } /* serialize */ TAG* tag_getTAG(PyObject*self, TAG*prevTag, PyObject*tagmap) { TagObject*tag = (TagObject*)self; - TAG* t = tag_getRAWTAG(self); - mylog(" %08x(%d) tag_getTAG tagmap=%08x tag=%08x\n", (int)self, self->ob_refcnt, tagmap, t); - t->next = 0; - t->prev = prevTag; - if(prevTag) - prevTag->next = t; + + mylog(" %08x(%d) tag_getTAG: tag=%08x id=%d (%s)", (int)self, self->ob_refcnt, tag->tag, tag->tag->id, swf_TagGetName(tag->tag)); + + TAG* t = swf_InsertTag(prevTag, tag->tag->id); + swf_SetBlock(t, tag->tag->data, tag->tag->len); + + if(swf_isDefiningTag(t)) { + int newid = tagmap_add(tagmap, self); + swf_SetDefineID(t, newid); + } int num = swf_GetNumUsedIDs(t); - int * positions = malloc(num*sizeof(int)); - swf_GetUsedIDs(t, positions); - int i; - for(i=0;idata[positions[i]]); - PyObject* obj = tagmap_id2obj(tag->tagmap, id); - mylog(" %08x(%d) tag_getTAG: id %d is %08x\n", (int)tag, tag->ob_refcnt, id, obj); - assert(obj!=NULL); - TAG*othertag = tag_getRAWTAG(obj); - int newid = tagmap_add(tagmap, obj); - mylog(" %08x(%d) tag_getTAG: othertag->tagid=%d, new ID: %d\n", (int)tag, tag->ob_refcnt, othertag->id, newid); - - /* here comes the big hack- we define the *other* tags define ID. - This assumes that the other tag is not yet written or processed, - and we are, apart from the calling taglist, the only ones who know - about it. */ - swf_SetDefineID(othertag, newid); - - PUT16(&t->data[positions[i]], newid); + if(num) { // tag has dependencies + int * positions = malloc(num*sizeof(int)); + swf_GetUsedIDs(t, positions); + int i; + for(i=0;idata[positions[i]]); + PyObject* obj = tagmap_id2obj(tag->tagmap, id); + if(obj==NULL) { + PyErr_SetString(PyExc_Exception, setError("Internal error: id %d not known in taglist:")); + free(positions); + return 0; + } + int newid = tagmap_obj2id(tagmap, obj); + PUT16(&t->data[positions[i]], newid); + } + free(positions); } return t; } PyObject* tag_getDependencies(PyObject*self) { - mylog("+%08x(%d) tag_getDependencies\n", (int)self, self->ob_refcnt); TagObject*tag = (TagObject*)self; + mylog(" %08x(%d) tag_getDependencies id=%d tag=%s\n", (int)self, self->ob_refcnt, tag->tag->id, swf_TagGetName(tag->tag)); return tagmap_getObjectList(tag->tagmap); } +int tag_print (PyObject * self, FILE * fi, int flags) +{ + mylog(" %08x(%d) tag_print flags=%08x\n", (int)self, self->ob_refcnt, flags); + return 0; +} + PyTypeObject TagClass = { PyObject_HEAD_INIT(NULL) @@ -381,7 +403,7 @@ PyTypeObject TagClass = tp_basicsize: sizeof(TagObject), tp_itemsize: 0, tp_dealloc: tag_dealloc, - tp_print: 0, + tp_print: tag_print, tp_getattr: tag_getattr, }; static PyMethodDef TagMethods[] =