Пример #1
0
/* 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;
}
Пример #2
0
static int gvloadimage_process_surface(GVJ_t *job, usershape_t *us, gs_t *gs, void *instance)
{
    cairo_t *cr; /* temp cr for gs */
    int rc, rc2;
    char width_height[20], dpi[10], cairo_context[30];
    char *gs_args[] = {
	"dot",      /* actual value of argv[0] doesn't matter */
	"-dQUIET",
	"-dNOPAUSE",
	"-sDEVICE=cairo",
	cairo_context,
	width_height,
	dpi,
    };
#define GS_ARGC sizeof(gs_args)/sizeof(gs_args[0])

    gs->surface = cairo_surface_create_similar( 
	cairo_get_target(gs->cr),
	CAIRO_CONTENT_COLOR_ALPHA,
	us->x + us->w,
	us->y + us->h);

    cr = cairo_create(gs->surface);  /* temp context for gs */

    sprintf(width_height, "-g%dx%d", us->x + us->w, us->y + us->h);
    sprintf(dpi, "-r%d", us->dpi);
    sprintf(cairo_context, "-sCairoContext=%p", cr);

    rc = gsapi_init_with_args(instance, GS_ARGC, gs_args);

    cairo_destroy(cr); /* finished with temp context */

    if (rc)
	gs_error(job, us->name, "gsapi_init_with_args", rc);
    else
	rc = gvloadimage_process_file(job, us, instance);

    if (rc) {
	cairo_surface_destroy(gs->surface);
	gs->surface = NULL;
    }

    rc2 = gsapi_exit(instance);
    if (rc2) {
	gs_error(job, us->name, "gsapi_exit", rc2);
	return rc2;
    }

    if (!rc) 
        gs->pattern = cairo_pattern_create_for_surface (gs->surface);

    return rc;
}
Пример #3
0
int main(int argc, char *argv[])
{
    int code, code1;
    char* gsargv[10];
    int gsargc;
	
	/* Hideous hack without bound checking */
	
	char out_flag[1024] = { "-sOutputFile=" };
	
	if (argc != 2) {
		return 2;
	}
	
	char* dest = out_flag+13;
	const char* src = argv[1];
	
	while (*dest++=*src++)
		;
		
	dest -= 4;
	src = "pdf";
	
	while (*dest++=*src++)
		;	

    gsargv[0] = "ps2pdf";	/* actual value doesn't matter */
    gsargv[1] = "-dNOPAUSE";
    gsargv[2] = "-dBATCH";
    gsargv[3] = "-dSAFER";
    gsargv[4] = "-sDEVICE=pdfwrite";
    gsargv[5] = out_flag;
    gsargv[6] = "-c";
    gsargv[7] = ".setpdfwrite";
    gsargv[8] = "-f";
    gsargv[9] = argv[1];
    gsargc=10;

    code = gsapi_new_instance(&minst, NULL);
    if (code < 0)
	return 1;
    code = gsapi_init_with_args(minst, gsargc, gsargv);
    code1 = gsapi_exit(minst);
    if ((code == 0) || (code == e_Quit))
	code = code1;

    gsapi_delete_instance(minst);

    if ((code == 0) || (code == e_Quit))
	return 0;
    return 1;
}
Пример #4
0
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;
}
Пример #5
0
GSDLLEXPORT int GSDLLAPI
gsapi_init_with_argsA(void *lib, int argc, char **argv)
{
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
    int code;
    gs_arg_get_codepoint *old;
    if (lib == NULL)
        return gs_error_Fatal;

    old = gs_main_inst_get_arg_decode(get_minst_from_memory(ctx->memory));
    code = gsapi_set_arg_encoding(lib, GS_ARG_ENCODING_LOCAL);
    if (code != 0)
        return code;
    code = gsapi_init_with_args(lib, 2*argc, (char **)argv);
    gs_main_inst_arg_decode(get_minst_from_memory(ctx->memory), old);
    return code;
}
Пример #6
0
int IOemPS::DoConvertion(wchar_t* wPSFile, wchar_t* wPDFFile )
{
    int code, code1;
    void *minst;
    const char * gsargv[10];
    int gsargc;
    char psfile[256];
    char pdffile[256];
    char temp[300];

    wcstombs(psfile, wPSFile, 256 );
    wcstombs(pdffile, wPDFFile, 256 );
    
    gsargv[0] = "ps2pdf";	/* actual value doesn't matter */
    gsargv[1] = "-dNOPAUSE";
    gsargv[2] = "-dBATCH";
    gsargv[3] = "-dSAFER";
    gsargv[4] = "-sDEVICE=pdfwrite";
    sprintf_s(temp, 300, "-sOutputFile=%s", pdffile);
    gsargv[5] = temp;
    gsargv[6] = "-c";
    gsargv[7] = ".setpdfwrite";
    gsargv[8] = "-f";
    gsargv[9] = psfile;
    gsargc=10;

    code = gsapi_new_instance(&minst, NULL);
    if (code < 0)
	   return 1;
    code = gsapi_init_with_args(minst, gsargc, (char**)gsargv);
    code1 = gsapi_exit(minst);
    if ((code == 0) || (code == e_Quit))
	   code = code1;

    gsapi_delete_instance(minst);

    if ((code == 0) || (code == e_Quit))
	   return 0;
    return 1;
}
Пример #7
0
GSDLLEXPORT int GSDLLAPI
gsapi_init_with_argsW(void *lib, int argc, wchar_t **argv)
{
#ifdef GS_NO_UTF8
    /* Cannot call the W entrypoints in a GS_NO_UTF8 build */
    return gs_error_Fatal;
#else
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
    int code;
    gs_arg_get_codepoint *old;
    if (lib == NULL)
        return gs_error_Fatal;

    old = gs_main_inst_get_arg_decode(get_minst_from_memory(ctx->memory));
    code = gsapi_set_arg_encoding(lib, GS_ARG_ENCODING_UTF16LE);
    if (code != 0)
        return code;
    code = gsapi_init_with_args(lib, 2*argc, (char **)argv);
    gs_main_inst_arg_decode(get_minst_from_memory(ctx->memory), old);
    return code;
#endif
}
Пример #8
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;
}
Пример #9
0
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);
    }
}