示例#1
0
static cairo_pattern_t* gvloadimage_gs_load(GVJ_t * job, usershape_t *us)
{
    gs_t *gs = NULL;
    gsapi_revision_t gsapi_revision_info;
    void *instance;
    int rc;

    assert(job);
    assert(us);
    assert(us->name);

    if (us->data) {
        if (us->datafree == gvloadimage_gs_free
	&& ((gs_t*)(us->data))->cr == (cairo_t *)job->context)
	    gs = (gs_t*)(us->data); /* use cached data */
	else {
	    us->datafree(us);        /* free incompatible cache data */
	    us->data = NULL;
	}
    }
    if (!gs) {
	gs = (gs_t *)malloc(sizeof(gs_t));
	if (!gs) {
	    job->common->errorfn("malloc() failure\n");
	    return NULL;
	}
	gs->cr = (cairo_t *)job->context;
	gs->surface = NULL;
	gs->pattern = NULL;

	/* cache this - even if things go bad below - avoids repeats */
	us->data = (void*)gs;
	us->datafree = gvloadimage_gs_free;

#define GSAPI_REVISION_REQUIRED 863
	rc = gsapi_revision(&gsapi_revision_info, sizeof(gsapi_revision_t));
        if (rc && rc < sizeof(gsapi_revision_t)) {
    	    job->common->errorfn("gs revision - struct too short %d\n", rc);
	    return NULL;
        }
	if (gsapi_revision_info.revision < GSAPI_REVISION_REQUIRED) {
    	    job->common->errorfn("gs revision - too old %d\n",
		gsapi_revision_info.revision);
	    return NULL;
	}

	rc = gsapi_new_instance(&instance, (void*)job);
	if (rc)
	    gs_error(job, us->name, "gsapi_new_instance", rc);
	else {
	    rc = gsapi_set_stdio(instance, NULL, gs_writer, gs_writer);
	    if (rc)
	        gs_error(job, us->name, "gsapi_set_stdio", rc);
	    else
                rc = gvloadimage_process_surface(job, us, gs, instance);
	    gsapi_delete_instance(instance);
	}
    }
    return gs->pattern;
}
示例#2
0
文件: gsdll.c 项目: hackqiang/gs
/* arguments are:
 * 1. callback function for stdio and for notification of
 *   sync_output, output_page and resize events
 * 2. window handle, used as parent.  Use NULL if you have no window.
 * 3. argc
 * 4. argv
 */
int GSDLLEXPORT GSDLLAPI
gsdll_init_with_encoding(GSDLL_CALLBACK callback, HWND hwnd, int argc, char * argv[], int encoding)
{
    int code;

    if ((code = gsapi_new_instance(&pgs_minst, (void *)1)) < 0)
        return -1;

    gsapi_set_stdio(pgs_minst,
        gsdll_old_stdin, gsdll_old_stdout, gsdll_old_stderr);
    gsapi_set_poll(pgs_minst, gsdll_old_poll);
    /* ignore hwnd */

/* rest of MacGSView compatibilty hack */
#ifdef __MACOS__
        hwndtext=hwnd;
#endif

/****** SINGLE-INSTANCE HACK ******/
    pgsdll_callback = callback;
/****** SINGLE-INSTANCE HACK ******/

    code = gsapi_set_arg_encoding(pgs_minst, encoding);
    if (code >= 0)
        code = gsapi_init_with_args(pgs_minst, argc, argv);
    if (code == e_Quit) {
        gsapi_exit(pgs_minst);
        return GSDLL_INIT_QUIT;
    }
    return code;
}
示例#3
0
文件: test.c 项目: ststeiger/ghostsvg
int main(int argc, char *argv[])
{
    int code;
    const char * gsargv[12];
    char arg[64];
    int gsargc;
    gsargv[0] = "ps2colordetect";	/* actual value doesn't matter */
    gsargv[1] = "-dNOPAUSE";
    gsargv[2] = "-dBATCH";
    gsargv[3] = "-dSAFER";
//    gsargv[4] = "-sDEVICE=pdfwrite";
    gsargv[4] = "-sDEVICE=display";
    gsargv[5] = "-dDisplayHandle=0";
    sprintf(arg,"-dDisplayFormat=%d",DISPLAY_COLORS_RGB|DISPLAY_ALPHA_NONE|DISPLAY_DEPTH_8|DISPLAY_LITTLEENDIAN|DISPLAY_BOTTOMFIRST);
    gsargv[6] = arg;
    gsargv[7] = "-sOutputFile=out.pdf";
    gsargv[8] = "-c";
    gsargv[9] = ".setpdfwrite";
    gsargv[10] = "-f";
//    gsargv[11] = "input.ps";
    gsargv[11] = "-";
    gsargc=12;



    code = gsapi_new_instance(&minst, NULL);
    if (code < 0)
	return 1;
    gsapi_set_stdio(minst, gsdll_stdin, gsdll_stdout, gsdll_stderr);
    gsapi_set_display_callback(minst, &display);

	color_fd=fopen("color.ps","wb");
	black_fd=fopen("black.ps","wb");
	temp_fd=fopen("temp.ps","wb");
	choose=black_fd;

    code = gsapi_init_with_args(minst, gsargc, gsargv);
    gsapi_exit(minst);

    gsapi_delete_instance(minst);

	fclose(color_fd);
	fclose(black_fd);
	fclose(temp_fd);

    if ((code == 0) || (code == e_Quit))
	return 0;
    return 1;
}
示例#4
0
int main(int argc, char *argv[])
{
    int exit_status;
    int code = 1, code1;
    void *instance;
    int exit_code;

    /* run Ghostscript */
    if ((code = gsapi_new_instance(&instance, NULL)) == 0) {
        gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr);
	code = gsapi_init_with_args(instance, argc, argv);

	if (code == 0)
	    code = gsapi_run_string(instance, start_string, 0, &exit_code);
        code1 = gsapi_exit(instance);
	if (code == 0 || code == e_Quit)
	    code = code1;
	if (code == e_Quit)
	    code = 0;	/* user executed 'quit' */

	gsapi_delete_instance(instance);
    }

    exit_status = 0;
    switch (code) {
	case 0:
	case e_Info:
	case e_Quit:
	    break;
	case e_Fatal:
	    exit_status = 1;
	    break;
	default:
	    exit_status = 255;
    }

    return exit_status;
}
示例#5
0
文件: dmmain.c 项目: hackqiang/gs
void main(void)
{
    int code;
    int exit_code;
    int argc;
    char **argv;
    char dformat[64], ddevice[32];
    SInt32        response;

    /* Initialize operating environment */
#if TARGET_API_MAC_CARBON
    MoreMasterPointers(224);
#else
    MoreMasters();
#endif
    InitCursor();
    FlushEvents(everyEvent,0);

    if (AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
                              NewAEEventHandlerUPP((AEEventHandlerProcPtr) quitAppEventHandler),
                              0L,false) != noErr)
        ExitToShell();

        gActionFunctionScrollUPP = NewControlActionUPP(&actionFunctionScroll);

    Gestalt(gestaltMenuMgrAttr,&response);
    if(response & gestaltMenuMgrAquaLayoutMask)
                gRunningOnX = true;

    /* Initialize SIOUX */
    SIOUXSettings.initializeTB = false;
    SIOUXSettings.standalone = false;
    SIOUXSettings.asktosaveonclose = false;
    SIOUXSettings.sleep = GetCaretTime();
    SIOUXSettings.userwindowtitle = "\pGhostscript";

    /* Get arguments from user */
    argc = ccommand(&argv);

    /* Show command line window */
    if (InstallConsole(0))
        ExitToShell();

    /* Part of fudge to make SIOUX accept characters without becoming modal */
    SelectWindow(SIOUXTextWindow->window);
    PostEvent(keyDown, 0x4c00);  // Enter
    ReadCharsFromConsole(dformat, 0x7FFF);
    clrscr();

    /* Add in the display format as the first command line argument */
    if (argc >= MAX_ARGS - 1)
    {
       printf("Too many command line arguments\n");
       return;
    }

    memmove(&argv[3], &argv[1], (argc-1) * sizeof(char**));
    argc += 2;
    argv[1] = ddevice;
    argv[2] = dformat;

    gs_sprintf(ddevice, "-sDEVICE=display");
    gs_sprintf(dformat, "-dDisplayFormat=%d", display_format);

    /* Run Ghostscript */
    if (gsapi_new_instance(&instance, NULL) < 0)
    {
       printf("Can't create Ghostscript instance\n");
       return;
    }

#ifdef DEBUG
    visual_tracer_init();
    set_visual_tracer(&visual_tracer);
#endif

    gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr);
    gsapi_set_poll(instance, gsdll_poll);
    gsapi_set_display_callback(instance, &display);

    code = gsapi_init_with_args(instance, argc, argv);
    if (code == 0)
       code = gsapi_run_string(instance, start_string, 0, &exit_code);
    else
    {
       printf("Failed to initialize. Error %d.\n", code);
       fflush(stdout);
    }
    code = gsapi_exit(instance);
    if (code != 0)
    {
       printf("Failed to terminate. Error %d.\n", code);
       fflush(stdout);
    }

    gsapi_delete_instance(instance);

#ifdef DEBUG
    visual_tracer_close();
#endif

    /* Ghostscript has finished - let user see output before quitting */
    WriteCharsToConsole("\r[Finished - hit any key to quit]", 33);
    fflush(stdout);

    /* Process events until a key is hit or user quits from menu */
    while(!gDone)
    {
        EventRecord eventStructure;

        if(WaitNextEvent(everyEvent,&eventStructure,SIOUXSettings.sleep,NULL))
        {
            if (eventStructure.what == keyDown)
            gDone = true;

            doEvents(&eventStructure);
        }
        else
            SIOUXHandleOneEvent(&eventStructure);
    }
}