Пример #1
0
gfxdevice_t*create_output_device()
{
    gfxdevice_swf_init(&swf);

    /* set up filter chain */
	
    out = &swf;
    if(flatten) {
        gfxdevice_removeclippings_init(&wrap, &swf);
        out = &wrap;
    }

    if(maxwidth || maxheight) {
        gfxdevice_rescale_init(&rescale, out, maxwidth, maxheight, 0);
        out = &rescale;
    }

    if(filters) {
	gfxfilterchain_t*chain = gfxfilterchain_parse(filters);
	if(!chain) {
	    fprintf(stderr, "Unable to parse filters: %s\n", filters);
	    exit(1);
	}
	out = gfxfilterchain_apply(chain, out);
	gfxfilterchain_destroy(chain);
    }

    /* pass global parameters to output device */
    parameter_t*p = device_config;
    while(p) {
	out->setparameter(out, p->name, p->value);
	p = p->next;
    }
    return out;
}
Пример #2
0
static PyObject* f_createSWF(PyObject* parent, PyObject* args, PyObject* kwargs)
{
    static char *kwlist[] = {NULL};
    if (args && !PyArg_ParseTupleAndKeywords(args, kwargs, "", kwlist))
	return NULL;
    OutputObject*self = PyObject_New(OutputObject, &OutputClass);
    
    self->output_device = (gfxdevice_t*)malloc(sizeof(gfxdevice_t));
    gfxdevice_swf_init(self->output_device);
    return (PyObject*)self;
}
Пример #3
0
int args_callback_option(char*name,char*val) {
    if (!strcmp(name, "o"))
    {
	outputname = val;
	return 1;
    }
    else if (!strcmp(name, "v"))
    {
	loglevel ++;
        setConsoleLogging(loglevel);
	return 0;
    }
    else if (!strcmp(name, "2"))
    {
        xnup = 2;
        ynup = 1;
	return 0;
    }
    else if (!strcmp(name, "4"))
    {
        xnup = 2;
        ynup = 2;
	return 0;
    }
    else if (!strcmp(name, "9"))
    {
        xnup = 3;
        ynup = 3;
	return 0;
    }
    else if (!strcmp(name, "X"))
    {
        maxwidth = atoi(val);
	return 1;
    }
    else if (!strcmp(name, "Y"))
    {
        maxheight = atoi(val);
	return 1;
    }
    else if (!strcmp(name, "q"))
    {
	loglevel --;
        setConsoleLogging(loglevel);
	system_quiet = 1;
	return 0;
    }
    else if (name[0]=='p')
    {
	/* check whether the page range follows the p directly, like 
	   in -p1,2 */
	do {
	    name++;
	} while(*name == 32 || *name == 13 || *name == 10 || *name == '\t');

	if(*name) {
	    pagerange = name;
	    return 0;
	} 
	pagerange = val;	
	return 1;
    }
    else if (!strcmp(name, "P"))
    {
	password = val;
	return 1;
    }
    else if (!strcmp(name, "c"))
    {
	char*s = strdup(val);
	char*x1 = strtok(s, ":");
	char*y1 = strtok(0, ":");
	char*x2 = strtok(0, ":");
	char*y2 = strtok(0, ":");
	if(!(x1 && y1 && x2 && y2)) {
	    fprintf(stderr, "-c option requires four arguments, <x1>:<y1>:<x2>:<y2>\n");
	    exit(1);
	}
	custom_clip = 1;
	clip_x1 = atoi(x1);
	clip_y1 = atoi(y1);
	clip_x2 = atoi(x2);
	clip_y2 = atoi(y2);
	free(s);
	return 1;
    }
    else if (!strcmp(name, "m"))
    {
	char*s = strdup(val);
	char*c = strchr(s, ':');
	if(!c) {
	    fprintf(stderr, "-m option requires two arguments, <x>:<y>\n");
	    exit(1);
	}
	*c = 0;
	custom_move = 1;
	move_x = atoi(val);
	move_y = atoi(c+1);
	free(s);
	return 1;
    }
    else if (!strcmp(name, "s"))
    {
	char*s = val;
	char*c = strchr(s, '=');
	if(c && *c && c[1])  {
	    *c = 0;
	    c++;
	    store_parameter(s,c);
	} else if(!strcmp(s,"help")) {
	    printf("PDF Parameters:\n");
	    gfxsource_t*pdf = gfxsource_pdf_create();
	    pdf->setparameter(pdf, "help", "");
	    gfxdevice_t swf;
	    gfxdevice_swf_init(&swf);
	    printf("SWF Parameters:\n");
	    swf.setparameter(&swf, "help", "");
	    exit(0);
	} else {
	    store_parameter(s,"1");
	}
	return 1;
    }
    else if (!strcmp(name, "S"))
    {
	store_parameter("drawonlyshapes", "1");
	return 0;
    }
    else if (!strcmp(name, "i"))
    {
	store_parameter("ignoredraworder", "1");
	return 0;
    }
#ifndef WIN32
    else if (!strcmp(name, "Q"))
    {
	max_time = atoi(val);
	alarm(max_time);
# ifdef HAVE_SIGNAL_H
        signal(SIGALRM, sigalarm);
# endif
	return 1;
    }
#endif
    else if (!strcmp(name, "z"))
    {
	store_parameter("enablezlib", "1");
	zlib = 1;
	return 0;
    }
    else if (!strcmp(name, "n"))
    {
	store_parameter("opennewwindow", "1");
	return 0;
    }
    else if (!strcmp(name, "I"))
    {
	info_only = 1;
	return 0;
    }
    else if (!strcmp(name, "t"))
    {
	store_parameter("insertstop", "1");
	return 0;
    }
    else if (!strcmp(name, "T"))
    {
	if(!strcasecmp(val, "mx"))
	    store_parameter("flashversion", "6");
	else
	    store_parameter("flashversion", val);

	return 1;
    }
    else if (!strcmp(name, "f"))
    {
	store_parameter("storeallcharacters", "1");
	store_parameter("extrafontdata", "1");
	return 0;
    }
    else if (!strcmp(name, "ff"))
    {
	if(filters) {
	    // append this to the current filter expression (we allow more than one --filter)
	    int l = strlen(filters);
	    int new_len = l + strlen(val) + 2;
	    filters = (char*)realloc(filters, new_len);
	    filters[l] = ':';
	    strcpy(filters+l+1, val);
	} else {
	    filters = strdup(val);
	}
	return 1;
    }
    else if (!strcmp(name, "w"))
    {
	store_parameter("linksopennewwindow", "0");
	return 0;
    }
    else if (!strcmp(name, "O"))
    {
	int level = 1;
	int ret=0;
	if(val&& val[0] && val[1]==0 && isdigit(val[0])) {
	    level = atoi(val);
	    ret=1;
	}
	if(level>=1)
	    store_parameter("poly2bitmap", "1");
	if(level>=2)
	    store_parameter("bitmapfonts", "1");
	if(level>=3)
	    store_parameter("ignoredraworder", "1");
	return ret;
    }
    else if (!strcmp(name, "G"))
    {
	//store_parameter("optimize_polygons", "1");
	flatten = 1;
	return 0;
    }
    else if (!strcmp(name, "F"))
    {
	char *s = strdup(val);
	int l = strlen(s);
	while(l && s[l-1]=='/') {
	    s[l-1] = 0;
	    l--;
	}
	fontpaths[fontpathpos++] = s;
	return 1;
    }
    else if (!strcmp(name, "l"))
    {
	char buf[256];
	sprintf(buf, "%s/default_loader.swf", SWFDIR);
	preloader = strdup(buf);
	return 0;
    }
    else if (!strcmp(name, "b"))
    {
	char buf[256];
	sprintf(buf, "%s/default_viewer.swf", SWFDIR);
	viewer = strdup(buf);
	return 0;
    }
    else if (!strcmp(name, "L"))
    {
	if(val)
	{
	    preloader = val;
	}
	else
	{
	    systemf("ls %s/*_loader.swf", SWFDIR);
	    if(!system_quiet)
		printf("\n");
	    exit(1);
	}
	return 1;
    }
    else if (!strcmp(name, "B"))
    {
	if(val)
	{
	    viewer = val;
	}
	else
	{
	    systemf("ls %s/*_viewer.swf", SWFDIR);
	    if(!system_quiet)
		printf("\n");
	    exit(1);
	}
	return 1;
    }
    else if (!strcmp(name, "j"))
    {
	if(name[1]) {
	    store_parameter("jpegquality", &name[1]);
	    return 0;
	} else {
	    store_parameter("jpegquality", val);
	    return 1;
	}
    }
    else if (!strcmp(name, "V"))
    {	
	printf("pdf2swf - part of %s %s\n", PACKAGE, VERSION);
	exit(0);
    }
    else 
    {
	fprintf(stderr, "Unknown option: -%s\n", name);
	exit(1);
    }
    return 0;
}
Пример #4
0
int main(int argn, char *argv[])
{
    processargs(argn, argv);
    initLog(0,-1,0,0,-1,loglevel);
    
    if(!filename) {
	fprintf(stderr, "Please specify an input file\n");
	exit(1);
    }
    
    if(!outputname)
    {
	if(filename) {
	    outputname = stripFilename(filename, ".out");
	    msg("<notice> Output filename not given. Writing to %s", outputname);
	} 
    }
    if(!outputname)
    {
	fprintf(stderr, "Please use -o to specify an output file\n");
	exit(1);
    }
    is_in_range(0x7fffffff, pagerange);
    if(pagerange)
	driver->setparameter(driver, "pages", pagerange);

    if(!filename) {
	args_callback_usage(argv[0]);
	exit(0);
    }

    gfxdocument_t* doc = driver->open(driver, filename);
    if(!doc) {
        msg("<error> Couldn't open %s", filename);
        exit(1);
    }

    if(!format) {
	char*x = strrchr(outputname, '.');
	if(x) 
	    format = x+1;
    }


    gfxresult_t*result = 0;
#ifdef HAVE_LRF
    if(!strcasecmp(format, "lrf")) {
        gfxdevice_t lrf;
        gfxdevice_lrf_init(&lrf);

        gfxdevice_t rescale;
        gfxdevice_rescale_init(&rescale, &lrf, 592, 732, 0);

        gfxdevice_t*out = &rescale;
        out->setparameter(out, "keepratio", "1");
        out->setparameter(out, "pagepattern", outputname);

        gfxdevice_t bbox2,*bbox=&bbox2;
        gfxdevice_bbox_init(bbox);
        bbox->setparameter(bbox, "graphics", "0");

        int pagenr;

        for(pagenr = 1; pagenr <= doc->num_pages; pagenr++) 
        {
            if(is_in_range(pagenr, pagerange)) {
                gfxpage_t* page = doc->getpage(doc, pagenr);
                bbox->startpage(bbox,-1,-1);
                page->render(page, bbox);
                gfxbbox_t b = gfxdevice_bbox_getbbox(bbox);

                out->startpage(out, b.xmax-b.xmin, b.ymax-b.ymin);
                page->rendersection(page, out, -b.xmin, -b.ymin, 0,0,b.xmax-b.xmin,b.ymax-b.ymin);
                out->endpage(out);

                page->destroy(page);
            }
        }
        result = out->finish(out);
    } else 
#endif
    {
        gfxdevice_t _out,*out=&_out;
        if(!strcasecmp(format, "ocr")) {
            gfxdevice_ocr_init(out);
        } else if(!strcasecmp(format, "swf")) {
            gfxdevice_swf_init(out);
        } else if(!strcasecmp(format, "img") || !strcasecmp(format, "png")) {
            gfxdevice_render_init(out);
	    out->setparameter(out, "antialize", "4");
        } else if(!strcasecmp(format, "txt")) {
            gfxdevice_text_init(out);
        } else if(!strcasecmp(format, "log")) {
            gfxdevice_file_init(out, "/tmp/device.log");
        } else if(!strcasecmp(format, "pdf")) {
            gfxdevice_pdf_init(out);
        } else {
	    msg("<error> Invalid output format: %s", format);
	    exit(1);
	}

        int pagenr;
        for(pagenr = 1; pagenr <= doc->num_pages; pagenr++) 
        {
            if(is_in_range(pagenr, pagerange)) {
                gfxpage_t* page = doc->getpage(doc, pagenr);
                out->startpage(out, page->width, page->height);
                page->render(page, out);
                out->endpage(out);
                page->destroy(page);
            }
        }
        result = out->finish(out);
    }

    if(result) {
	if(result->save(result, outputname) < 0) {
	    exit(1);
	}
	result->destroy(result);
    }

    doc->destroy(doc);

    driver->destroy(driver);
    return 0;
}