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; }
static int _pdf_doc_find_page_no( struct _pdf_doc *self, fz_obj *dest) { if (fz_is_dict(dest)) { /* The destination is linked from a Go-To action's D array. */ fz_obj * D = fz_dict_gets(dest, "D"); if (D && fz_is_array(D)) dest = D; } if (fz_is_array(dest)) dest = fz_array_get(dest, 0); if (fz_is_int(dest)) return fz_to_int(dest); return pdf_find_page_number(self->xref, dest); }
/* * Load CMap stream in PDF file */ fz_error pdf_load_embedded_cmap(pdf_cmap **cmapp, pdf_xref *xref, fz_obj *stmobj) { fz_error error = fz_okay; fz_stream *file = NULL; pdf_cmap *cmap = NULL; pdf_cmap *usecmap; fz_obj *wmode; fz_obj *obj; if ((*cmapp = pdf_find_item(xref->store, pdf_drop_cmap, stmobj))) { pdf_keep_cmap(*cmapp); return fz_okay; } error = pdf_open_stream(&file, xref, fz_to_num(stmobj), fz_to_gen(stmobj)); if (error) { error = fz_rethrow(error, "cannot open cmap stream (%d %d R)", fz_to_num(stmobj), fz_to_gen(stmobj)); goto cleanup; } error = pdf_parse_cmap(&cmap, file); if (error) { error = fz_rethrow(error, "cannot parse cmap stream (%d %d R)", fz_to_num(stmobj), fz_to_gen(stmobj)); goto cleanup; } fz_close(file); wmode = fz_dict_gets(stmobj, "WMode"); if (fz_is_int(wmode)) pdf_set_wmode(cmap, fz_to_int(wmode)); obj = fz_dict_gets(stmobj, "UseCMap"); if (fz_is_name(obj)) { error = pdf_load_system_cmap(&usecmap, fz_to_name(obj)); if (error) { error = fz_rethrow(error, "cannot load system usecmap '%s'", fz_to_name(obj)); goto cleanup; } pdf_set_usecmap(cmap, usecmap); pdf_drop_cmap(usecmap); } else if (fz_is_indirect(obj)) { error = pdf_load_embedded_cmap(&usecmap, xref, obj); if (error) { error = fz_rethrow(error, "cannot load embedded usecmap (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); goto cleanup; } pdf_set_usecmap(cmap, usecmap); pdf_drop_cmap(usecmap); } pdf_store_item(xref->store, pdf_keep_cmap, pdf_drop_cmap, stmobj, cmap); *cmapp = cmap; return fz_okay; cleanup: if (file) fz_close(file); if (cmap) pdf_drop_cmap(cmap); return error; /* already rethrown */ }