Beispiel #1
0
//----------------------------------------------------------------------------
static PyObject* f_load(PyObject* self, PyObject* args, PyObject* kwargs)
{
    static char *kwlist1[] = {"filename", NULL};
    static char *kwlist2[] = {"data", NULL};
    char* filename = 0;
    char* data = 0;
    int len = 0;
    SWFObject* swf;
    int fi;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist1, &filename)) {
	PyErr_Clear();
	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#", kwlist2, &data, &len)) {
	    PyErr_Clear();
	    PyArg_ParseTupleAndKeywords(args, kwargs, "s:load", kwlist1, &filename);
	    return 0;
	}
    }

    swf = PyObject_New(SWFObject, &SWFClass);
    mylog("+%08x(%d) f_load\n", (int)swf, swf->ob_refcnt);

    memset(&swf->swf, 0, sizeof(SWF));

    if(filename) {
	if(!filename) {
	    PyErr_SetString(PyExc_Exception, setError("Couldn't open file %s", filename));
	    return 0;
	}
	swf->filename = strdup(filename);
	fi = open(filename,O_RDONLY|O_BINARY);
	if (fi<0) { 
	    return PY_ERROR("Couldn't open file %s", filename);
	}
	if(swf_ReadSWF(fi,&swf->swf)<0) { 
	    close(fi);
	    return PY_ERROR("%s is not a valid SWF file or contains errors",filename);
	}
	close(fi);
    } else {
	reader_t r;
	reader_init_memreader(&r, data, len);
	swf->filename = 0;
	if(swf_ReadSWF2(&r, &swf->swf)<0) {
	    return PY_ERROR("<data> is not a valid SWF file or contains errors");
	}
	r.dealloc(&r);
    }
    swf_FoldAll(&swf->swf);

    swf->taglist = taglist_new2(swf->swf.firstTag);
    if(swf->taglist == NULL) {
	return NULL;
    }
    
    swf_FreeTags(&swf->swf);
    swf->swf.firstTag = 0;
    
    return (PyObject*)swf;
}
Beispiel #2
0
void gfxresult_record_replay(gfxresult_t*result, gfxdevice_t*device, gfxfontlist_t**fontlist)
{
    internal_result_t*i = (internal_result_t*)result->internal;
    
    reader_t r;
    if(i->use_tempfile) {
	reader_init_filereader2(&r, i->filename);
    } else {
	reader_init_memreader(&r, i->data, i->length);
    }

    replay(0, device, &r, fontlist);
}
void gfxdevice_record_show(gfxdevice_t*dev)
{
    internal_t*i = (internal_t*)dev->internal;
    writer_t w;

    int len;
    void*data = writer_growmemwrite_memptr(&i->w, &len);

    gfxdevice_t out;
    gfxdevice_dummy_init(&out, NULL);

    reader_t r;
    reader_init_memreader(&r, data, len);
    replay(dev, &out, &r, NULL);
}
Beispiel #4
0
void gfxdevice_record_flush(gfxdevice_t*dev, gfxdevice_t*out, gfxfontlist_t**fontlist)
{
    internal_t*i = (internal_t*)dev->internal;
    if(out) {
	if(!i->use_tempfile) {
	    int len=0;
	    void*data = writer_growmemwrite_memptr(&i->w, &len);
	    reader_t r;
	    reader_init_memreader(&r, data, len);
	    replay(dev, out, &r, fontlist);
	    writer_growmemwrite_reset(&i->w);
	} else {
	    msg("<fatal> Flushing not supported for file based record device");
	    exit(1);
	}
    }
}