X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftags.c;h=7235e1ee0afc555d9538e885af4f95383945d355;hb=62ee6091193d1a7827f0f5c9669bb5b05de9939e;hp=329b69f449c6a1497ea8a10614102c16c859011d;hpb=e8d1f9a89eefc8035f91e296f1f6e6833d88b000;p=swftools.git diff --git a/lib/python/tags.c b/lib/python/tags.c index 329b69f..7235e1e 100644 --- a/lib/python/tags.c +++ b/lib/python/tags.c @@ -1,6 +1,7 @@ #include "pyutils.h" #include "primitives.h" #include "action.h" +#include "taglist.h" #include "tag.h" #include "tags.h" #include "image.h" @@ -72,6 +73,8 @@ static tag_internals_t font_tag = parse: font_parse, fillTAG: font_fillTAG, dealloc: font_dealloc, + getattr: 0, + setattr: 0, tagfunctions: 0, datasize: sizeof(font_internal_t), }; @@ -172,6 +175,8 @@ static tag_internals_t placeobject_tag = parse: po_parse, fillTAG: po_fillTAG, dealloc: po_dealloc, + getattr: 0, + setattr: 0, tagfunctions: 0, datasize: sizeof(placeobject_internal_t), }; @@ -223,6 +228,8 @@ static tag_internals_t bgcolor_tag = parse: 0, fillTAG: 0, dealloc: 0, + getattr: 0, + setattr: 0, tagfunctions: setbgcolor_methods, datasize: 0, }; @@ -250,6 +257,8 @@ static tag_internals_t protect_tag = parse: 0, fillTAG: 0, dealloc: 0, + getattr: 0, + setattr: 0, tagfunctions: 0, datasize: 0, }; @@ -273,16 +282,129 @@ static tag_internals_t showframe_tag = parse: 0, fillTAG: 0, dealloc: 0, + getattr: 0, + setattr: 0, tagfunctions: 0, datasize: 0, }; //---------------------------------------------------------------------------- +staticforward tag_internals_t removeobject_tag; +static PyObject* f_RemoveObject(PyObject* self, PyObject* args, PyObject* kwargs) +{ + static char *kwlist[] = {"depth", NULL}; + int depth; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &depth)) + return NULL; + + PyObject*tag = tag_new(&removeobject_tag); + tag_internals_t*itag = tag_getinternals(tag); + itag->tag = swf_InsertTag(0, ST_REMOVEOBJECT); + swf_SetU16(itag->tag, depth); + mylog("+%08x(%d) f_RemoveObject", (int)tag, tag->ob_refcnt); + return (PyObject*)tag; +} +static tag_internals_t removeobject_tag = +{ + parse: 0, + fillTAG: 0, + dealloc: 0, + getattr: 0, + setattr: 0, + tagfunctions: 0, + datasize: 0, +}; +//---------------------------------------------------------------------------- +staticforward tag_internals_t sprite_tag; +typedef struct _sprite_internal +{ + PyObject* taglist; +} sprite_internal_t; + +static int sprite_fillTAG(tag_internals_t*self) +{ + mylog("+%08x(?) sprite_fillTAG", (int)self); + + sprite_internal_t*si = (sprite_internal_t*)self->data; + + TAG*sprite = swf_InsertTag(0, ST_DEFINESPRITE); + swf_SetU16(sprite, 0); //id + swf_SetU16(sprite, 0); //frames + + TAG*tag = taglist_getTAGs2(si->taglist, self->tagmap, 0); + if(!tag) { + /* pass through exception */ + return 0; + } + TAG*tag2 = tag; + while(tag2->next) tag2 = tag2->next; + swf_InsertTag(tag2, ST_END); + + sprite->next = tag; + tag->prev = sprite; + + swf_FoldSprite(sprite); + self->tag = sprite; + return 1; +} + +static PyObject* f_Sprite(PyObject* self, PyObject* args, PyObject* kwargs) +{ + static char *kwlist[] = {"name", NULL}; + char*name= 0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &name)) + return NULL; + + PyObject*tag = tag_new(&sprite_tag); + tag_internals_t*itag = tag_getinternals(tag); + sprite_internal_t*si = (sprite_internal_t*)itag->data; + si->taglist = taglist_new(); + mylog("+%08x(%d) f_DefineSprite", (int)tag, tag->ob_refcnt); + return (PyObject*)tag; +} +static PyObject* sprite_getattr(tag_internals_t*self,char*a) +{ + sprite_internal_t*si = (sprite_internal_t*)self->data; + if(!strcmp(a, "tags")) { + Py_INCREF(si->taglist); + return si->taglist; + } + return 0; +} +static int sprite_setattr(tag_internals_t*self,char*a, PyObject*obj) +{ + sprite_internal_t*si = (sprite_internal_t*)self->data; + if(self->tag) { + swf_DeleteTag(self->tag); + self->tag = 0; + } + if(!strcmp(a, "tags")) { + PY_ASSERT_TYPE(obj,&TagListClass); + Py_DECREF(si->taglist); + si->taglist = obj; + Py_INCREF(si->taglist); + return 0; + } + return 1; +} +static tag_internals_t sprite_tag = +{ + parse: 0, + fillTAG: sprite_fillTAG, + dealloc: 0, + getattr: sprite_getattr, + setattr: sprite_setattr, + tagfunctions: 0, + datasize: sizeof(sprite_internal_t), +}; +//---------------------------------------------------------------------------- staticforward tag_internals_t end_tag; static tag_internals_t end_tag = { parse: 0, fillTAG: 0, dealloc: 0, + getattr: 0, + setattr: 0, tagfunctions: 0, datasize: 0, }; @@ -295,6 +417,7 @@ typedef struct _text_internal SWFFONT* swffont; RGBA rgba; int size; + SRECT bbox; } text_internal_t; staticforward tag_internals_t placeobject_tag; @@ -303,28 +426,35 @@ static int text_fillTAG(tag_internals_t*self) text_internal_t*ti = (text_internal_t*)self->data; self->tag= swf_InsertTag(0, ST_DEFINETEXT2); swf_SetU16(self->tag, /*ID*/0); - SRECT r = swf_SetDefineText(self->tag, ti->swffont, &ti->rgba, ti->text, ti->size); + ti->bbox = swf_SetDefineText(self->tag, ti->swffont, &ti->rgba, ti->text, ti->size); return 1; } +static PyObject* text_getattr(tag_internals_t*self,char*a) +{ + text_internal_t*si = (text_internal_t*)self->data; + if(!strcmp(a, "bbox")) { + return f_BBox2(si->bbox); + } + return 0; +} static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs) { static char *kwlist[] = {"font", "text", "size", "color", NULL}; PyObject*tag = 0; + PyObject*otext; char*text = 0; - int textlen = 0; - PyObject*unicode16; - PyObject*unicode8; int size = 0; RGBA rgba = {255,0,0,0}; PyObject*color = 0; PyObject*font = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!u#i|O!", kwlist, &TagClass, &font, &text, &textlen, &size, &ColorClass, &color)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!Oi|O!", kwlist, &TagClass, &font, &otext, &size, &ColorClass, &color)) return NULL; - - unicode16 = PyUnicode_DecodeUTF16(text, textlen*2, NULL, NULL); - unicode8 = PyUnicode_AsUTF8String(unicode16); - text = PyString_AS_STRING(unicode8); + if(PyUnicode_Check(otext)) { + text = PyString_AS_STRING(PyUnicode_AsUTF8String(otext)); + } else if(PyString_Check(otext)) { + text = PyString_AS_STRING(otext); + } if(color) rgba = color_getRGBA(color); @@ -349,6 +479,8 @@ static tag_internals_t text_tag = parse: 0, fillTAG: text_fillTAG, dealloc: 0, + getattr: text_getattr, + setattr: 0, tagfunctions: 0, datasize: sizeof(text_internal_t), }; @@ -424,6 +556,8 @@ static tag_internals_t image_tag = parse: 0, fillTAG: image_fillTAG, dealloc: image_dealloc, + getattr: 0, + setattr: 0, tagfunctions: 0, datasize: sizeof(image_internal_t), }; @@ -480,6 +614,8 @@ static tag_internals_t shape_tag = parse: 0, fillTAG: shape_fillTAG, dealloc: shape_dealloc, + getattr: 0, + setattr: 0, tagfunctions: 0, datasize: sizeof(shape_internal_t), }; @@ -691,6 +827,8 @@ static tag_internals_t videostream_tag = parse: videostream_parse, fillTAG: videostream_fillTAG, dealloc: videostream_dealloc, + getattr: 0, + setattr: 0, tagfunctions: videostream_methods, datasize: sizeof(videostream_internal_t), }; @@ -702,6 +840,8 @@ static tag_internals_t videoframe_tag = parse: 0, fillTAG: 0, dealloc: 0, + getattr: 0, + setattr: 0, tagfunctions: 0, datasize: 0 }; @@ -716,11 +856,13 @@ static PyMethodDef TagMethods[] = {"Font", (PyCFunction)f_DefineFont, METH_KEYWORDS, "Create a DefineFont Tag."}, {"Text", (PyCFunction)f_DefineText, METH_KEYWORDS, "Create a DefineText Tag."}, {"PlaceObject", (PyCFunction)f_PlaceObject, METH_KEYWORDS, "Create a PlaceObject Tag."}, + {"RemoveObject", (PyCFunction)f_RemoveObject, METH_KEYWORDS, "Create a RemoveObject Tag."}, {"MoveObject", (PyCFunction)f_MoveObject, METH_KEYWORDS, "Create a PlaceObject Move Tag."}, {"VideoStream", (PyCFunction)f_DefineVideoStream, METH_KEYWORDS, "Create a Videostream."}, {"Image", (PyCFunction)f_DefineImage, METH_KEYWORDS, "Create an SWF Image Tag."}, {"ImageShape", (PyCFunction)f_DefineImageShape, METH_KEYWORDS, "Create an SWF Image Shape Tag."}, {"ShowFrame", (PyCFunction)f_ShowFrame, METH_KEYWORDS, "Create an SWF Show Frame Tag."}, + {"Sprite", (PyCFunction)f_Sprite, METH_KEYWORDS, "Create an SWF Sprite Tag."}, {NULL, NULL, 0, NULL} }; PyMethodDef* tags_getMethods() @@ -729,6 +871,8 @@ PyMethodDef* tags_getMethods() register_tag(ST_PLACEOBJECT,&placeobject_tag); register_tag(ST_PLACEOBJECT2,&placeobject_tag); + register_tag(ST_REMOVEOBJECT,&removeobject_tag); + register_tag(ST_REMOVEOBJECT2,&removeobject_tag); register_tag(ST_SETBACKGROUNDCOLOR,&bgcolor_tag); register_tag(ST_DEFINEFONT,&font_tag); register_tag(ST_PROTECT,&protect_tag); @@ -738,6 +882,10 @@ PyMethodDef* tags_getMethods() register_tag(ST_DEFINEBITSJPEG3,&image_tag); register_tag(ST_DEFINEBITSLOSSLESS,&image_tag); register_tag(ST_DEFINEBITSLOSSLESS2,&image_tag); + register_tag(ST_SHOWFRAME,&showframe_tag); + register_tag(ST_DEFINEVIDEOSTREAM,&videostream_tag); + register_tag(ST_VIDEOFRAME,&videoframe_tag); + register_tag(ST_DEFINESPRITE,&sprite_tag); register_tag(ST_END,&end_tag); return TagMethods;