all: mypython SWF.so
+LIB=-L/usr/lib/python2.2/config/ -lpython2.2
+
primitives.o: primitives.c primitives.h
gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c primitives.c -o primitives.o
+taglist.o: taglist.c taglist.h
+ gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c taglist.c -o taglist.o
+tag.o: tag.c tag.h
+ gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c tag.c -o tag.o
+action.o: action.c action.h
+ gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c action.c -o action.o
pyutils.o: pyutils.c pyutils.h
gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c pyutils.c -o pyutils.o
+
SWF.o: SWF.c pyutils.h primitives.h
gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c SWF.c -o SWF.o
-SWF.so: primitives.o pyutils.o SWF.o
- gcc -shared primitives.o SWF.o pyutils.o -o SWF.so -lpython2.2 ../librfxswf.a -ljpeg -lz
+SWF.so: SWF.o taglist.o tag.o action.o primitives.o pyutils.o ../librfxswf.a
+ gcc -shared SWF.o taglist.o tag.o action.o primitives.o pyutils.o -o SWF.so $(LIB) ../librfxswf.a -ljpeg -lz -lt1 -lfreetype
+ cp SWF.so test
mypython: mypython.c
- gcc -I/usr/include/python2.2 mypython.c -o mypython -lpython2.2
+ gcc -g -I/usr/include/python2.2 mypython.c -o mypython $(LIB) -ldl -lm -lpthread -lutil
test: SWF.so
- python fonts.py
+ cd test;./test_create.py
+ #python fonts.py
+clean:
+ rm *.o *.so mypython
+
+.PHONY: test
#include "../rfxswf.h"
#include "../log.h"
#include "./pyutils.h"
-#include "primitives.h"
-#include "action.h"
+#include "./tag.h"
+#include "./taglist.h"
/*
TODO:
//-------------------------- Types -------------------------------------------
staticforward PyTypeObject SWFClass;
-staticforward PyTypeObject TagListClass;
-staticforward PyTypeObject TagClass;
/* Tags, Objects */
typedef struct {
PyObject_HEAD
- TAG*tag;
- /* ST_DEFINEFONT*/
- SWFFONT* font;
- /* ST_PLACEOBJECT, ST_PLACEOBJECT2*/
- SWFPLACEOBJECT* placeobject;
- PyObject* character;
-} TagObject;
-
-typedef struct {
- PyObject_HEAD
- TAG*firstTag;
- TAG*searchTag;
- TAG*lastTag;
- PyDictObject* char2id;
- PyDictObject* id2char;
- U16 currentID;
-} TagListObject;
-
-typedef struct {
- PyObject_HEAD
SWF swf; //swf.firstTag ist not used
- TagListObject*taglist;
+ PyObject*taglist;
char*filename;
} SWFObject;
+
//----------------------------------------------------------------------------
static PyObject* f_create(PyObject* self, PyObject* args, PyObject* kwargs)
{
swf->swf.fileVersion = version;
swf->swf.frameRate = (int)(framerate*0x100);
swf->swf.movieSize = bbox;
- swf->taglist = PyObject_New(TagListObject, &TagListClass);
- swf->taglist->firstTag = 0;
- swf->taglist->searchTag = 0;
- swf->taglist->lastTag = 0;
- swf->taglist->currentID = 1;
- swf->taglist->char2id = (PyDictObject*)PyDict_New();
- swf->taglist->id2char = (PyDictObject*)PyDict_New();
+ swf->taglist = taglist_new();
if(swf->swf.fileVersion>=6)
swf->swf.compressed = 1;
swf = PyObject_New(SWFObject, &SWFClass);
memset(&swf->swf, 0, sizeof(SWF));
swf->filename = strdup(filename);
- swf->taglist = PyObject_New(TagListObject, &TagListClass);
if(!filename) {
PyErr_SetString(PyExc_Exception, setError("Couldn't open file %s", filename));
return 0;
}
close(fi);
-
- swf->taglist->firstTag = swf->swf.firstTag;
- swf->taglist->searchTag = swf->swf.firstTag;
- swf->taglist->lastTag = swf->swf.firstTag;
- while(swf->taglist->lastTag->next)
- swf->taglist->lastTag = swf->taglist->lastTag->next;
- swf->taglist->currentID = 1;
- swf->taglist->char2id = (PyDictObject*)PyDict_New();
- swf->taglist->id2char = (PyDictObject*)PyDict_New();
swf->swf.firstTag = 0;
+ swf->taglist = taglist_new2(swf->swf.firstTag);
+
mylog("load %08x -> %08x\n", (int)self, (int)swf);
return (PyObject*)swf;
}
if(compress)
swf->compressed = 1;
- swf->firstTag = swfo->taglist->firstTag;
+ swf->firstTag = taglist_getTAGs(swfo->taglist);
// fix the file, in case it is empty or not terminated properly
{
SWFObject*swf = (SWFObject*)self;
if(!self || !PyArg_ParseTuple(args,""))
return NULL;
- swf->swf.firstTag = swf->taglist->firstTag;
+ swf->swf.firstTag = taglist_getTAGs(swf->taglist);
swf_WriteCGI(&swf->swf);
swf->swf.firstTag = 0;
return PY_NONE;
}
//----------------------------------------------------------------------------
-static PyObject * taglist_foldAll(PyObject* self, PyObject* args)
-{
- SWF swf;
- TagListObject*taglist = (TagListObject*)self;
- if(!self || !PyArg_ParseTuple(args,""))
- return NULL;
- swf.firstTag = taglist->firstTag;
- swf_FoldAll(&swf);
- taglist->firstTag = swf.firstTag;
- taglist->lastTag = 0; // FIXME
- taglist->searchTag = 0;
- return PY_NONE;
-}
-//----------------------------------------------------------------------------
-static PyObject * taglist_unfoldAll(PyObject* self, PyObject* args)
-{
- SWF swf;
- TagListObject*taglist = (TagListObject*)self;
- if(!self || !PyArg_ParseTuple(args,""))
- return NULL;
- swf.firstTag = taglist->firstTag;
- swf_UnFoldAll(&swf);
- taglist->firstTag = swf.firstTag;
- taglist->lastTag = 0; // FIXME
- taglist->searchTag = 0;
- return PY_NONE;
-}
-//----------------------------------------------------------------------------
-static PyObject * taglist_optimizeOrder(PyObject* self, PyObject* args)
-{
- SWF swf;
- TagListObject*taglist = (TagListObject*)self;
- if(!self || !PyArg_ParseTuple(args,""))
- return NULL;
- swf.firstTag = taglist->firstTag;
- swf_UnFoldAll(&swf);
- taglist->firstTag = swf.firstTag;
- taglist->lastTag = 0; // FIXME
- taglist->searchTag = 0;
- return PY_NONE;
-}
-//----------------------------------------------------------------------------
//TODO: void swf_Relocate(SWF*swf, char*bitmap); // bitmap is 65536 bytes, bitmap[a]==0 means id a is free
PyObject_Del(self);
}
//----------------------------------------------------------------------------
-static void taglist_dealloc(PyObject* self)
-{
- TagListObject*taglist = (TagListObject*)self;
- SWF swf;
- mylog("taglist_dealloc %08x(%d)\n", (int)self, self->ob_refcnt);
- swf.firstTag = taglist->firstTag;
- swf_FreeTags(&swf);
- taglist->firstTag = 0;
- taglist->lastTag = 0;
- taglist->searchTag = 0;
- PyObject_Del(self);
-}
-//----------------------------------------------------------------------------
static int swf_print(PyObject * self, FILE *fi, int flags) //flags&Py_PRINT_RAW
{
SWFObject*swf = (SWFObject*)self;
mylog("swf_setattr %08x(%d) %s = (%d,%d,%d,%d)\n", (int)self, self->ob_refcnt, a, xmin,ymin,xmax,ymax);
return 0;
} else if(!strcmp(a, "tags")) {
- TagListObject* taglist;
+ PyObject* taglist;
/*if (!PyArg_Parse(o, "O!", &TagListClass, &taglist));
goto err;*/
- taglist = (TagListObject*)o;
+ // TODO: check if it's really a taglist
+ taglist = o;
Py_DECREF(swf->taglist);
swf->taglist = taglist;
Py_INCREF(swf->taglist);
}
//----------------------------------------------------------------------------
-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);
- if(!ret) return ret;
- ret = FindMethodMore(ret, common_tagfunctions, self, a);
- mylog("tag_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret);
- return ret;
- }
- }
-
- ret = Py_FindMethod(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;
-}
-//----------------------------------------------------------------------------
static PyTypeObject SWFClass =
{
PyObject_HEAD_INIT(NULL)
tp_getattr: swf_getattr,
tp_setattr: swf_setattr,
};
-static PySequenceMethods taglist_as_sequence =
-{
- sq_length: taglist_length, // len(obj)
- sq_concat: taglist_concat, // obj += [...], obj1+obj2
- sq_repeat: 0, // x*n, intargfunc
- sq_item: taglist_item, // obj[3]
- sq_slice: 0, // x[i:j] intintargfunc
- sq_ass_item: 0, // x[i] = y intobjargproc
- sq_ass_slice: 0, // x[i:j] = v intintobjargproc
- sq_contains: 0, //???
-};
-static PyTypeObject TagListClass =
+//----------------------------------------------------------------------------
+
+static PyMethodDef SWFMethods[] =
{
- PyObject_HEAD_INIT(NULL)
- 0,
- tp_name: "TagList",
- tp_basicsize: sizeof(TagListObject),
- tp_itemsize: 0,
- tp_dealloc: taglist_dealloc,
- tp_print: 0, // print x
- tp_getattr: taglist_getattr, // x.attr
- tp_setattr: 0, // x.attr = v
- tp_compare: 0, // x>y
- tp_repr: 0, // `x`, print x
- tp_as_number: 0,
- tp_as_sequence: &taglist_as_sequence,
+ /* SWF creation*/
+ {"load", f_load, METH_VARARGS, "Load a SWF from disc."},
+ {"create", (PyCFunction)f_create, METH_KEYWORDS, "Create a new SWF from scratch."},
+ {0,0,0,0}
+ // save is a member function
};
-static PyTypeObject TagClass =
+PyMethodDef* swf_getMethods()
{
- PyObject_HEAD_INIT(NULL)
- 0,
- tp_name: "Tag",
- tp_basicsize: sizeof(TagObject),
- tp_itemsize: 0,
- tp_dealloc: tag_dealloc,
- tp_print: 0,
- tp_getattr: tag_getattr,
-};
-//----------------------------------------------------------------------------
+ SWFClass.ob_type = &PyType_Type;
+ return SWFMethods;
+}
+
+// =============================================================================
+
+#include "primitives.h"
+#include "action.h"
+#include "tag.h"
+#include "taglist.h"
static PyObject* module_verbose(PyObject* self, PyObject* args)
{
return Py_BuildValue("s", 0);
}
-
-static PyMethodDef SWFMethods[] =
+static PyMethodDef LoggingMethods[] =
{
/* Module functions */
{"verbose", module_verbose, METH_VARARGS, "Set the module verbosity"},
-
- /* SWF creation*/
- {"load", f_load, METH_VARARGS, "Load a SWF from disc."},
- {"create", (PyCFunction)f_create, METH_KEYWORDS, "Create a new SWF from scratch."},
-
- /* Primitives */
- {"Color", (PyCFunction)f_Color, METH_KEYWORDS, "Create a new color object."},
- {"Gradient", (PyCFunction)f_Gradient, METH_KEYWORDS, "Create a new gradient object."},
- {"ColorTransform", (PyCFunction)f_ColorTransform, METH_KEYWORDS, "Create a new colortransform object."},
- {"Matrix", (PyCFunction)f_Matrix, METH_KEYWORDS, "Create a new matrix object."},
- {"BBox", (PyCFunction)f_BBox, METH_KEYWORDS, "Create a new bounding box object."},
-
- /* TAGS */
- {"SetBackgroundColor", (PyCFunction)f_SetBackgroundColor, METH_KEYWORDS, "Create a SetBackGroundColor Tag."},
- {"Protect", (PyCFunction)f_Protect, METH_KEYWORDS, "Create a Protect Tag."},
- {"DefineFont", (PyCFunction)f_DefineFont, METH_KEYWORDS, "Create a DefineFont Tag."},
- {"DefineText", (PyCFunction)f_DefineText, METH_KEYWORDS, "Create a DefineText Tag."},
- {"PlaceObject", (PyCFunction)f_PlaceObject, METH_KEYWORDS, "Create a PlaceObject Tag."},
- {NULL, NULL, 0, NULL}
+ {0,0,0,0}
};
-
+
void initSWF(void)
{
- SWFClass.ob_type = &PyType_Type;
+ PyMethodDef* primitive_methods = primitive_getMethods();
+ PyMethodDef* tag_methods = tag_getMethods();
+ PyMethodDef* action_methods = action_getMethods();
+ PyMethodDef* swf_methods = swf_getMethods();
initLog("test.log",8,0,0,0,0);
- (void)Py_InitModule("SWF", SWFMethods);
+ PyMethodDef* all_methods = 0;
+ all_methods = addMethods(all_methods, primitive_methods);
+ all_methods = addMethods(all_methods, tag_methods);
+ all_methods = addMethods(all_methods, action_methods);
+ all_methods = addMethods(all_methods, swf_methods);
+
+ all_methods = addMethods(all_methods, LoggingMethods);
+
+ (void)Py_InitModule("SWF", all_methods);
}
#include "./pyutils.h"
#include "action.h"
+
+typedef struct {
+ PyObject_HEAD
+ ActionTAG*action;
+} ActionObject;
+
PyObject* f_Action(PyObject* self, PyObject* args, PyObject* kwargs)
{
- static char *kwlist[] = {"r", "g", "b", "a", NULL};
+ static char *kwlist[] = {"code", NULL};
ActionObject* action;
- int r=0,g=0,b=0,a=255;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii|i", kwlist, &r,&g,&b,&a))
+ char*code = 0;
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &code))
return NULL;
action = PyObject_New(ActionObject, &ActionClass);
- action->rgba.r = r;
- action->rgba.g = g;
- action->rgba.b = b;
- action->rgba.a = a;
+ action->action = 0;
return (PyObject*)action;
}
static PyObject* action_getattr(PyObject * self, char* a)
{
ActionObject*action = (ActionObject*)self;
- if(!strcmp(a, "r")) {
+/* if(!strcmp(a, "r")) {
return Py_BuildValue("r", action->rgba.r);
} else if(!strcmp(a, "g")) {
return Py_BuildValue("g", action->rgba.g);
return Py_BuildValue("b", action->rgba.b);
} else if(!strcmp(a, "a")) {
return Py_BuildValue("a", action->rgba.a);
- }
+ }*/
return NULL;
}
static int action_setattr(PyObject * self, char* attr, PyObject* o)
{
ActionObject*action = (ActionObject*)self;
- if(!strcmp(attr, "r")) {
+/* if(!strcmp(attr, "r")) {
if (!PyArg_Parse(o, "d", &action->rgba.r)) goto err;
return 0;
} else if(!strcmp(attr, "g")) {
return 0;
}
err:
- mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, attr, o);
+ mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, attr, o);*/
return 1;
}
+ActionTAG* action_getAction(PyObject*self)
+{
+ ActionObject*action= 0;
+ if (!PyArg_Parse(self, "O!", &ActionClass, &action)) {
+ return 0;
+ }
+ return action->action;
+}
+
PyTypeObject ActionClass =
{
PyObject_HEAD_INIT(NULL)
tp_getattr: action_getattr,
tp_setattr: action_setattr,
};
+
+static PyMethodDef action_methods[] =
+{
+ {"Action", (PyCFunction)f_Action, METH_KEYWORDS, "Create a new action object."},
+ {NULL, NULL, 0, NULL}
+};
+
+PyMethodDef* action_getMethods()
+{
+ ActionClass.ob_type = &PyType_Type;
+ return action_methods;
+}
+
-/* action.c
+/* action.h
Python wrapper for librfxswf- actionscript stuff (header)
#include <Python.h>
extern PyTypeObject ActionClass;
-
-typedef struct {
- PyObject_HEAD
- ActionTAG*action;
-} ActionObject;
-
PyObject* f_Action(PyObject* self, PyObject* args, PyObject* kwargs);
+ActionTAG* action_getAction(PyObject* self);
+
+PyMethodDef* action_getMethods();
#endif
#include "./pyutils.h"
#include "primitives.h"
+//----------------------------------------------------------------------------
+typedef struct {
+ PyObject_HEAD
+ RGBA rgba;
+} ColorObject;
+
PyObject* f_Color(PyObject* self, PyObject* args, PyObject* kwargs)
{
static char *kwlist[] = {"r", "g", "b", "a", NULL};
mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, attr, o);
return 1;
}
+RGBA color_getRGBA(PyObject*self)
+{
+ ColorObject*color = 0;
+ if (!PyArg_Parse(self, "O!", &ColorClass, &color)) {
+ RGBA dummy;
+ memset(&dummy, 0, sizeof(dummy));
+ mylog("Error: wrong type for function color_getRGBA");
+ return dummy;
+ }
+ return color->rgba;
+}
+PyTypeObject ColorClass =
+{
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ tp_name: "Color",
+ tp_basicsize: sizeof(ColorObject),
+ tp_itemsize: 0,
+ tp_dealloc: dummy_dealloc,
+ tp_print: 0,
+ tp_getattr: color_getattr,
+ tp_setattr: color_setattr,
+};
//----------------------------------------------------------------------------
+typedef struct {
+ PyObject_HEAD
+ SRECT bbox;
+} BBoxObject;
+
PyObject* f_BBox(PyObject* self, PyObject* args, PyObject* kwargs)
{
static char *kwlist[] = {"xmin", "ymin", "xmax", "ymax", NULL};
mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, a, o);
return 1;
}
+SRECT bbox_getBBox(PyObject*self)
+{
+ BBoxObject*bbox= 0;
+ if (!PyArg_Parse(self, "O!", &BBoxClass, &bbox)) {
+ SRECT dummy;
+ memset(&dummy, 0, sizeof(dummy));
+ mylog("Error: wrong type for function color_getRGBA");
+ return dummy;
+ }
+ return bbox->bbox;
+}
+PyTypeObject BBoxClass =
+{
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ tp_name: "BBox",
+ tp_basicsize: sizeof(BBoxObject),
+ tp_itemsize: 0,
+ tp_dealloc: dummy_dealloc,
+ tp_print: 0,
+ tp_getattr: bbox_getattr,
+ tp_setattr: bbox_setattr,
+};
+SRECT bbox_getBBox(PyObject*self);
//----------------------------------------------------------------------------
+typedef struct {
+ PyObject_HEAD
+ MATRIX matrix;
+} MatrixObject;
+
PyObject* f_Matrix(PyObject* self, PyObject* args, PyObject* kwargs)
{
return NULL;
{
return 0;
}
+MATRIX matrix_getMatrix(PyObject*self)
+{
+ MatrixObject*matrix= 0;
+ if (!PyArg_Parse(self, "O!", &MatrixClass, &matrix)) {
+ MATRIX dummy;
+ memset(&dummy, 0, sizeof(dummy));
+ mylog("Error: wrong type for function color_getRGBA");
+ return dummy;
+ }
+ return matrix->matrix;
+}
+PyTypeObject MatrixClass =
+{
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ tp_name: "Matrix",
+ tp_basicsize: sizeof(MatrixObject),
+ tp_itemsize: 0,
+ tp_dealloc: dummy_dealloc,
+ tp_print: 0,
+ tp_getattr: matrix_getattr,
+ tp_setattr: matrix_setattr,
+ tp_compare: 0,
+ tp_repr: 0,
+ tp_as_number: 0,
+ tp_as_sequence: 0,
+ tp_as_mapping: 0,
+ tp_hash: 0, // dict(x)
+ tp_call: 0, // x()
+ tp_str: 0 // str(x)
+};
//----------------------------------------------------------------------------
+typedef struct {
+ PyObject_HEAD
+ CXFORM cxform;
+} CXFormObject;
+
PyObject* f_ColorTransform(PyObject* self, PyObject* args, PyObject* kwargs)
{
return NULL;
{
return 0;
}
+CXFORM colortransform_getCXForm(PyObject*self)
+{
+ CXFormObject*cxform= 0;
+ if (!PyArg_Parse(self, "O!", &CXFormClass, &cxform)) {
+ CXFORM dummy;
+ memset(&dummy, 0, sizeof(dummy));
+ mylog("Error: wrong type for function color_getRGBA");
+ return dummy;
+ }
+ return cxform->cxform;
+}
+PyTypeObject CXFormClass =
+{
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ tp_name: "ColorTransform",
+ tp_basicsize: sizeof(CXFormObject),
+ tp_itemsize: 0,
+ tp_dealloc: dummy_dealloc,
+ tp_print: 0,
+ tp_getattr: colortransform_getattr,
+ tp_setattr: colortransform_setattr,
+};
//----------------------------------------------------------------------------
+typedef struct {
+ PyObject_HEAD
+ GRADIENT gradient;
+} GradientObject;
+
PyObject* f_Gradient(PyObject* self, PyObject* args, PyObject* kwargs)
{
return NULL;
{
return 0;
}
-//----------------------------------------------------------------------------
-
-PyTypeObject ColorClass =
-{
- PyObject_HEAD_INIT(NULL)
- 0,
- tp_name: "Color",
- tp_basicsize: sizeof(ColorObject),
- tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
- tp_print: 0,
- tp_getattr: color_getattr,
- tp_setattr: color_setattr,
-};
-PyTypeObject BBoxClass =
+GRADIENT colortransform_getGradient(PyObject*self)
{
- PyObject_HEAD_INIT(NULL)
- 0,
- tp_name: "BBox",
- tp_basicsize: sizeof(BBoxObject),
- tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
- tp_print: 0,
- tp_getattr: bbox_getattr,
- tp_setattr: bbox_setattr,
-};
+ GradientObject*gradient = 0;
+ if (!PyArg_Parse(self, "O!", &gradient, &gradient)) {
+ GRADIENT dummy;
+ memset(&dummy, 0, sizeof(dummy));
+ mylog("Error: wrong type for function color_getRGBA");
+ return dummy;
+ }
+ return gradient->gradient;
+}
PyTypeObject GradientClass =
{
PyObject_HEAD_INIT(NULL)
tp_getattr: gradient_getattr,
tp_setattr: gradient_setattr,
};
-PyTypeObject CXFormClass =
+//----------------------------------------------------------------------------
+
+static PyMethodDef primitive_methods[] =
{
- PyObject_HEAD_INIT(NULL)
- 0,
- tp_name: "ColorTransform",
- tp_basicsize: sizeof(CXFormObject),
- tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
- tp_print: 0,
- tp_getattr: colortransform_getattr,
- tp_setattr: colortransform_setattr,
+ {"Color", (PyCFunction)f_Color, METH_KEYWORDS, "Create a new color object."},
+ {"Gradient", (PyCFunction)f_Gradient, METH_KEYWORDS, "Create a new gradient object."},
+ {"ColorTransform", (PyCFunction)f_ColorTransform, METH_KEYWORDS, "Create a new colortransform object."},
+ {"Matrix", (PyCFunction)f_Matrix, METH_KEYWORDS, "Create a new matrix object."},
+ {"BBox", (PyCFunction)f_BBox, METH_KEYWORDS, "Create a new bounding box object."},
+ {NULL, NULL, 0, NULL}
};
-PyTypeObject MatrixClass =
+
+PyMethodDef* primitive_getMethods()
{
- PyObject_HEAD_INIT(NULL)
- 0,
- tp_name: "Matrix",
- tp_basicsize: sizeof(MatrixObject),
- tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
- tp_print: 0,
- tp_getattr: matrix_getattr,
- tp_setattr: matrix_setattr,
- tp_compare: 0,
- tp_repr: 0,
- tp_as_number: 0,
- tp_as_sequence: 0,
- tp_as_mapping: 0,
- tp_hash: 0, // dict(x)
- tp_call: 0, // x()
- tp_str: 0 // str(x)
-};
+ GradientClass.ob_type = &PyType_Type;
+ CXFormClass.ob_type = &PyType_Type;
+ BBoxClass.ob_type = &PyType_Type;
+ MatrixClass.ob_type = &PyType_Type;
+ return primitive_methods;
+}
+
+
#undef HAVE_STAT
#include <Python.h>
+/* exported to allow casting to this type */
extern PyTypeObject ColorClass;
extern PyTypeObject BBoxClass;
extern PyTypeObject CXFormClass;
extern PyTypeObject GradientClass;
extern PyTypeObject MatrixClass;
-typedef struct {
- PyObject_HEAD
- RGBA rgba;
-} ColorObject;
-
-typedef struct {
- PyObject_HEAD
- SRECT bbox;
-} BBoxObject;
-
-typedef struct {
- PyObject_HEAD
- MATRIX matrix;
-} MatrixObject;
-
-typedef struct {
- PyObject_HEAD
- CXFORM cxform;
-} CXFormObject;
-
-typedef struct {
- PyObject_HEAD
- GRADIENT gradient;
-} GradientObject;
-
PyObject* f_Color(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* f_ColorTransform(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* f_Gradient(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* f_BBox(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* f_Matrix(PyObject* self, PyObject* args, PyObject* kwargs);
+
+RGBA color_getRGBA(PyObject*self);
+CXFORM colortransform_getCXForm(PyObject*self);
+GRADIENT gradient_getGradient(PyObject*self);
+SRECT bbox_getBBox(PyObject*self);
+MATRIX matrix_getMatrix(PyObject*self);
+
+extern PyMethodDef* primitive_getMethods();
+
#endif
PyObject_Del(self);
}
+PyMethodDef* addMethods(PyMethodDef*obj1, PyMethodDef*obj2)
+{
+ int num1=0,num2=0;
+ if(obj1) for(num1=0;obj1[num1].ml_name;num1++);
+ if(obj2) for(num2=0;obj2[num2].ml_name;num2++);
+ PyMethodDef* result = malloc(sizeof(PyMethodDef)*(num1+num2+1));
+ memcpy(result, obj1, num1*sizeof(PyMethodDef));
+ memcpy(&result[num1], obj2, (num2+1)*sizeof(PyMethodDef));
+ //free(obj1)?
+ return result;
+}
void mylog(char*format, ...);
PyObject* FindMethodMore(PyObject*ret, PyMethodDef f[], PyObject*self, char* a);
void dummy_dealloc(PyObject* self);
+PyMethodDef* addMethods(PyMethodDef*obj1, PyMethodDef*obj2);
#endif
--- /dev/null
+#include <Python.h>
+#undef HAVE_STAT
+#include "../rfxswf.h"
+#include "../log.h"
+#include "./pyutils.h"
+#include "primitives.h"
+#include "action.h"
+#include "tag.h"
+
+//----------------------------------------------------------------------------
+typedef struct {
+ PyObject_HEAD
+ TAG*tag;
+ /* ST_DEFINEFONT*/
+ SWFFONT* font;
+ /* ST_PLACEOBJECT, ST_PLACEOBJECT2*/
+ SWFPLACEOBJECT* placeobject;
+ PyObject* character;
+} 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;
+
+ /* -- fields -- */
+ if(!strcmp(a, "id")) {
+ return Py_BuildValue("i", id);
+ }
+ if(!strcmp(a, "name")) {
+ char* name = swf_TagGetName(tag->tag);
+ return Py_BuildValue("s", name);
+ }
+ /* ------------ */
+
+ /* 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);
+ if(!ret) return ret;
+ ret = FindMethodMore(ret, common_tagfunctions, self, a);
+ mylog("tag_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret);
+ return ret;
+ }
+ }
+
+ ret = Py_FindMethod(common_tagfunctions, self, a);
+
+ mylog("tag_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret);
+ return ret;
+}
+//----------------------------------------------------------------------------
+// Tag Contructors
+//----------------------------------------------------------------------------
+PyObject* tag_new()
+{
+ TagObject*tag = PyObject_New(TagObject, &TagClass);
+ tag->font = 0;
+ tag->character = 0;
+ tag->placeobject = 0;
+ tag->tag = 0;
+ return (PyObject*)tag;
+}
+PyObject* tag_new2(TAG*_tag)
+{
+ TagObject*tag = PyObject_New(TagObject, &TagClass);
+ tag->font = 0;
+ tag->character = 0;
+ tag->placeobject = 0;
+ tag->tag = _tag;
+ return (PyObject*)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;
+ PyObject*color;
+
+ /* 1st try- copy constructor */
+ if(!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &ColorClass, &color)) {
+ /* 2nd try- color's contructor */
+ color = f_Color(NULL, args, kwargs);
+ }
+ if(!color)
+ return NULL;
+
+ tag = (TagObject*)tag_new();
+ tag->tag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
+ RGBA rgba = color_getRGBA(color);
+ swf_SetU8(tag->tag, rgba.r);
+ swf_SetU8(tag->tag, rgba.g);
+ swf_SetU8(tag->tag, rgba.b);
+ mylog("SetBackgroundColor(%02x,%02x,%02x) %08x -> %08x\n", rgba.r, rgba.g, 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_LoadFont(filename);
+ mylog("font=%08x",font);
+ if(!font) {
+ PyErr_SetString(PyExc_Exception, setError("Could not load %s", filename));
+ return NULL;
+ }
+
+ tag = (TagObject*)tag_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*)tag_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};
+ PyObject*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_getRGBA(color);
+
+ mylog("DefineText: text = %s", text);
+
+ tag = (TagObject*)tag_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;
+ PyObject*matrix = 0;
+ PyObject*cxform = 0;
+ PyObject*action = 0;
+ int ratio = 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_getMatrix(matrix);
+ if(cxform) po->cxform = colortransform_getCXForm(cxform);
+ if(action) po->actions = action_getAction(action);
+
+ tag = (TagObject*)tag_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;
+}
+
+TAG* tag_getTAG(PyObject*self)
+{
+ // TODO: checking!
+ return ((TagObject*)self)->tag;
+}
+
+PyTypeObject TagClass =
+{
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ tp_name: "Tag",
+ tp_basicsize: sizeof(TagObject),
+ tp_itemsize: 0,
+ tp_dealloc: tag_dealloc,
+ tp_print: 0,
+ tp_getattr: tag_getattr,
+};
+static PyMethodDef TagMethods[] =
+{
+ /* TAGS */
+ {"SetBackgroundColor", (PyCFunction)f_SetBackgroundColor, METH_KEYWORDS, "Create a SetBackGroundColor Tag."},
+ {"Protect", (PyCFunction)f_Protect, METH_KEYWORDS, "Create a Protect Tag."},
+ {"DefineFont", (PyCFunction)f_DefineFont, METH_KEYWORDS, "Create a DefineFont Tag."},
+ {"DefineText", (PyCFunction)f_DefineText, METH_KEYWORDS, "Create a DefineText Tag."},
+ {"PlaceObject", (PyCFunction)f_PlaceObject, METH_KEYWORDS, "Create a PlaceObject Tag."},
+ {NULL, NULL, 0, NULL}
+};
+PyMethodDef* tag_getMethods()
+{
+ TagClass.ob_type = &PyType_Type;
+ return TagMethods;
+}
+
--- /dev/null
+/* tag.h
+
+ Python wrapper for librfxswf- tag handlers
+
+ Part of the swftools package.
+
+ Copyright (c) 2003 Matthias Kramm <kramm@quiss.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef __tag_h__
+#define __tag_h__
+
+#include "../rfxswf.h"
+#undef HAVE_STAT
+#include <Python.h>
+
+extern PyTypeObject TagClass;
+
+PyObject* tag_new();
+PyObject* tag_new2(TAG*tag);
+TAG* tag_getTAG(PyObject*self);
+
+PyMethodDef* tag_getMethods();
+#endif
--- /dev/null
+#include <Python.h>
+#undef HAVE_STAT
+#include "../rfxswf.h"
+#include "../log.h"
+#include "./pyutils.h"
+#include "primitives.h"
+#include "action.h"
+#include "tag.h"
+#include "taglist.h"
+
+//----------------------------------------------------------------------------
+typedef struct {
+ PyObject_HEAD
+ TAG*firstTag;
+ TAG*searchTag;
+ TAG*lastTag;
+ PyDictObject* char2id;
+ PyDictObject* id2char;
+ U16 currentID;
+} TagListObject;
+//----------------------------------------------------------------------------
+PyObject * taglist_new()
+{
+ TagListObject* taglist = PyObject_New(TagListObject, &TagListClass);
+ taglist->firstTag = 0;
+ taglist->searchTag = 0;
+ taglist->lastTag = 0;
+ taglist->currentID = 1;
+ taglist->char2id = (PyDictObject*)PyDict_New();
+ taglist->id2char = (PyDictObject*)PyDict_New();
+ return (PyObject*)taglist;
+}
+PyObject * taglist_new2(TAG*tag)
+{
+ TagListObject* taglist = PyObject_New(TagListObject, &TagListClass);
+ taglist->firstTag = tag;
+ taglist->searchTag = tag;
+ taglist->lastTag = tag;
+ while(taglist->lastTag->next)
+ taglist->lastTag = taglist->lastTag->next;
+ taglist->currentID = 1;
+ taglist->char2id = (PyDictObject*)PyDict_New();
+ taglist->id2char = (PyDictObject*)PyDict_New();
+ return (PyObject*)taglist;
+}
+TAG* taglist_getTAGs(PyObject*taglist)
+{
+ // TODO: checking!
+ return ((TagListObject*)taglist)->firstTag;
+}
+//----------------------------------------------------------------------------
+static PyObject * taglist_foldAll(PyObject* self, PyObject* args)
+{
+ SWF swf;
+ TagListObject*taglist = (TagListObject*)self;
+ if(!self || !PyArg_ParseTuple(args,""))
+ return NULL;
+ swf.firstTag = taglist->firstTag;
+ swf_FoldAll(&swf);
+ taglist->firstTag = swf.firstTag;
+ taglist->lastTag = 0; // FIXME
+ taglist->searchTag = 0;
+ return PY_NONE;
+}
+//----------------------------------------------------------------------------
+static PyObject * taglist_unfoldAll(PyObject* self, PyObject* args)
+{
+ SWF swf;
+ TagListObject*taglist = (TagListObject*)self;
+ if(!self || !PyArg_ParseTuple(args,""))
+ return NULL;
+ swf.firstTag = taglist->firstTag;
+ swf_UnFoldAll(&swf);
+ taglist->firstTag = swf.firstTag;
+ taglist->lastTag = 0; // FIXME
+ taglist->searchTag = 0;
+ return PY_NONE;
+}
+//----------------------------------------------------------------------------
+static PyObject * taglist_optimizeOrder(PyObject* self, PyObject* args)
+{
+ SWF swf;
+ TagListObject*taglist = (TagListObject*)self;
+ if(!self || !PyArg_ParseTuple(args,""))
+ return NULL;
+ swf.firstTag = taglist->firstTag;
+ swf_UnFoldAll(&swf);
+ taglist->firstTag = swf.firstTag;
+ taglist->lastTag = 0; // FIXME
+ taglist->searchTag = 0;
+ return PY_NONE;
+}
+//----------------------------------------------------------------------------
+static void taglist_dealloc(PyObject* self)
+{
+ TagListObject*taglist = (TagListObject*)self;
+ SWF swf;
+ mylog("taglist_dealloc %08x(%d)\n", (int)self, self->ob_refcnt);
+ swf.firstTag = taglist->firstTag;
+ swf_FreeTags(&swf);
+ taglist->firstTag = 0;
+ taglist->lastTag = 0;
+ taglist->searchTag = 0;
+ PyObject_Del(self);
+}
+//----------------------------------------------------------------------------
+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)
+{
+ PyObject*tag = 0;
+ TagListObject*taglist = (TagListObject*)self;
+ mylog("taglist_concat %08x(%d) %08x", (int)self, self->ob_refcnt, list);
+
+ /* TODO: rewrite */
+
+ 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_getTAG(tag)->id);
+ swf_SetBlock(taglist->lastTag, tag_getTAG(tag)->data, tag_getTAG(tag)->len);
+ if(!taglist->firstTag) {
+ taglist->firstTag = taglist->searchTag = taglist->lastTag;
+ }
+ if(swf_isDefiningTag(tag_getTAG(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;
+}
+//----------------------------------------------------------------------------
+static PyObject * taglist_item(PyObject * self, int index)
+{
+ TagListObject*taglist = (TagListObject*)self;
+ TAG*tag;
+ PyObject*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 = tag_new2(tag);
+ return (PyObject*)tagobject;
+}
+static PySequenceMethods taglist_as_sequence =
+{
+ sq_length: taglist_length, // len(obj)
+ sq_concat: taglist_concat, // obj += [...], obj1+obj2
+ sq_repeat: 0, // x*n, intargfunc
+ sq_item: taglist_item, // obj[3]
+ sq_slice: 0, // x[i:j] intintargfunc
+ sq_ass_item: 0, // x[i] = y intobjargproc
+ sq_ass_slice: 0, // x[i:j] = v intintobjargproc
+ sq_contains: 0, //???
+};
+static PyTypeObject TagListClass =
+{
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ tp_name: "TagList",
+ tp_basicsize: sizeof(TagListObject),
+ tp_itemsize: 0,
+ tp_dealloc: taglist_dealloc,
+ tp_print: 0, // print x
+ tp_getattr: taglist_getattr, // x.attr
+ tp_setattr: 0, // x.attr = v
+ tp_compare: 0, // x>y
+ tp_repr: 0, // `x`, print x
+ tp_as_number: 0,
+ tp_as_sequence: &taglist_as_sequence,
+};
--- /dev/null
+/* taglist.h
+
+ Python wrapper for librfxswf- taglist handlers, header file
+
+ Part of the swftools package.
+
+ Copyright (c) 2003 Matthias Kramm <kramm@quiss.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef __taglist_h__
+#define __taglist_h__
+
+#include "../rfxswf.h"
+#undef HAVE_STAT
+#include <Python.h>
+
+extern PyTypeObject TagListClass;
+
+PyObject * taglist_new();
+PyObject * taglist_new2(TAG*tag);
+TAG* taglist_getTAGs(PyObject*);
+
+PyMethodDef* taglist_getMethods();
+#endif