Esempio n. 1
0
/* Close the output file and stream. */
int
gdev_vector_close_file(gx_device_vector * vdev)
{
    FILE *f = vdev->file;
    int err;

    if (vdev->dash_pattern) {
        gs_free_object(vdev->memory->stable_memory, vdev->dash_pattern, "vector free dash pattern");
        vdev->dash_pattern = 0;
    }
    if (vdev->bbox_device) {
        rc_decrement(vdev->bbox_device->icc_struct, "vector_close(bbox_device->icc_struct");
        vdev->bbox_device->icc_struct = NULL;
        gs_free_object(vdev->v_memory, vdev->bbox_device,
                   "vector_close(bbox_device)");
        vdev->bbox_device = 0;
    }

    if (vdev->strm) {
        sclose(vdev->strm);
        gs_free_object(vdev->v_memory, vdev->strm, "vector_close(strm)");
        vdev->strm = 0;
        gs_free_object(vdev->v_memory, vdev->strmbuf, "vector_close(strmbuf)");
        vdev->strmbuf = 0;
    }
    vdev->file = 0;
    if (f) {
        err = ferror(f);
        /* We prevented sclose from closing the file. */
        if (gx_device_close_output_file((gx_device *)vdev, vdev->fname, f) != 0
                || err != 0)
            return_error(gs_error_ioerror);
    }
    return 0;
}
Esempio n. 2
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;
}
Esempio n. 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;
}
Esempio n. 4
0
/* Close the device. */
static int
mac_close(register gx_device *dev)
{
	gx_device_macos	* mdev = (gx_device_macos *)dev;
	
	long	len;
	
	HUnlock((Handle) mdev->pic);	// no more changes in the pict -> unlock handle
	if (strcmp(mdev->outputFileName, "")) {
		DisposeHandle((Handle) mdev->pic);
		gx_device_close_output_file(dev, mdev->outputFileName, mdev->outputFile);
		mdev->outputFile = 0;
	} else {
		len = (long)mdev->currPicPos - (long)*mdev->pic;
		SetHandleSize((Handle) mdev->pic, len + 10);  // +10 just for the case
	}
	
	// notify the caller that the device was closed
	// it has to dispose the PICT handle when it is ready!
	if (pgsdll_callback)
		(*pgsdll_callback) (GSDLL_DEVICE, (char *)mdev, 0);
	
	return 0;
}
Esempio n. 5
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;
}