コード例 #1
0
ファイル: SWF.c プロジェクト: DJwa163/swftools
//----------------------------------------------------------------------------
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;
}
コード例 #2
0
ファイル: swfcombine.c プロジェクト: MaChao5/pdfviewer-win32
int combine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
{
    slavename = slave_name;
    slaveid = -1;
    slaveframe = -1;

    if(!master->fileVersion && slave)
	master->fileVersion = slave->fileVersion;
        
    master->fileAttributes |= slave->fileAttributes;

    swf_FoldAll(master);
    swf_FoldAll(slave);

    if(slavename[0] == '#')
    {
	slaveid = atoi(&slavename[1]);
	slavename = 0;
    }

    if(config.isframe)
    {
	if(slavename && slavename[0]!='#') {
	    int tmp;
	    int len;
	    sscanf(slavename, "%d%n", &tmp, &len);
	    if(len == strlen(slavename)) {
	    /* if the name the slave should replace 
	       consists only of digits and the -f
	       option is given, it probably is not
	       a frame name but a frame number.
	     */
		slaveid = tmp;
		slavename = 0;
	    }
	}

	if(slaveid>=0) {
	    slaveframe = slaveid;
	    slaveid = -1;
	} else {
	/* if id wasn't given as either #number or number,
	   the name is a frame label. BTW: The user wouldn't necessarily have
	   needed to supply the -f option in this case */
	}
    }

    msg("<debug> move x (%d)", config.movex);
    msg("<debug> move y (%d)", config.movey);
    msg("<debug> scale x (%f)", config.scalex);
    msg("<debug> scale y (%f)", config.scaley);
    msg("<debug> master move x (%d)", config.mastermovex);
    msg("<debug> master move y (%d)", config.mastermovey);
    msg("<debug> master scale x (%f)", config.masterscalex);
    msg("<debug> master scale y (%f)", config.masterscaley);
    msg("<debug> is frame (%d)", config.isframe);
    
    memset(masterbitmap, 0, sizeof(masterbitmap));

    if(config.cat) 
	return catcombine(master, slave_name, slave, newswf);
    else
	return normalcombine(master, slave_name, slave, newswf);
}