Exemple #1
0
static int
mac_put_params(gx_device *dev, gs_param_list *plist)
{
        gx_device_macos		*mdev	= (gx_device_macos *)dev;

        int						isOpen = mdev->is_open;
        int						code;
        int						depth;
    gs_param_string			outputFile;

        // Get the BitsPerPixel Parameter
        code = param_read_int(plist, "BitsPerPixel", &depth);
        if (!code) {
                code = mac_set_colordepth(dev, depth);
                if (code)
                        param_return_error(plist, "BitsPerPixel", gs_error_rangecheck);
        }

        // Get OutputFile
        code = param_read_string(plist, "OutputFile", &outputFile);
        if (code < 0) {
                param_signal_error(plist, "OutputFile", code);
                return code;
        } else if (code == 0) {

                if (dev->LockSafetyParams &&
                        bytes_compare(outputFile.data, outputFile.size,
                            (const byte *)mdev->outputFileName, strlen(mdev->outputFileName))) {
                        param_signal_error(plist, "OutputFile", gs_error_invalidaccess);
                        return gs_error_invalidaccess;
                }
                if (outputFile.size > (gp_file_name_sizeof - 1)) {
                        param_signal_error(plist, "OutputFile", gs_error_limitcheck);
                        return gs_error_limitcheck;
                }

                /* If filename changed, close file. */
                if (outputFile.data != 0 &&
                                bytes_compare(outputFile.data, outputFile.size,
                                        (const byte *)mdev->outputFileName, strlen(mdev->outputFileName))) {
                        /* Close the file if it's open. */
                        if (mdev->outputFile != NULL) {
                        gx_device_close_output_file(dev, mdev->outputFileName, mdev->outputFile);
                                memcpy(mdev->outputFileName, outputFile.data, outputFile.size);
                                mdev->outputFileName[outputFile.size] = 0;
                                gx_device_open_output_file(dev, mdev->outputFileName, true, true, &(mdev->outputFile));
                    } else {
                                memcpy(mdev->outputFileName, outputFile.data, outputFile.size);
                                mdev->outputFileName[outputFile.size] = 0;
                    }
            }
        }

        // Get the Default Parameters
        mdev->is_open = 0;
        code = gx_default_put_params( dev, plist );
        mdev->is_open = isOpen;

        return code;
}
Exemple #2
0
static int
txtwrite_open_device(gx_device * dev)
{
    int code;
    gx_device_txtwrite_t *const tdev = (gx_device_txtwrite_t *) dev;

    gx_device_fill_in_procs(dev);
    if (tdev->fname[0] == 0)
        return_error(gs_error_undefinedfilename);
    code = gx_device_open_output_file(dev, tdev->fname,
		true, false, &tdev->file); /* binary, sequential */
    if (code < 0)
        return code;
    return 0;
}
Exemple #3
0
static int
mac_save_pict(gx_device * dev)
{
	gx_device_macos		* mdev = (gx_device_macos *)dev;
	int					code = 0;
	int					i;
	
	if (mdev->outputFile == NULL) {
		code = gx_device_open_output_file(dev, mdev->outputFileName, true, true, &(mdev->outputFile));
		if (code < 0) return code;
	}
	
	for (i=0; i<512; i++) fputc(0, mdev->outputFile);
	fwrite(*(mdev->pic), sizeof(char), ((long) mdev->currPicPos - (long) *mdev->pic + 2), mdev->outputFile);
	
	gx_device_close_output_file(dev, mdev->outputFileName, mdev->outputFile);
	mdev->outputFile = NULL;
	
	return code;
}
Exemple #4
0
/* Open the output file and stream. */
int
gdev_vector_open_file_options(gx_device_vector * vdev, uint strmbuf_size,
                              int open_options)
{
    bool binary = !(open_options & VECTOR_OPEN_FILE_ASCII);
    int code = -1;		/* (only for testing, never returned) */
    cmm_dev_profile_t *icc_struct;

    /* Open the file as seekable or sequential, as requested. */
    if (!(open_options & VECTOR_OPEN_FILE_SEQUENTIAL)) {
        /* Try to open as seekable. */
        code =
            gx_device_open_output_file((gx_device *)vdev, vdev->fname,
                                       binary, true, &vdev->file);
    }
    if (code < 0 && (open_options & (VECTOR_OPEN_FILE_SEQUENTIAL |
                                     VECTOR_OPEN_FILE_SEQUENTIAL_OK))) {
        /* Try to open as sequential. */
        code = gx_device_open_output_file((gx_device *)vdev, vdev->fname,
                                          binary, false, &vdev->file);
    }
    if ((code >= 0) && (dev_proc(vdev, get_profile) != NULL)) {
        code = dev_proc(vdev, get_profile)((gx_device *)vdev, &icc_struct);
    }

    if (code < 0)
        return code;
    if ((vdev->strmbuf = gs_alloc_bytes(vdev->v_memory, strmbuf_size,
                                        "vector_open(strmbuf)")) == 0 ||
        (vdev->strm = s_alloc(vdev->v_memory,
                              "vector_open(strm)")) == 0 ||
        ((open_options & VECTOR_OPEN_FILE_BBOX) &&
         (vdev->bbox_device =
          gs_alloc_struct_immovable(vdev->v_memory,
                                    gx_device_bbox, &st_device_bbox,
                                    "vector_open(bbox_device)")) == 0)
        ) {
        if (vdev->bbox_device)
            gs_free_object(vdev->v_memory, vdev->bbox_device,
                           "vector_open(bbox_device)");
        vdev->bbox_device = 0;
        if (vdev->strm)
            gs_free_object(vdev->v_memory, vdev->strm,
                           "vector_open(strm)");
        vdev->strm = 0;
        if (vdev->strmbuf)
            gs_free_object(vdev->v_memory, vdev->strmbuf,
                           "vector_open(strmbuf)");
        vdev->strmbuf = 0;
        gx_device_close_output_file((gx_device *)vdev, vdev->fname, vdev->file);
        vdev->file = 0;
        return_error(gs_error_VMerror);
    }
    vdev->strmbuf_size = strmbuf_size;
    swrite_file(vdev->strm, vdev->file, vdev->strmbuf, strmbuf_size);
    vdev->open_options = open_options;
    /*
     * We don't want finalization to close the file, but we do want it
     * to flush the stream buffer.
     */
    vdev->strm->procs.close = vdev->strm->procs.flush;
    if (vdev->bbox_device) {
        gx_device_bbox_init(vdev->bbox_device, NULL, vdev->v_memory);
        rc_increment(vdev->bbox_device);

        vdev->bbox_device->icc_struct = icc_struct;
        rc_increment(vdev->bbox_device->icc_struct);

        gx_device_set_resolution((gx_device *) vdev->bbox_device,
                                 vdev->HWResolution[0],
                                 vdev->HWResolution[1]);
        /* Do the right thing about upright vs. inverted. */
        /* (This is dangerous in general, since the procedure */
        /* might reference non-standard elements.) */
        set_dev_proc(vdev->bbox_device, get_initial_matrix,
                     dev_proc(vdev, get_initial_matrix));
        (*dev_proc(vdev->bbox_device, open_device))
            ((gx_device *) vdev->bbox_device);
    }
    return 0;
}