Exemplo n.º 1
0
int
display_set_callback(gs_main_instance *minst, display_callback *callback)
{
    i_ctx_t *i_ctx_p;
    bool was_open;
    int code;
    int exit_code = 0;
    os_ptr op;
    gx_device *dev;
    gx_device_display *ddev;

    /* If display device exists, copy prototype if needed and return
     *  device true
     * If it doesn't exist, return
     *  false
     */
    const char getdisplay[] =
      "devicedict /display known dup { /display finddevice exch } if";
    code = gs_main_run_string(minst, getdisplay, 0, &exit_code,
        &minst->error_object);
    if (code < 0)
       return code;

    i_ctx_p = minst->i_ctx_p;	/* run_string may change i_ctx_p if GC */
    op = osp;
    check_type(*op, t_boolean);
    if (op->value.boolval) {
        /* display device was included in Ghostscript so we need
         * to set the callback structure pointer within it.
         * If the device is already open, close it before
         * setting callback, then reopen it.
         */
        check_read_type(op[-1], t_device);
        dev = op[-1].value.pdevice;

        was_open = dev->is_open;
        if (was_open) {
            code = gs_closedevice(dev);
            if (code < 0)
                return_error(code);
        }

        ddev = (gx_device_display *) dev;
        ddev->callback = callback;

        if (was_open) {
            code = gs_opendevice(dev);
            if (code < 0) {
                dprintf("**** Unable to open the display device, quitting.\n");
                return_error(code);
            }
        }
        pop(1);	/* device */
    }
    pop(1);	/* boolean */
    return 0;
}
Exemplo n.º 2
0
static int
bbox_close_device(gx_device * dev)
{
    gx_device_bbox *const bdev = (gx_device_bbox *) dev;
    gx_device *tdev = bdev->target;

    if (bdev->box_procs.init_box != box_procs_default.init_box) {
	/*
	 * This device was created as a wrapper for a compositor.
	 * Just free the devices.
	 */
	int code = (tdev && bdev->forward_open_close ? gs_closedevice(tdev) : 0);

	gs_free_object(dev->memory, dev, "bbox_close_device(composite)");
	return code;
    } else {
	return (tdev && bdev->forward_open_close ? gs_closedevice(tdev) : 0);
    }
}
Exemplo n.º 3
0
/* End a compositing operation. */
static void
end_composite(i_ctx_t *i_ctx_p, alpha_composite_state_t * pcp)
{
    /* Close and free the compositor and the compositing object. */
    if (pcp->cdev != pcp->orig_dev) {
        gs_closedevice(pcp->cdev);	/* also frees the device */
        gs_setdevice_no_init(igs, pcp->orig_dev);
    }
    ifree_object(pcp->pcte, "end_composite(gs_composite_t)");
}
Exemplo n.º 4
0
/*
 * Finalization for devices: do any special finalization first, then
 * close the device if it is open, and finally free the structure
 * descriptor if it is dynamic.
 */
void
gx_device_finalize(void *vptr)
{
    gx_device * const dev = (gx_device *)vptr;

    if (dev->finalize)
	dev->finalize(dev);
    discard(gs_closedevice(dev));
    if (dev->stype_is_dynamic)
	gs_free_const_object(dev->memory->non_gc_memory, dev->stype,
			     "gx_device_finalize");
}
Exemplo n.º 5
0
/*
 * Finalization for devices: do any special finalization first, then
 * close the device if it is open, and finally free the structure
 * descriptor if it is dynamic.
 */
void
gx_device_finalize(const gs_memory_t *cmem, void *vptr)
{
    gx_device * const dev = (gx_device *)vptr;
    (void)cmem; /* unused */

    if (dev->icc_struct != NULL) {
        rc_decrement(dev->icc_struct, "gx_device_finalize(icc_profile)");
    }
    if (dev->finalize)
        dev->finalize(dev);
    discard(gs_closedevice(dev));
    if (dev->stype_is_dynamic)
        gs_free_const_object(dev->memory->non_gc_memory, dev->stype,
                             "gx_device_finalize");
}
Exemplo n.º 6
0
void eprn_init_device(eprn_Device *dev, const eprn_PrinterDescription *desc)
{
  eprn_Eprn *eprn = &dev->eprn;
  int j;
  float hres, vres;

  if (dev->is_open) gs_closedevice((gx_device *)dev);

  assert(desc != NULL);
  eprn->cap = desc;
  eprn_set_media_data(dev, NULL, 0);

  /* The media flags are retained because they have not been prescribed by the
     user directly in contact with eprn but are completely under the control
     of the derived device. */

  eprn->code = ms_none;
  eprn->leading_edge_set = false;
  eprn->right_shift = 0;
  eprn->down_shift = 0;
  eprn->keep_margins = false;
  eprn->soft_tumble = false;
  for (j = 0; j < 4; j++) dev->HWMargins[j] = 0;

  /* Set to default colour state, ignoring request failures */
  eprn->colour_model = eprn_DeviceGray;
  eprn->black_levels = 2;
  eprn->non_black_levels = 0;
  eprn->intensity_rendering = eprn_IR_halftones;
  hres = dev->HWResolution[0];
  vres = dev->HWResolution[1];
  eprn_check_colour_info(desc->colour_info, &eprn->colour_model,
      &hres, &vres, &eprn->black_levels, &eprn->non_black_levels);

  if (eprn->pagecount_file != NULL) {
    gs_free(dev->memory->non_gc_memory, eprn->pagecount_file, strlen(eprn->pagecount_file) + 1,
      sizeof(char), "eprn_init_device");
    eprn->pagecount_file = NULL;
  }

  eprn->media_position_set = false;

  return;
}
Exemplo n.º 7
0
/* Write the page. */
static int
pcx2up_print_page(gx_device_printer * pdev, FILE * file)
{
    gx_device_2up *pdev2 = (gx_device_2up *) pdev;
    const gx_device_printer *prdev_template =
    (const gx_device_printer *)&gs_pcx2up_device;

    if (!pdev2->have_odd_page) {	/* This is the odd page, just save it. */
        pdev2->have_odd_page = true;
        return gdev_prn_save_page(pdev, &pdev2->odd_page, 1);
    } else {			/* This is the even page, do 2-up output. */
        gx_saved_page even_page;
        gx_placed_page pages[2];
        int x_offset = (int)(pdev->HWResolution[0] * 0.5);
        int code = gdev_prn_save_page(pdev, &even_page, 1);
        int prdev_size = prdev_template->params_size;
        gx_device_printer *prdev;

#define rdev ((gx_device *)prdev)

        if (code < 0)
            return code;
        /* Create the placed page list. */
        pages[0].page = &pdev2->odd_page;
        pages[0].offset.x = x_offset;
        pages[0].offset.y = 0 /*y_offset */ ;
        pages[1].page = &even_page;
        pages[1].offset.x = pdev->width + x_offset * 3;
        pages[1].offset.y = 0 /*y_offset */ ;
        /* Create and open a device for rendering. */
        prdev = (gx_device_printer *)
            gs_alloc_bytes(pdev->memory, prdev_size,
                           "pcx2up_print_page(device)");
        if (prdev == 0)
            return_error(gs_error_VMerror);
        memcpy(prdev, prdev_template, prdev_size);
        check_device_separable((gx_device *)rdev);
        gx_device_fill_in_procs(rdev);
        set_dev_proc(prdev, open_device,
                     dev_proc(&gs_pcx256_device, open_device));
        prdev->printer_procs.print_page =
            gs_pcx256_device.printer_procs.print_page;
        prdev->space_params.band =
            pages[0].page->info.band_params;	/* either one will do */
        prdev->space_params.MaxBitmap = 0;
        prdev->space_params.BufferSpace =
            prdev->space_params.band.BandBufferSpace;
        prdev->width = prdev->space_params.band.BandWidth;
        prdev->OpenOutputFile = false;
        code = (*dev_proc(rdev, open_device)) (rdev);
        if (code < 0)
            return code;
        rdev->is_open = true;
        prdev->file = pdev->file;
        /* Render the pages. */
        code = gdev_prn_render_pages(prdev, pages, 2);
        /* Clean up. */
        if (pdev->file != 0)
            prdev->file = 0;	/* don't close it */
        gs_closedevice(rdev);
        pdev2->have_odd_page = false;
        return code;
#undef rdev
    }
}