コード例 #1
0
/* - .popdevicefilter - */
static int
zpopdevicefilter(i_ctx_t *i_ctx_p)
{
    gs_memory_t *mem = gs_memory_stable(imemory);

    return gs_pop_device_filter(mem, igs);
}
コード例 #2
0
ファイル: gxpath.c プロジェクト: BorodaZizitopa/ghostscript
/* Note that all lines have the same notes. */
int
gx_path_add_lines_notes(gx_path *ppath, const gs_fixed_point *ppts, int count,
                        segment_notes notes)
{
    subpath *psub;
    segment *prev;
    line_segment *lp = 0;
    int i;
    int code = 0;

    if (count <= 0)
        return 0;
    path_unshare(ppath);
    path_open();
    psub = ppath->current_subpath;
    prev = psub->last;
    /*
     * We could do better than the following, but this is a start.
     * Note that we don't make any attempt to undo partial additions
     * if we fail partway through; this is equivalent to what would
     * happen with multiple calls on gx_path_add_line.
     */
    for (i = 0; i < count; i++) {
        fixed x = ppts[i].x;
        fixed y = ppts[i].y;
        line_segment *next;

        if (ppath->bbox_set && outside_bbox(ppath, x, y)) {
            code = gs_note_error(gs_error_rangecheck);
            break;
        }
        if (!(next = gs_alloc_struct(gs_memory_stable(ppath->memory),
                                     line_segment, &st_line,
                                     "gx_path_add_lines"))
            ) {
            code = gs_note_error(gs_error_VMerror);
            break;
        }
        lp = next;
        lp->type = s_line;
        lp->notes = notes;
        prev->next = (segment *) lp;
        lp->prev = prev;
        lp->pt.x = x;
        lp->pt.y = y;
        prev = (segment *) lp;
        trace_segment("[P]", (segment *) lp);
    }
    if (lp != 0)
        ppath->position.x = lp->pt.x,
            ppath->position.y = lp->pt.y,
            psub->last = (segment *) lp,
            lp->next = 0,
            path_update_draw(ppath);
    return code;
}
コード例 #3
0
ファイル: gxpath.c プロジェクト: BorodaZizitopa/ghostscript
/*
 * Initialize a path contained in an already-heap-allocated object,
 * optionally allocating its segments.
 */
static int
path_alloc_segments(gx_path_segments ** ppsegs, gs_memory_t * mem,
                    client_name_t cname)
{
    mem = gs_memory_stable(mem);
    rc_alloc_struct_1(*ppsegs, gx_path_segments, &st_path_segments,
                      mem, return_error(gs_error_VMerror), cname);
    (*ppsegs)->rc.free = rc_free_path_segments;
    return 0;
}
コード例 #4
0
ファイル: zbseq.c プロジェクト: computersforpeace/ghostpdl
/* Create a system or user name table (in the stable memory of mem). */
int
create_names_array(ref **ppnames, gs_memory_t *mem, client_name_t cname)
{
    ref *pnames = (ref *)
        gs_alloc_struct(gs_memory_stable(mem), names_array_ref_t,
                        &st_names_array_ref, cname);

    if (pnames == 0)
        return_error(gs_error_VMerror);
    make_empty_array(pnames, a_readonly);
    *ppnames = pnames;
    return 0;
}
コード例 #5
0
/* Put parameters */
int
gdev_pdf_put_params(gx_device * dev, gs_param_list * plist)
{
    int code;
    gx_device_pdf *pdev = (gx_device_pdf *) dev;
    gs_memory_t *mem = gs_memory_stable(pdev->memory);
    gx_device_pdf *save_dev = gs_malloc(mem, sizeof(gx_device_pdf), 1,
        "saved gx_device_pdf");

    if (!save_dev)
        return_error(gs_error_VMerror);
    memcpy(save_dev, pdev, sizeof(gx_device_pdf));
    code = gdev_pdf_put_params_impl(dev, save_dev, plist);
    gs_free(mem, save_dev, sizeof(gx_device_pdf), 1, "saved gx_device_pdf");
    return code;
}
コード例 #6
0
ファイル: gxpath.c プロジェクト: BorodaZizitopa/ghostscript
/*
 * Free the segments of a path when their reference count goes to zero.
 * We do this in reverse order so as to maximize LIFO allocator behavior.
 * We don't have to worry about cleaning up pointers, because we're about
 * to free the segments object.
 */
static void
rc_free_path_segments_local(gs_memory_t * mem, void *vpsegs,
                            client_name_t cname)
{
    gx_path_segments *psegs = (gx_path_segments *) vpsegs;
    segment *pseg;

    mem = gs_memory_stable(mem);
    if (psegs->contents.subpath_first == 0)
        return;			/* empty path */
    pseg = (segment *) psegs->contents.subpath_current->last;
    while (pseg) {
        segment *prev = pseg->prev;

        trace_segment("[P]release", pseg);
        gs_free_object(mem, pseg, cname);
        pseg = prev;
    }
}
コード例 #7
0
/* Put parameters, implementation */
static int
gdev_pdf_put_params_impl(gx_device * dev, const gx_device_pdf * save_dev, gs_param_list * plist)
{
    int ecode, code;
    gx_device_pdf *pdev = (gx_device_pdf *) dev;
    float cl = (float)pdev->CompatibilityLevel;
    bool locked = pdev->params.LockDistillerParams;
    gs_param_name param_name;
    enum psdf_color_conversion_strategy save_ccs = pdev->params.ColorConversionStrategy;
  
    pdev->pdf_memory = gs_memory_stable(pdev->memory);
    /*
     * If this is a pseudo-parameter (pdfmark or DSC),
     * don't bother checking for any real ones.
     */

    {
	gs_param_string_array ppa;

	code = param_read_string_array(plist, (param_name = "pdfmark"), &ppa);
	switch (code) {
	    case 0:
		code = pdf_open_document(pdev);
		if (code < 0)
		    return code;
		code = pdfmark_process(pdev, &ppa);
		if (code >= 0)
		    return code;
		/* falls through for errors */
	    default:
		param_signal_error(plist, param_name, code);
		return code;
	    case 1:
		break;
	}

	code = param_read_string_array(plist, (param_name = "DSC"), &ppa);
	switch (code) {
	    case 0:
		code = pdf_open_document(pdev);
		if (code < 0)
		    return code;
		code = pdf_dsc_process(pdev, &ppa);
		if (code >= 0)
		    return code;
		/* falls through for errors */
	    default:
		param_signal_error(plist, param_name, code);
		return code;
	    case 1:
		break;
	}
    }
  
    /*
     * Check for LockDistillerParams before doing anything else.
     * If LockDistillerParams is true and is not being set to false,
     * ignore all resettings of PDF-specific parameters.  Note that
     * LockDistillerParams is read again, and reset if necessary, in
     * psdf_put_params.
     */
    ecode = code = param_read_bool(plist, "LockDistillerParams", &locked);
 
    if (!(locked && pdev->params.LockDistillerParams)) {
	/* General parameters. */

	{
	    int efo = 1;

	    ecode = param_put_int(plist, (param_name = ".EmbedFontObjects"), &efo, ecode);
	    if (efo != 1)
		param_signal_error(plist, param_name, ecode = gs_error_rangecheck);
	}
	{
	    int cdv = CoreDistVersion;

	    ecode = param_put_int(plist, (param_name = "CoreDistVersion"), &cdv, ecode);
	    if (cdv != CoreDistVersion)
		param_signal_error(plist, param_name, ecode = gs_error_rangecheck);
	}

	switch (code = param_read_float(plist, (param_name = "CompatibilityLevel"), &cl)) {
	    default:
		ecode = code;
		param_signal_error(plist, param_name, ecode);
	    case 0:
		/*
		 * Must be 1.2, 1.3, 1.4, or 1.5.  Per Adobe documentation, substitute
		 * the nearest achievable value.
		 */
		if (cl < (float)1.15)
		    cl = (float)1.1;
		else if (cl < (float)1.25)
		    cl = (float)1.2;
		else if (cl < (float)1.35)
		    cl = (float)1.3;
		else if (cl < (float)1.45)
		    cl = (float)1.4;
		else
		    cl = (float)1.5;
	    case 1:
		break;
	}
	{   /* HACK : gs_param_list_s::memory is documented in gsparam.h as
	       "for allocating coerced arrays". Not sure why zputdeviceparams
	       sets it to the current memory space, while the device
	       assumes to store them in the device's memory space.
	       As a hackish workaround we temporary replace it here.
	       Doing so because we don't want to change the global code now
	       because we're unable to test it with all devices.
	       Bug 688531 "Segmentation fault running pdfwrite from 219-01.ps".

	       This solution to be reconsidered after fixing 
	       the bug 688533 "zputdeviceparams specifies a wrong memory space.".
 	    */
	    gs_memory_t *mem = plist->memory;

	    plist->memory = pdev->pdf_memory;
	    code = gs_param_read_items(plist, pdev, pdf_param_items);
	    if (code < 0 ||
		(pdev->is_ps2write && (code = param_read_string(plist, "OPDFReadProcsetPath", &pdev->OPDFReadProcsetPath)) < 0) ||
		(!pdev->is_ps2write && (code = param_read_bool(plist, "ForOPDFRead", &pdev->ForOPDFRead)) < 0)
		);
	    plist->memory = mem;
	}
	if (code < 0)
	    ecode = code;
	{
	    /*
	     * Setting FirstObjectNumber is only legal if the file
	     * has just been opened and nothing has been written,
	     * or if we are setting it to the same value.
	     */
	    long fon = pdev->FirstObjectNumber;

	    if (fon != save_dev->FirstObjectNumber) {
		if (fon <= 0 || fon > 0x7fff0000 ||
		    (pdev->next_id != 0 &&
		     pdev->next_id !=
		     save_dev->FirstObjectNumber + pdf_num_initial_ids)
		    ) {
		    ecode = gs_error_rangecheck;
		    param_signal_error(plist, "FirstObjectNumber", ecode);
		}
	    }
	}
	{
	    /*
	     * Set ProcessColorModel now, because gx_default_put_params checks
	     * it.
	     */
	    static const char *const pcm_names[] = {
		"DeviceGray", "DeviceRGB", "DeviceCMYK", "DeviceN", 0
	    };
	    int pcm = -1;

	    ecode = param_put_enum(plist, "ProcessColorModel", &pcm,
				   pcm_names, ecode);
	    if (pcm >= 0) {
		pdf_set_process_color_model(pdev, pcm);
		pdf_set_initial_color(pdev, &pdev->saved_fill_color, &pdev->saved_stroke_color,
				&pdev->fill_used_process_color, &pdev->stroke_used_process_color);
	    }
	}
    }
    if (ecode < 0)
	goto fail;
    if (pdev->PDFX && pdev->PDFA) {
	ecode = gs_note_error(gs_error_rangecheck);
	param_signal_error(plist, "PDFA", ecode);
	goto fail;
    }
    if (pdev->PDFX && pdev->ForOPDFRead) {
	ecode = gs_note_error(gs_error_rangecheck);
	param_signal_error(plist, "PDFX", ecode);
	goto fail;
    }
    if (pdev->PDFA && pdev->ForOPDFRead) {
	ecode = gs_note_error(gs_error_rangecheck);
	param_signal_error(plist, "PDFA", ecode);
	goto fail;
    }
    if (pdev->PDFA)
	 pdev->HaveTransparency = false;
    /*
     * We have to set version to the new value, because the set of
     * legal parameter values for psdf_put_params varies according to
     * the version.
     */
    if (pdev->PDFX)
	cl = (float)1.3; /* Instead pdev->CompatibilityLevel = 1.2; - see below. */
    if (pdev->PDFA && cl < 1.4)
	cl = (float)1.4;
    pdev->version = (cl < 1.2 ? psdf_version_level2 : psdf_version_ll3);
    if (pdev->ForOPDFRead) {
	pdev->ResourcesBeforeUsage = true;
	pdev->HaveCFF = false;
	pdev->HavePDFWidths = false;
	pdev->HaveStrokeColor = false;
	cl = (float)1.2; /* Instead pdev->CompatibilityLevel = 1.2; - see below. */
	pdev->MaxInlineImageSize = max_long; /* Save printer's RAM from saving temporary image data.
					        Immediate images doen't need buffering. */
	pdev->version = psdf_version_level2;
    } else {
	pdev->ResourcesBeforeUsage = false;
	pdev->HaveCFF = true;
	pdev->HavePDFWidths = true;
	pdev->HaveStrokeColor = true;
    }
    pdev->ParamCompatibilityLevel = cl;
    ecode = gdev_psdf_put_params(dev, plist);
    if (ecode < 0)
	goto fail;
    if ((pdev->params.ColorConversionStrategy == ccs_CMYK &&
	 strcmp(pdev->color_info.cm_name, "DeviceCMYK")) ||
	(pdev->params.ColorConversionStrategy == ccs_sRGB &&
	  strcmp(pdev->color_info.cm_name, "DeviceRGB")) ||
	(pdev->params.ColorConversionStrategy == ccs_Gray &&
	  strcmp(pdev->color_info.cm_name, "DeviceGray"))) {
	eprintf("ColorConversionStrategy is incompatible to ProcessColorModel.\n");
	ecode = gs_note_error(gs_error_rangecheck);
	pdev->params.ColorConversionStrategy = save_ccs;
    }
    if (pdev->params.ColorConversionStrategy == ccs_UseDeviceIndependentColor) {
	if (!pdev->UseCIEColor) {
	    eprintf("Set UseCIEColor for UseDeviceIndependentColor to work properly.\n");
	    ecode = gs_note_error(gs_error_rangecheck);
	    pdev->UseCIEColor = true;
	}
    }
    if (pdev->params.ColorConversionStrategy == ccs_UseDeviceIndependentColorForImages) {
	if (!pdev->UseCIEColor) {
	    eprintf("UseDeviceDependentColorForImages is not supported. Use UseDeviceIndependentColor.\n");
	    pdev->params.ColorConversionStrategy = ccs_UseDeviceIndependentColor;
	    if (!pdev->UseCIEColor) {
		eprintf("Set UseCIEColor for UseDeviceIndependentColor to work properly.\n");
		ecode = gs_note_error(gs_error_rangecheck);
		pdev->UseCIEColor = true;
	    }
	}
    }
    if (pdev->params.ColorConversionStrategy == ccs_UseDeviceDependentColor) {
	if (!strcmp(pdev->color_info.cm_name, "DeviceCMYK")) {
	    eprintf("Replacing the deprecated device parameter value UseDeviceDependentColor with CMYK.\n");
	    pdev->params.ColorConversionStrategy = ccs_CMYK;
	} else if (!strcmp(pdev->color_info.cm_name, "DeviceRGB")) {
	    eprintf("Replacing the deprecated device parameter value UseDeviceDependentColor with sRGB.\n");
	    pdev->params.ColorConversionStrategy = ccs_sRGB;
	} else {
	    eprintf("Replacing the deprecated device parameter value UseDeviceDependentColor with Gray.\n");
	    pdev->params.ColorConversionStrategy = ccs_Gray;
	}
    }
    if (cl < 1.5 && pdev->params.ColorImage.Filter != NULL &&
	    !strcmp(pdev->params.ColorImage.Filter, "JPXEncode")) {
	eprintf("JPXEncode requires CompatibilityLevel >= 1.5 .\n");
	ecode = gs_note_error(gs_error_rangecheck);
    }
    if (cl < 1.5 && pdev->params.GrayImage.Filter != NULL &&
	    !strcmp(pdev->params.GrayImage.Filter, "JPXEncode")) {
	eprintf("JPXEncode requires CompatibilityLevel >= 1.5 .\n");
	ecode = gs_note_error(gs_error_rangecheck);
    }
    if (cl < 1.4  && pdev->params.MonoImage.Filter != NULL &&
	    !strcmp(pdev->params.MonoImage.Filter, "JBIG2Encode")) {
	eprintf("JBIG2Encode requires CompatibilityLevel >= 1.4 .\n");
	ecode = gs_note_error(gs_error_rangecheck);
    }
    if (pdev->HaveTrueTypes && pdev->version == psdf_version_level2) {
	pdev->version = psdf_version_level2_with_TT ;
    }
    /*
     * Acrobat Reader doesn't handle user-space coordinates larger than
     * MAX_USER_COORD.  To compensate for this, reduce the resolution so
     * that the page size in device space (which we equate to user space) is
     * significantly less than MAX_USER_COORD.  Note that this still does
     * not protect us against input files that use coordinates far outside
     * the page boundaries.
     */
#define MAX_EXTENT ((int)(MAX_USER_COORD * 0.9))
    /* Changing resolution or page size requires closing the device, */
    if (dev->height > MAX_EXTENT || dev->width > MAX_EXTENT) {
	double factor =
	    max(dev->height / (double)MAX_EXTENT,
		dev->width / (double)MAX_EXTENT);

	gx_device_set_resolution(dev, dev->HWResolution[0] / factor,
				 dev->HWResolution[1] / factor);
    }
#undef MAX_EXTENT
    if (pdev->FirstObjectNumber != save_dev->FirstObjectNumber) {
	if (pdev->xref.file != 0) {
	    fseek(pdev->xref.file, 0L, SEEK_SET);
	    pdf_initialize_ids(pdev);
	}
    }
    /* Handle the float/double mismatch. */
    pdev->CompatibilityLevel = (int)(cl * 10 + 0.5) / 10.0;
    return 0;
 fail:
    /* Restore all the parameters to their original state. */
    pdev->version = save_dev->version;
    pdf_set_process_color_model(pdev, save_dev->pcm_color_info_index);
    pdev->saved_fill_color = save_dev->saved_fill_color;
    pdev->saved_stroke_color = save_dev->saved_fill_color;
    {
	const gs_param_item_t *ppi = pdf_param_items;

	for (; ppi->key; ++ppi)
	    memcpy((char *)pdev + ppi->offset,
		   (char *)save_dev + ppi->offset,
		   gs_param_type_sizes[ppi->type]);
	pdev->ForOPDFRead = save_dev->ForOPDFRead;
	pdev->OPDFReadProcsetPath = save_dev->OPDFReadProcsetPath;
    }
    return ecode;
}
コード例 #8
0
/*
 * Return the enumerator memory used for allocating the row buffers.
 * Because some PostScript files use save/restore within an image data
 * reading procedure, this must be a stable allocator.
 */
static gs_memory_t *
gs_image_row_memory(const gs_image_enum *penum)
{
    return gs_memory_stable(penum->memory);
}
コード例 #9
0
ファイル: xpsttf.c プロジェクト: ststeiger/ghostsvg
int
xps_init_truetype_font(xps_context_t *ctx, xps_font_t *font)
{
    font->font = (void*) gs_alloc_struct(ctx->memory, gs_font_type42, &st_gs_font_type42, "xps_font type42");
    if (!font->font)
        return gs_throw(gs_error_VMerror, "out of memory");

    /* no shortage of things to initialize */
    {
        gs_font_type42 *p42 = (gs_font_type42*) font->font;

        /* Common to all fonts: */

        p42->next = 0;
        p42->prev = 0;
        p42->memory = ctx->memory;

        p42->dir = ctx->fontdir; /* NB also set by gs_definefont later */
        p42->base = font->font; /* NB also set by gs_definefont later */
        p42->is_resource = false;
        gs_notify_init(&p42->notify_list, gs_memory_stable(ctx->memory));
        p42->id = gs_next_ids(ctx->memory, 1);

        p42->client_data = font; /* that's us */

        /* this is overwritten in grid_fit() */
        gs_make_identity(&p42->FontMatrix);
        gs_make_identity(&p42->orig_FontMatrix); /* NB ... original or zeroes? */

        p42->FontType = ft_TrueType;
        p42->BitmapWidths = false;
        p42->ExactSize = fbit_use_outlines;
        p42->InBetweenSize = fbit_use_outlines;
        p42->TransformedChar = fbit_use_outlines;
        p42->WMode = 0;
        p42->PaintType = 0;
        p42->StrokeWidth = 0;
        p42->is_cached = 0;

        p42->procs.define_font = gs_no_define_font;
        p42->procs.make_font = gs_no_make_font;
        p42->procs.font_info = gs_type42_font_info;
        p42->procs.same_font = gs_default_same_font;
        p42->procs.encode_char = xps_true_callback_encode_char;
        p42->procs.decode_glyph = xps_true_callback_decode_glyph;
        p42->procs.enumerate_glyph = gs_type42_enumerate_glyph;
        p42->procs.glyph_info = gs_type42_glyph_info;
        p42->procs.glyph_outline = gs_type42_glyph_outline;
        p42->procs.glyph_name = xps_true_callback_glyph_name;
        p42->procs.init_fstack = gs_default_init_fstack;
        p42->procs.next_char_glyph = gs_default_next_char_glyph;
        p42->procs.build_char = xps_true_callback_build_char;

        memset(p42->font_name.chars, 0, sizeof(p42->font_name.chars));
        xps_load_sfnt_name(font, (char*)p42->font_name.chars);
        p42->font_name.size = strlen((char*)p42->font_name.chars);

        memset(p42->key_name.chars, 0, sizeof(p42->key_name.chars));
        strcpy((char*)p42->key_name.chars, (char*)p42->font_name.chars);
        p42->key_name.size = strlen((char*)p42->key_name.chars);

        /* Base font specific: */

        p42->FontBBox.p.x = 0;
        p42->FontBBox.p.y = 0;
        p42->FontBBox.q.x = 0;
        p42->FontBBox.q.y = 0;

        uid_set_UniqueID(&p42->UID, p42->id);

        p42->encoding_index = ENCODING_INDEX_UNKNOWN;
        p42->nearest_encoding_index = ENCODING_INDEX_ISOLATIN1;

        p42->FAPI = 0;
        p42->FAPI_font_data = 0;

        /* Type 42 specific: */

        p42->data.string_proc = xps_true_callback_string_proc;
        p42->data.proc_data = font;

        gs_type42_font_init(p42, font->subfontid);
        p42->data.get_glyph_index = xps_true_get_glyph_index;
    }

    gs_definefont(ctx->fontdir, font->font);

    return 0;
}