static void sweepref(fz_obj *obj) { int num = fz_to_num(obj); int gen = fz_to_gen(obj); if (num < 0 || num >= xref->len) return; if (uselist[num]) return; uselist[num] = 1; /* Bake in /Length in stream objects */ fz_try(ctx) { if (pdf_is_stream(xref, num, gen)) { fz_obj *len = fz_dict_gets(obj, "Length"); if (fz_is_indirect(len)) { uselist[fz_to_num(len)] = 0; len = fz_resolve_indirect(len); fz_dict_puts(obj, "Length", len); } } } fz_catch(ctx) { /* Leave broken */ } sweepobj(fz_resolve_indirect(obj)); }
static void removeduplicateobjs(void) { int num, other; for (num = 1; num < xref->len; num++) { /* Only compare an object to objects preceding it */ for (other = 1; other < num; other++) { fz_obj *a, *b; if (num == other || !uselist[num] || !uselist[other]) continue; /* * Comparing stream objects data contents would take too long. * * pdf_is_stream calls pdf_cache_object and ensures * that the xref table has the objects loaded. */ fz_try(ctx) { if (pdf_is_stream(xref, num, 0) || pdf_is_stream(xref, other, 0)) continue; } fz_catch(ctx) { /* Assume different */ } a = xref->table[num].obj; b = xref->table[other].obj; a = fz_resolve_indirect(a); b = fz_resolve_indirect(b); if (fz_objcmp(a, b)) continue; /* Keep the lowest numbered object */ renumbermap[num] = MIN(num, other); renumbermap[other] = MIN(num, other); uselist[MAX(num, other)] = 0; /* One duplicate was found, do not look for another */ break; } } }
/* for use by pdf_crypt_obj_imp to decrypt AES string in place */ void fz_set_str_len(fz_context *ctx, fz_obj *obj, int newlen) { obj = fz_resolve_indirect(ctx, obj); if (fz_is_string(ctx, obj)) if (newlen < obj->u.s.len) obj->u.s.len = newlen; }
char *fz_to_str_buf(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); if (fz_is_string(ctx, obj)) return obj->u.s.buf; return ""; }
int fz_to_str_len(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); if (fz_is_string(ctx, obj)) return obj->u.s.len; return 0; }
int fz_to_bool(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); if (fz_is_bool(ctx, obj)) return obj->u.b; return 0; }
char *fz_to_name(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); if (fz_is_name(ctx, obj)) return obj->u.n; return ""; }
float fz_to_real(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); if (fz_is_real(ctx, obj)) return obj->u.f; if (fz_is_int(ctx, obj)) return obj->u.i; return 0; }
int fz_to_int(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); if (fz_is_int(ctx, obj)) return obj->u.i; if (fz_is_real(ctx, obj)) return (int)(obj->u.f + 0.5f); /* No roundf in MSVC */ return 0; }
int fz_is_dict(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); return obj ? obj->kind == FZ_DICT : 0; }
int fz_is_array(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); return obj ? obj->kind == FZ_ARRAY : 0; }
int fz_is_name(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); return obj ? obj->kind == FZ_NAME : 0; }
int fz_is_string(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); return obj ? obj->kind == FZ_STRING : 0; }
int fz_is_real(fz_context *ctx, fz_obj *obj) { obj = fz_resolve_indirect(ctx, obj); return obj ? obj->kind == FZ_REAL : 0; }