static void pdf_dev_alpha(fz_context *ctx, pdf_device *pdev, float alpha, int stroke) { int i; pdf_document *doc = pdev->doc; gstate *gs = CURRENT_GSTATE(pdev); /* If the alpha is unchanged, nothing to do */ if (gs->alpha[stroke] == alpha) return; /* Have we sent such an alpha before? */ for (i = 0; i < pdev->num_alphas; i++) if (pdev->alphas[i].alpha == alpha && pdev->alphas[i].stroke == stroke) break; if (i == pdev->num_alphas) { pdf_obj *o; pdf_obj *ref = NULL; fz_var(ref); /* No. Need to make a new one */ if (pdev->num_alphas == pdev->max_alphas) { int newmax = pdev->max_alphas * 2; if (newmax == 0) newmax = 4; pdev->alphas = fz_resize_array(ctx, pdev->alphas, newmax, sizeof(*pdev->alphas)); pdev->max_alphas = newmax; } pdev->alphas[i].alpha = alpha; pdev->alphas[i].stroke = stroke; o = pdf_new_dict(ctx, doc, 1); fz_try(ctx) { char text[32]; pdf_dict_put_drop(ctx, o, (stroke ? PDF_NAME_CA : PDF_NAME_ca), pdf_new_real(ctx, doc, alpha)); ref = pdf_add_object(ctx, doc, o); fz_snprintf(text, sizeof(text), "ExtGState/Alp%d", i); pdf_dict_putp(ctx, pdev->resources, text, ref); } fz_always(ctx) { pdf_drop_obj(ctx, o); pdf_drop_obj(ctx, ref); } fz_catch(ctx) { fz_rethrow(ctx); } pdev->num_alphas++; }
static void insert_resource_name(pdf_csi *csi, pdf_filter_state *state, const char *key, const char *name) { pdf_obj *xobj; pdf_obj *obj; if (!state->resources || !name || name[0] == 0) return; xobj = pdf_dict_gets(csi->rdb, key); obj = pdf_dict_gets(xobj, name); xobj = pdf_dict_gets(state->resources, key); if (xobj == NULL) { xobj = pdf_new_dict(csi->doc, 1); pdf_dict_puts_drop(state->resources, key, xobj); } pdf_dict_putp(xobj, name, obj); }
static void copy_resource(fz_context *ctx, pdf_filter_processor *p, pdf_obj *key, const char *name) { pdf_obj *res, *obj; if (!name || name[0] == 0) return; res = pdf_dict_get(ctx, p->old_rdb, key); obj = pdf_dict_gets(ctx, res, name); if (obj) { res = pdf_dict_get(ctx, p->new_rdb, key); if (!res) { res = pdf_new_dict(ctx, p->doc, 1); pdf_dict_put_drop(ctx, p->new_rdb, key, res); } pdf_dict_putp(ctx, res, name, obj); } }