예제 #1
0
/* we call this from ps code to instantiate a jbig2_global_context
   object which the JBIG2Decode filter uses if available. The
   pointer to the global context is stored in an astruct object
   and returned that way since it lives outside the interpreters
   memory management */
static int
z_jbig2makeglobalctx(i_ctx_t * i_ctx_p)
{
        void *global = NULL;
        s_jbig2_global_data_t *st;
        os_ptr op = osp;
        byte *data;
        int size;
        int code = 0;

        check_type(*op, t_astruct);
        size = gs_object_size(imemory, op->value.pstruct);
        data = r_ptr(op, byte);

        code = s_jbig2decode_make_global_data(data, size,
                        &global);
        if (size > 0 && global == NULL) {
            dlprintf("failed to create parsed JBIG2GLOBALS object.");
            return_error(e_unknownerror);
        }

        st = ialloc_struct(s_jbig2_global_data_t,
                &st_jbig2_global_data_t,
                "jbig2decode parsed global context");
        if (st == NULL) return_error(e_VMerror);

        st->data = global;
        make_astruct(op, a_readonly | icurrent_space, (byte*)st);

        return code;
}
예제 #2
0
/* The caller guarantees that *op is a dictionary. */
int
build_gs_sub_font(i_ctx_t *i_ctx_p, const ref *op, gs_font **ppfont,
                  font_type ftype, gs_memory_type_ptr_t pstype,
                  const build_proc_refs * pbuild, const ref *pencoding,
                  ref *fid_op)
{
    gs_matrix mat, omat;
    ref fname;			/* t_string */
    gs_font *pfont;
    font_data *pdata;
    /*
     * Make sure that we allocate the font data
     * in the same VM as the font dictionary.
     */
    uint space = ialloc_space(idmemory);
    int code = sub_font_params(imemory, op, &mat, &omat, &fname);

    if (code < 0)
        return code;
    ialloc_set_space(idmemory, r_space(op));
    pfont = gs_font_alloc(imemory, pstype, &gs_font_procs_default, NULL,
                          "buildfont(font)");
    pdata = ialloc_struct(font_data, &st_font_data,
                          "buildfont(data)");
    if (pfont == 0 || pdata == 0)
        code = gs_note_error(e_VMerror);
    else if (fid_op)
        code = add_FID(i_ctx_p, fid_op, pfont, iimemory);
    if (code < 0) {
        ifree_object(pdata, "buildfont(data)");
        ifree_object(pfont, "buildfont(font)");
        ialloc_set_space(idmemory, space);
        return code;
    }
    refset_null((ref *) pdata, sizeof(font_data) / sizeof(ref));
    ref_assign_new(&pdata->dict, op);
    ref_assign_new(&pdata->BuildChar, &pbuild->BuildChar);
    ref_assign_new(&pdata->BuildGlyph, &pbuild->BuildGlyph);
    if (pencoding)
        ref_assign_new(&pdata->Encoding, pencoding);
    pfont->client_data = pdata;
    pfont->FontType = ftype;
    pfont->FontMatrix = mat;
    pfont->orig_FontMatrix = omat;
    pfont->BitmapWidths = false;
    pfont->ExactSize = fbit_use_bitmaps;
    pfont->InBetweenSize = fbit_use_outlines;
    pfont->TransformedChar = fbit_use_outlines;
    pfont->WMode = 0;
    pfont->procs.encode_char = zfont_encode_char;
    pfont->procs.glyph_name = zfont_glyph_name;
    ialloc_set_space(idmemory, space);
    copy_font_name(&pfont->font_name, &fname);
    *ppfont = pfont;
    return 0;
}
예제 #3
0
/*
 * Do a callout to an OtherSubr implemented in PostScript.
 * The caller must have done a check_estack(4 + num_args).
 */
static int
type1_call_OtherSubr(i_ctx_t *i_ctx_p, const gs_type1exec_state * pcxs,
                     int (*cont) (i_ctx_t *),
                     const ref * pos)
{
    /* Move the Type 1 interpreter state to the heap. */
    gs_type1exec_state *hpcxs =
        ialloc_struct(gs_type1exec_state, &st_gs_type1exec_state,
                      "type1_call_OtherSubr");

    if (hpcxs == 0)
        return_error(e_VMerror);
    *hpcxs = *pcxs;
    gs_type1_set_callback_data(&hpcxs->cis, hpcxs);
    push_mark_estack(es_show, op_type1_cleanup);
    ++esp;
    make_istruct(esp, 0, hpcxs);
    return type1_push_OtherSubr(i_ctx_p, pcxs, cont, pos);
}
예제 #4
0
/* - save <save> */
int
zsave(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    uint space = icurrent_space;
    vm_save_t *vmsave;
    ulong sid;
    int code;
    gs_state *prev;

    if (I_VALIDATE_BEFORE_SAVE)
        ivalidate_clean_spaces(i_ctx_p);
    ialloc_set_space(idmemory, avm_local);
    vmsave = ialloc_struct(vm_save_t, &st_vm_save, "zsave");
    ialloc_set_space(idmemory, space);
    if (vmsave == 0)
        return_error(e_VMerror);
    code = alloc_save_state(idmemory, vmsave, &sid);
    if (code < 0)
        return code;
    if (sid == 0) {
        ifree_object(vmsave, "zsave");
        return_error(e_VMerror);
    }
    if_debug2('u', "[u]vmsave 0x%lx, id = %lu\n",
              (ulong) vmsave, (ulong) sid);
    code = gs_gsave_for_save(igs, &prev);
    if (code < 0)
        return code;
    code = gs_gsave(igs);
    if (code < 0)
        return code;
    vmsave->gsave = prev;
    push(1);
    make_tav(op, t_save, 0, saveid, sid);
    if (I_VALIDATE_AFTER_SAVE)
        ivalidate_clean_spaces(i_ctx_p);
    return 0;
}
예제 #5
0
파일: zdps1.c 프로젝트: ststeiger/ghostsvg
/* - gstate <gstate> */
int
zgstate(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;

    int code = gstate_check_space(i_ctx_p, istate, icurrent_space);
    igstate_obj *pigo;
    gs_state *pnew;
    int_gstate *isp;

    if (code < 0)
	return code;
    pigo = ialloc_struct(igstate_obj, &st_igstate_obj, "gstate");
    if (pigo == 0)
	return_error(e_VMerror);
    pnew = gs_state_copy(igs, imemory);
    if (pnew == 0) {
	ifree_object(pigo, "gstate");
	return_error(e_VMerror);
    }
    isp = gs_int_gstate(pnew);
    int_gstate_map_refs(isp, ref_mark_new);
    push(1);
    /*
     * Since igstate_obj isn't a ref, but only contains a ref, save won't
     * clear its l_new bit automatically, and restore won't set it
     * automatically; we have to make sure this ref is on the changes chain.
     */
    make_iastruct(op, a_all, pigo);
#if 0 /* Bug 689849 "gstate leaks memory" */ 
    make_null(&pigo->gstate);
    ref_save(op, &pigo->gstate, "gstate");
    make_istruct_new(&pigo->gstate, 0, pnew);
#else
    make_istruct(&pigo->gstate, 0, pnew);
#endif
    return 0;
}
예제 #6
0
/*
 * Handle a scan_Comment or scan_DSC_Comment return from gs_scan_token
 * (scan_code) by calling out to %Process[DSC]Comment.  The continuation
 * procedure expects the scanner state on the o-stack.
 */
int
ztoken_handle_comment(i_ctx_t *i_ctx_p, scanner_state *sstate,
                      const ref *ptoken, int scan_code,
                      bool save, bool push_file, op_proc_t cont)
{
    const char *proc_name;
    scanner_state *pstate;
    os_ptr op;
    ref *ppcproc;
    int code;

    switch (scan_code) {
    case scan_Comment:
        proc_name = "%ProcessComment";
        break;
    case scan_DSC_Comment:
        proc_name = "%ProcessDSCComment";
        break;
    default:
        return_error(e_Fatal);  /* can't happen */
    }
    /*
     * We can't use check_ostack here, because it returns on overflow.
     */
    /*check_ostack(2);*/
    if (ostop - osp < 2) {
        code = ref_stack_extend(&o_stack, 2);
        if (code < 0)
            return code;
    }
    check_estack(3);
    code = name_enter_string(imemory, proc_name, esp + 3);
    if (code < 0)
        return code;
    if (save) {
        pstate = (scanner_state *)ialloc_struct(scanner_state_dynamic, &st_scanner_state_dynamic,
                               "ztoken_handle_comment");
        if (pstate == 0)
            return_error(e_VMerror);
        ((scanner_state_dynamic *)pstate)->mem = imemory;
        *pstate = *sstate;
    } else
        pstate = sstate;
    /* Save the token now -- it might be on the e-stack. */
    if (!pstate->s_pstack)
        osp[2] = *ptoken;
    /*
     * Push the continuation, scanner state, file, and callout procedure
     * on the e-stack.
     */
    make_op_estack(esp + 1, cont);
    make_istruct(esp + 2, 0, pstate);
    ppcproc = dict_find_name(esp + 3);
    if (ppcproc == 0) {
        /*
         * This can only happen during initialization.
         * Pop the comment string from the o-stack if needed (see below).
         */
        if (pstate->s_pstack)
            --osp;
        esp += 2;               /* do run the continuation */
    } else {
        /*
         * Push the file and comment string on the o-stack.
         * If we were inside { }, the comment string is already on the stack.
         */
        if (pstate->s_pstack) {
            op = ++osp;
            *op = op[-1];
        } else {
            op = osp += 2;
            /* *op = *ptoken; */        /* saved above */
        }
        op[-1] = pstate->s_file;
        esp[3] = *ppcproc;
        esp += 3;
    }
    return o_push_estack;
}
예제 #7
0
/* Common framework for building shadings. */
static int
build_shading(i_ctx_t *i_ctx_p, build_shading_proc_t proc)
{
    os_ptr op = osp;
    int code;
    float box[4];
    gs_shading_params_t params;
    gs_shading_t *psh;
    ref *pvalue;

    check_type(*op, t_dictionary);
    params.ColorSpace = 0;
    params.cie_joint_caches = 0;
    params.Background = 0;
    /* Collect parameters common to all shading types. */
    {
        gs_color_space *pcs = gs_currentcolorspace(igs);
        int num_comp = gs_color_space_num_components(pcs);

        if (num_comp < 0) {	/* Pattern color space */
            gs_errorinfo_put_pair_from_dict(i_ctx_p, op, "ColorSpace");
            return_error(gs_error_typecheck);
        }
        params.ColorSpace = pcs;
        rc_increment_cs(pcs);
        if (dict_find_string(op, "Background", &pvalue) > 0) {
            gs_client_color *pcc =
                ialloc_struct(gs_client_color, &st_client_color,
                              "build_shading");

            if (pcc == 0) {
                code = gs_note_error(gs_error_VMerror);
                goto fail;
            }
            pcc->pattern = 0;
            params.Background = pcc;
            code = dict_floats_param(imemory, op, "Background",
                                     gs_color_space_num_components(pcs),
                                     pcc->paint.values, NULL);
            if (code < 0) {
                gs_errorinfo_put_pair_from_dict(i_ctx_p, op, "Background");
                goto fail;
            }
        }
    }
    if (dict_find_string(op, "BBox", &pvalue) <= 0)
        params.have_BBox = false;
    else if ((code = dict_floats_param(imemory, op, "BBox",
                                       4, box, NULL)) == 4) {
        /* Adobe Interpreters accept denormalised BBox - bug 688937 */
        if (box[0] <= box[2]) {
            params.BBox.p.x = box[0];
            params.BBox.q.x = box[2];
        } else {
            params.BBox.p.x = box[2];
            params.BBox.q.x = box[0];
        }
        if (box[1] <= box[3]) {
            params.BBox.p.y = box[1];
            params.BBox.q.y = box[3];
        } else {
            params.BBox.p.y = box[3];
            params.BBox.q.y = box[1];
        }
        params.have_BBox = true;
    } else {
        gs_errorinfo_put_pair_from_dict(i_ctx_p, op, "BBox");
        goto fail;
    }
    code = dict_bool_param(op, "AntiAlias", false, &params.AntiAlias);
    if (code < 0) {
        gs_errorinfo_put_pair_from_dict(i_ctx_p, op, "AntiAlias");
        goto fail;
    }
    /* Finish building the shading. */
    code = (*proc)(i_ctx_p, op, &params, &psh, imemory);
    if (code < 0)
        goto fail;
    if (gx_color_space_needs_cie_caches(psh->params.ColorSpace)) {
        rc_decrement(psh->params.cie_joint_caches, "build_shading");
        psh->params.cie_joint_caches = gx_currentciecaches(igs);
        rc_increment(psh->params.cie_joint_caches);
    }
    make_istruct_new(op, 0, psh);
    return code;
fail:
    gs_free_object(imemory, params.Background, "Background");
    if (params.ColorSpace) {
        rc_decrement_only_cs(params.ColorSpace, "build_shading");
    }
    return (code < 0 ? code : gs_note_error(gs_error_rangecheck));
}