pdf_obj * pdf_copy_dict(fz_context *ctx, pdf_obj *obj) { pdf_document *doc; pdf_obj *dict; int i, n; RESOLVE(obj); if (!OBJ_IS_DICT(obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj)); doc = DICT(obj)->doc; n = pdf_dict_len(ctx, obj); dict = pdf_new_dict(ctx, doc, n); fz_try(ctx) for (i = 0; i < n; i++) pdf_dict_put(ctx, dict, pdf_dict_get_key(ctx, obj, i), pdf_dict_get_val(ctx, obj, i)); fz_catch(ctx) { pdf_drop_obj(ctx, dict); fz_rethrow(ctx); } return dict; }
int pdf_dict_len(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); if (!OBJ_IS_DICT(obj)) return 0; return DICT(obj)->len; }
pdf_obj * pdf_dict_get_val(fz_context *ctx, pdf_obj *obj, int i) { RESOLVE(obj); if (!OBJ_IS_DICT(obj)) return NULL; if (i < 0 || i >= DICT(obj)->len) return NULL; return DICT(obj)->items[i].v; }
void pdf_dict_put_val_null(fz_context *ctx, pdf_obj *obj, int idx) { RESOLVE(obj); if (!OBJ_IS_DICT(obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj)); if (idx < 0 || idx >= DICT(obj)->len) fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds"); prepare_object_for_alteration(ctx, obj, NULL); pdf_drop_obj(ctx, DICT(obj)->items[idx].v); DICT(obj)->items[idx].v = PDF_OBJ_NULL; }
int pdf_is_dict(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); return OBJ_IS_DICT(obj); }