diff options
Diffstat (limited to 'pdf/pdf_xref.c')
-rw-r--r-- | pdf/pdf_xref.c | 368 |
1 files changed, 184 insertions, 184 deletions
diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index 2e98c97e..ce973d39 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -13,24 +13,24 @@ static inline int iswhite(int ch) */ static fz_error -pdf_loadversion(pdf_xref *xref) +pdf_load_version(pdf_xref *xref) { char buf[20]; fz_seek(xref->file, 0, 0); - fz_readline(xref->file, buf, sizeof buf); + fz_read_line(xref->file, buf, sizeof buf); if (memcmp(buf, "%PDF-", 5) != 0) return fz_throw("cannot recognize version marker"); xref->version = atof(buf + 5) * 10; - pdf_logxref("version %d.%d\n", xref->version / 10, xref->version % 10); + pdf_log_xref("version %d.%d\n", xref->version / 10, xref->version % 10); return fz_okay; } static fz_error -pdf_readstartxref(pdf_xref *xref) +pdf_read_start_xref(pdf_xref *xref) { unsigned char buf[1024]; int t, n; @@ -38,9 +38,9 @@ pdf_readstartxref(pdf_xref *xref) fz_seek(xref->file, 0, 2); - xref->filesize = fz_tell(xref->file); + xref->file_size = fz_tell(xref->file); - t = MAX(0, xref->filesize - (int)sizeof buf); + t = MAX(0, xref->file_size - (int)sizeof buf); fz_seek(xref->file, t, 0); n = fz_read(xref->file, buf, sizeof buf); @@ -55,7 +55,7 @@ pdf_readstartxref(pdf_xref *xref) while (iswhite(buf[i]) && i < n) i ++; xref->startxref = atoi((char*)(buf + i)); - pdf_logxref("startxref %d\n", xref->startxref); + pdf_log_xref("startxref %d\n", xref->startxref); return fz_okay; } } @@ -68,7 +68,7 @@ pdf_readstartxref(pdf_xref *xref) */ static fz_error -pdf_readoldtrailer(pdf_xref *xref, char *buf, int cap) +pdf_read_old_trailer(pdf_xref *xref, char *buf, int cap) { fz_error error; int len; @@ -78,19 +78,19 @@ pdf_readoldtrailer(pdf_xref *xref, char *buf, int cap) int tok; int c; - pdf_logxref("load old xref format trailer\n"); + pdf_log_xref("load old xref format trailer\n"); - fz_readline(xref->file, buf, cap); + fz_read_line(xref->file, buf, cap); if (strncmp(buf, "xref", 4) != 0) return fz_throw("cannot find xref marker"); while (1) { - c = fz_peekbyte(xref->file); + c = fz_peek_byte(xref->file); if (!(c >= '0' && c <= '9')) break; - fz_readline(xref->file, buf, cap); + fz_read_line(xref->file, buf, cap); s = buf; fz_strsep(&s, " "); /* ignore ofs */ if (!s) @@ -111,55 +111,55 @@ pdf_readoldtrailer(pdf_xref *xref, char *buf, int cap) error = pdf_lex(&tok, xref->file, buf, cap, &n); if (error) return fz_rethrow(error, "cannot parse trailer"); - if (tok != PDF_TTRAILER) + if (tok != PDF_TOK_TRAILER) return fz_throw("expected trailer marker"); error = pdf_lex(&tok, xref->file, buf, cap, &n); if (error) return fz_rethrow(error, "cannot parse trailer"); - if (tok != PDF_TODICT) + if (tok != PDF_TOK_OPEN_DICT) return fz_throw("expected trailer dictionary"); - error = pdf_parsedict(&xref->trailer, xref, xref->file, buf, cap); + error = pdf_parse_dict(&xref->trailer, xref, xref->file, buf, cap); if (error) return fz_rethrow(error, "cannot parse trailer"); return fz_okay; } static fz_error -pdf_readnewtrailer(pdf_xref *xref, char *buf, int cap) +pdf_read_new_trailer(pdf_xref *xref, char *buf, int cap) { fz_error error; - pdf_logxref("load new xref format trailer\n"); + pdf_log_xref("load new xref format trailer\n"); - error = pdf_parseindobj(&xref->trailer, xref, xref->file, buf, cap, nil, nil, nil); + error = pdf_parse_ind_obj(&xref->trailer, xref, xref->file, buf, cap, NULL, NULL, NULL); if (error) return fz_rethrow(error, "cannot parse trailer (compressed)"); return fz_okay; } static fz_error -pdf_readtrailer(pdf_xref *xref, char *buf, int cap) +pdf_read_trailer(pdf_xref *xref, char *buf, int cap) { fz_error error; int c; fz_seek(xref->file, xref->startxref, 0); - while (iswhite(fz_peekbyte(xref->file))) - fz_readbyte(xref->file); + while (iswhite(fz_peek_byte(xref->file))) + fz_read_byte(xref->file); - c = fz_peekbyte(xref->file); + c = fz_peek_byte(xref->file); if (c == 'x') { - error = pdf_readoldtrailer(xref, buf, cap); + error = pdf_read_old_trailer(xref, buf, cap); if (error) return fz_rethrow(error, "cannot read trailer"); } else if (c >= '0' && c <= '9') { - error = pdf_readnewtrailer(xref, buf, cap); + error = pdf_read_new_trailer(xref, buf, cap); if (error) return fz_rethrow(error, "cannot read trailer"); } @@ -176,24 +176,24 @@ pdf_readtrailer(pdf_xref *xref, char *buf, int cap) */ void -pdf_resizexref(pdf_xref *xref, int newlen) +pdf_resize_xref(pdf_xref *xref, int newlen) { int i; - xref->table = fz_realloc(xref->table, newlen, sizeof(pdf_xrefentry)); + xref->table = fz_realloc(xref->table, newlen, sizeof(pdf_xref_entry)); for (i = xref->len; i < newlen; i++) { xref->table[i].type = 0; xref->table[i].ofs = 0; xref->table[i].gen = 0; - xref->table[i].stmofs = 0; - xref->table[i].obj = nil; + xref->table[i].stm_ofs = 0; + xref->table[i].obj = NULL; } xref->len = newlen; } static fz_error -pdf_readoldxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) +pdf_read_old_xref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) { fz_error error; int ofs, len; @@ -203,19 +203,19 @@ pdf_readoldxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) int i; int c; - pdf_logxref("load old xref format\n"); + pdf_log_xref("load old xref format\n"); - fz_readline(xref->file, buf, cap); + fz_read_line(xref->file, buf, cap); if (strncmp(buf, "xref", 4) != 0) return fz_throw("cannot find xref marker"); while (1) { - c = fz_peekbyte(xref->file); + c = fz_peek_byte(xref->file); if (!(c >= '0' && c <= '9')) break; - fz_readline(xref->file, buf, cap); + fz_read_line(xref->file, buf, cap); s = buf; ofs = atoi(fz_strsep(&s, " ")); len = atoi(fz_strsep(&s, " ")); @@ -231,7 +231,7 @@ pdf_readoldxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) if (ofs + len > xref->len) { fz_warn("broken xref section, proceeding anyway."); - pdf_resizexref(xref, ofs + len); + pdf_resize_xref(xref, ofs + len); } for (i = ofs; i < ofs + len; i++) @@ -259,23 +259,23 @@ pdf_readoldxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) error = pdf_lex(&tok, xref->file, buf, cap, &n); if (error) return fz_rethrow(error, "cannot parse trailer"); - if (tok != PDF_TTRAILER) + if (tok != PDF_TOK_TRAILER) return fz_throw("expected trailer marker"); error = pdf_lex(&tok, xref->file, buf, cap, &n); if (error) return fz_rethrow(error, "cannot parse trailer"); - if (tok != PDF_TODICT) + if (tok != PDF_TOK_OPEN_DICT) return fz_throw("expected trailer dictionary"); - error = pdf_parsedict(trailerp, xref, xref->file, buf, cap); + error = pdf_parse_dict(trailerp, xref, xref->file, buf, cap); if (error) return fz_rethrow(error, "cannot parse trailer"); return fz_okay; } static fz_error -pdf_readnewxrefsection(pdf_xref *xref, fz_stream *stm, int i0, int i1, int w0, int w1, int w2) +pdf_read_new_xref_section(pdf_xref *xref, fz_stream *stm, int i0, int i1, int w0, int w1, int w2) { int i, n; @@ -288,15 +288,15 @@ pdf_readnewxrefsection(pdf_xref *xref, fz_stream *stm, int i0, int i1, int w0, i int b = 0; int c = 0; - if (fz_iseof(stm)) + if (fz_is_eof(stm)) return fz_throw("truncated xref stream"); for (n = 0; n < w0; n++) - a = (a << 8) + fz_readbyte(stm); + a = (a << 8) + fz_read_byte(stm); for (n = 0; n < w1; n++) - b = (b << 8) + fz_readbyte(stm); + b = (b << 8) + fz_read_byte(stm); for (n = 0; n < w2; n++) - c = (c << 8) + fz_readbyte(stm); + c = (c << 8) + fz_read_byte(stm); if (!xref->table[i].type) { @@ -311,83 +311,83 @@ pdf_readnewxrefsection(pdf_xref *xref, fz_stream *stm, int i0, int i1, int w0, i } static fz_error -pdf_readnewxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) +pdf_read_new_xref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) { fz_error error; fz_stream *stm; fz_obj *trailer; fz_obj *index; fz_obj *obj; - int num, gen, stmofs; + int num, gen, stm_ofs; int size, w0, w1, w2; int t; - pdf_logxref("load new xref format\n"); + pdf_log_xref("load new xref format\n"); - error = pdf_parseindobj(&trailer, xref, xref->file, buf, cap, &num, &gen, &stmofs); + error = pdf_parse_ind_obj(&trailer, xref, xref->file, buf, cap, &num, &gen, &stm_ofs); if (error) return fz_rethrow(error, "cannot parse compressed xref stream object"); - obj = fz_dictgets(trailer, "Size"); + obj = fz_dict_gets(trailer, "Size"); if (!obj) { - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_throw("xref stream missing Size entry (%d %d R)", num, gen); } - size = fz_toint(obj); + size = fz_to_int(obj); if (size > xref->len) { - pdf_resizexref(xref, size); + pdf_resize_xref(xref, size); } if (num < 0 || num >= xref->len) { - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_throw("object id (%d %d R) out of range (0..%d)", num, gen, xref->len - 1); } - pdf_logxref("\tnum=%d gen=%d size=%d\n", num, gen, size); + pdf_log_xref("\tnum=%d gen=%d size=%d\n", num, gen, size); - obj = fz_dictgets(trailer, "W"); + obj = fz_dict_gets(trailer, "W"); if (!obj) { - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_throw("xref stream missing W entry (%d %d R)", num, gen); } - w0 = fz_toint(fz_arrayget(obj, 0)); - w1 = fz_toint(fz_arrayget(obj, 1)); - w2 = fz_toint(fz_arrayget(obj, 2)); + w0 = fz_to_int(fz_array_get(obj, 0)); + w1 = fz_to_int(fz_array_get(obj, 1)); + w2 = fz_to_int(fz_array_get(obj, 2)); - index = fz_dictgets(trailer, "Index"); + index = fz_dict_gets(trailer, "Index"); - error = pdf_openstreamat(&stm, xref, num, gen, trailer, stmofs); + error = pdf_open_stream_at(&stm, xref, num, gen, trailer, stm_ofs); if (error) { - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_rethrow(error, "cannot open compressed xref stream (%d %d R)", num, gen); } if (!index) { - error = pdf_readnewxrefsection(xref, stm, 0, size, w0, w1, w2); + error = pdf_read_new_xref_section(xref, stm, 0, size, w0, w1, w2); if (error) { fz_close(stm); - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_rethrow(error, "cannot read xref stream (%d %d R)", num, gen); } } else { - for (t = 0; t < fz_arraylen(index); t += 2) + for (t = 0; t < fz_array_len(index); t += 2) { - int i0 = fz_toint(fz_arrayget(index, t + 0)); - int i1 = fz_toint(fz_arrayget(index, t + 1)); - error = pdf_readnewxrefsection(xref, stm, i0, i1, w0, w1, w2); + int i0 = fz_to_int(fz_array_get(index, t + 0)); + int i1 = fz_to_int(fz_array_get(index, t + 1)); + error = pdf_read_new_xref_section(xref, stm, i0, i1, w0, w1, w2); if (error) { fz_close(stm); - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_rethrow(error, "cannot read xref stream section (%d %d R)", num, gen); } } @@ -401,26 +401,26 @@ pdf_readnewxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) } static fz_error -pdf_readxref(fz_obj **trailerp, pdf_xref *xref, int ofs, char *buf, int cap) +pdf_read_xref(fz_obj **trailerp, pdf_xref *xref, int ofs, char *buf, int cap) { fz_error error; int c; fz_seek(xref->file, ofs, 0); - while (iswhite(fz_peekbyte(xref->file))) - fz_readbyte(xref->file); + while (iswhite(fz_peek_byte(xref->file))) + fz_read_byte(xref->file); - c = fz_peekbyte(xref->file); + c = fz_peek_byte(xref->file); if (c == 'x') { - error = pdf_readoldxref(trailerp, xref, buf, cap); + error = pdf_read_old_xref(trailerp, xref, buf, cap); if (error) return fz_rethrow(error, "cannot read xref (ofs=%d)", ofs); } else if (c >= '0' && c <= '9') { - error = pdf_readnewxref(trailerp, xref, buf, cap); + error = pdf_read_new_xref(trailerp, xref, buf, cap); if (error) return fz_rethrow(error, "cannot read xref (ofs=%d)", ofs); } @@ -433,43 +433,43 @@ pdf_readxref(fz_obj **trailerp, pdf_xref *xref, int ofs, char *buf, int cap) } static fz_error -pdf_readxrefsections(pdf_xref *xref, int ofs, char *buf, int cap) +pdf_read_xref_sections(pdf_xref *xref, int ofs, char *buf, int cap) { fz_error error; fz_obj *trailer; fz_obj *prev; fz_obj *xrefstm; - error = pdf_readxref(&trailer, xref, ofs, buf, cap); + error = pdf_read_xref(&trailer, xref, ofs, buf, cap); if (error) return fz_rethrow(error, "cannot read xref section"); /* FIXME: do we overwrite free entries properly? */ - xrefstm = fz_dictgets(trailer, "XRefStm"); + xrefstm = fz_dict_gets(trailer, "XRefStm"); if (xrefstm) { - pdf_logxref("load xrefstm\n"); - error = pdf_readxrefsections(xref, fz_toint(xrefstm), buf, cap); + pdf_log_xref("load xrefstm\n"); + error = pdf_read_xref_sections(xref, fz_to_int(xrefstm), buf, cap); if (error) { - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_rethrow(error, "cannot read /XRefStm xref section"); } } - prev = fz_dictgets(trailer, "Prev"); + prev = fz_dict_gets(trailer, "Prev"); if (prev) { - pdf_logxref("load prev at %#x\n", fz_toint(prev)); - error = pdf_readxrefsections(xref, fz_toint(prev), buf, cap); + pdf_log_xref("load prev at %#x\n", fz_to_int(prev)); + error = pdf_read_xref_sections(xref, fz_to_int(prev), buf, cap); if (error) { - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_rethrow(error, "cannot read /Prev xref section"); } } - fz_dropobj(trailer); + fz_drop_obj(trailer); return fz_okay; } @@ -478,33 +478,33 @@ pdf_readxrefsections(pdf_xref *xref, int ofs, char *buf, int cap) */ static fz_error -pdf_loadxref(pdf_xref *xref, char *buf, int bufsize) +pdf_load_xref(pdf_xref *xref, char *buf, int bufsize) { fz_error error; fz_obj *size; int i; - error = pdf_loadversion(xref); + error = pdf_load_version(xref); if (error) return fz_rethrow(error, "cannot read version marker"); - error = pdf_readstartxref(xref); + error = pdf_read_start_xref(xref); if (error) return fz_rethrow(error, "cannot read startxref"); - error = pdf_readtrailer(xref, buf, bufsize); + error = pdf_read_trailer(xref, buf, bufsize); if (error) return fz_rethrow(error, "cannot read trailer"); - size = fz_dictgets(xref->trailer, "Size"); + size = fz_dict_gets(xref->trailer, "Size"); if (!size) return fz_throw("trailer missing Size entry"); - pdf_logxref("\tsize %d at %#x\n", fz_toint(size), xref->startxref); + pdf_log_xref("\tsize %d at %#x\n", fz_to_int(size), xref->startxref); - pdf_resizexref(xref, fz_toint(size)); + pdf_resize_xref(xref, fz_to_int(size)); - error = pdf_readxrefsections(xref, xref->startxref, buf, bufsize); + error = pdf_read_xref_sections(xref, xref->startxref, buf, bufsize); if (error) return fz_rethrow(error, "cannot read xref"); @@ -515,7 +515,7 @@ pdf_loadxref(pdf_xref *xref, char *buf, int bufsize) /* broken pdfs where object offsets are out of range */ for (i = 0; i < xref->len; i++) if (xref->table[i].type == 'n') - if (xref->table[i].ofs <= 0 || xref->table[i].ofs >= xref->filesize) + if (xref->table[i].ofs <= 0 || xref->table[i].ofs >= xref->file_size) return fz_throw("object offset out of range: %d (%d 0 R)", xref->table[i].ofs, i); return fz_okay; @@ -527,7 +527,7 @@ pdf_loadxref(pdf_xref *xref, char *buf, int bufsize) */ fz_error -pdf_openxrefwithstream(pdf_xref **xrefp, fz_stream *file, char *password) +pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password) { pdf_xref *xref; fz_error error; @@ -536,61 +536,61 @@ pdf_openxrefwithstream(pdf_xref **xrefp, fz_stream *file, char *password) int i, repaired = 0; /* install pdf specific callback */ - fz_resolveindirect = pdf_resolveindirect; + fz_resolve_indirect = pdf_resolve_indirect; xref = fz_malloc(sizeof(pdf_xref)); memset(xref, 0, sizeof(pdf_xref)); - pdf_logxref("openxref %p\n", xref); + pdf_log_xref("openxref %p\n", xref); - xref->file = fz_keepstream(file); + xref->file = fz_keep_stream(file); - error = pdf_loadxref(xref, xref->scratch, sizeof xref->scratch); + error = pdf_load_xref(xref, xref->scratch, sizeof xref->scratch); if (error) { fz_catch(error, "trying to repair"); if (xref->table) { fz_free(xref->table); - xref->table = nil; + xref->table = NULL; xref->len = 0; } if (xref->trailer) { - fz_dropobj(xref->trailer); - xref->trailer = nil; + fz_drop_obj(xref->trailer); + xref->trailer = NULL; } - error = pdf_repairxref(xref, xref->scratch, sizeof xref->scratch); + error = pdf_repair_xref(xref, xref->scratch, sizeof xref->scratch); if (error) { - pdf_freexref(xref); + pdf_free_xref(xref); return fz_rethrow(error, "cannot repair document"); } repaired = 1; } - encrypt = fz_dictgets(xref->trailer, "Encrypt"); - id = fz_dictgets(xref->trailer, "ID"); - if (fz_isdict(encrypt)) + encrypt = fz_dict_gets(xref->trailer, "Encrypt"); + id = fz_dict_gets(xref->trailer, "ID"); + if (fz_is_dict(encrypt)) { - error = pdf_newcrypt(&xref->crypt, encrypt, id); + error = pdf_new_crypt(&xref->crypt, encrypt, id); if (error) { - pdf_freexref(xref); + pdf_free_xref(xref); return fz_rethrow(error, "cannot decrypt document"); } } - if (pdf_needspassword(xref)) + if (pdf_needs_password(xref)) { /* Only care if we have a password */ if (password) { - int okay = pdf_authenticatepassword(xref, password); + int okay = pdf_authenticate_password(xref, password); if (!okay) { - pdf_freexref(xref); + pdf_free_xref(xref); return fz_throw("invalid password"); } } @@ -600,22 +600,22 @@ pdf_openxrefwithstream(pdf_xref **xrefp, fz_stream *file, char *password) { int hasroot, hasinfo; - error = pdf_repairobjstms(xref); + error = pdf_repair_obj_stms(xref); if (error) { - pdf_freexref(xref); + pdf_free_xref(xref); return fz_rethrow(error, "cannot repair document"); } - hasroot = fz_dictgets(xref->trailer, "Root") != nil; - hasinfo = fz_dictgets(xref->trailer, "Info") != nil; + hasroot = fz_dict_gets(xref->trailer, "Root") != NULL; + hasinfo = fz_dict_gets(xref->trailer, "Info") != NULL; for (i = 1; i < xref->len; i++) { if (xref->table[i].type == 0 || xref->table[i].type == 'f') continue; - error = pdf_loadobject(&dict, xref, i, 0); + error = pdf_load_object(&dict, xref, i, 0); if (error) { fz_catch(error, "ignoring broken object (%d 0 R)", i); @@ -624,28 +624,28 @@ pdf_openxrefwithstream(pdf_xref **xrefp, fz_stream *file, char *password) if (!hasroot) { - obj = fz_dictgets(dict, "Type"); - if (fz_isname(obj) && !strcmp(fz_toname(obj), "Catalog")) + obj = fz_dict_gets(dict, "Type"); + if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Catalog")) { - pdf_logxref("found catalog: (%d %d R)\n", i, 0); - obj = fz_newindirect(i, 0, xref); - fz_dictputs(xref->trailer, "Root", obj); - fz_dropobj(obj); + pdf_log_xref("found catalog: (%d %d R)\n", i, 0); + obj = fz_new_indirect(i, 0, xref); + fz_dict_puts(xref->trailer, "Root", obj); + fz_drop_obj(obj); } } if (!hasinfo) { - if (fz_dictgets(dict, "Creator") || fz_dictgets(dict, "Producer")) + if (fz_dict_gets(dict, "Creator") || fz_dict_gets(dict, "Producer")) { - pdf_logxref("found info: (%d %d R)\n", i, 0); - obj = fz_newindirect(i, 0, xref); - fz_dictputs(xref->trailer, "Info", obj); - fz_dropobj(obj); + pdf_log_xref("found info: (%d %d R)\n", i, 0); + obj = fz_new_indirect(i, 0, xref); + fz_dict_puts(xref->trailer, "Info", obj); + fz_drop_obj(obj); } } - fz_dropobj(dict); + fz_drop_obj(dict); } } @@ -654,14 +654,14 @@ pdf_openxrefwithstream(pdf_xref **xrefp, fz_stream *file, char *password) } void -pdf_freexref(pdf_xref *xref) +pdf_free_xref(pdf_xref *xref) { int i; - pdf_logxref("freexref %p\n", xref); + pdf_log_xref("freexref %p\n", xref); if (xref->store) - pdf_freestore(xref->store); + pdf_free_store(xref->store); if (xref->table) { @@ -669,50 +669,50 @@ pdf_freexref(pdf_xref *xref) { if (xref->table[i].obj) { - fz_dropobj(xref->table[i].obj); - xref->table[i].obj = nil; + fz_drop_obj(xref->table[i].obj); + xref->table[i].obj = NULL; } } fz_free(xref->table); } - if (xref->pageobjs) + if (xref->page_objs) { - for (i = 0; i < xref->pagelen; i++) - fz_dropobj(xref->pageobjs[i]); - fz_free(xref->pageobjs); + for (i = 0; i < xref->page_len; i++) + fz_drop_obj(xref->page_objs[i]); + fz_free(xref->page_objs); } - if (xref->pagerefs) + if (xref->page_refs) { - for (i = 0; i < xref->pagelen; i++) - fz_dropobj(xref->pagerefs[i]); - fz_free(xref->pagerefs); + for (i = 0; i < xref->page_len; i++) + fz_drop_obj(xref->page_refs[i]); + fz_free(xref->page_refs); } if (xref->file) fz_close(xref->file); if (xref->trailer) - fz_dropobj(xref->trailer); + fz_drop_obj(xref->trailer); if (xref->crypt) - pdf_freecrypt(xref->crypt); + pdf_free_crypt(xref->crypt); fz_free(xref); } void -pdf_debugxref(pdf_xref *xref) +pdf_debug_xref(pdf_xref *xref) { int i; printf("xref\n0 %d\n", xref->len); for (i = 0; i < xref->len; i++) { - printf("%05d: %010d %05d %c (refs=%d, stmofs=%d)\n", i, + printf("%05d: %010d %05d %c (refs=%d, stm_ofs=%d)\n", i, xref->table[i].ofs, xref->table[i].gen, xref->table[i].type ? xref->table[i].type : '-', xref->table[i].obj ? xref->table[i].obj->refs : 0, - xref->table[i].stmofs); + xref->table[i].stm_ofs); } } @@ -721,7 +721,7 @@ pdf_debugxref(pdf_xref *xref) */ static fz_error -pdf_loadobjstm(pdf_xref *xref, int num, int gen, char *buf, int cap) +pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap) { fz_error error; fz_stream *stm; @@ -735,21 +735,21 @@ pdf_loadobjstm(pdf_xref *xref, int num, int gen, char *buf, int cap) int i, n; int tok; - pdf_logxref("loadobjstm (%d %d R)\n", num, gen); + pdf_log_xref("loadobjstm (%d %d R)\n", num, gen); - error = pdf_loadobject(&objstm, xref, num, gen); + error = pdf_load_object(&objstm, xref, num, gen); if (error) return fz_rethrow(error, "cannot load object stream object (%d %d R)", num, gen); - count = fz_toint(fz_dictgets(objstm, "N")); - first = fz_toint(fz_dictgets(objstm, "First")); + count = fz_to_int(fz_dict_gets(objstm, "N")); + first = fz_to_int(fz_dict_gets(objstm, "First")); - pdf_logxref("\tcount %d\n", count); + pdf_log_xref("\tcount %d\n", count); numbuf = fz_calloc(count, sizeof(int)); ofsbuf = fz_calloc(count, sizeof(int)); - error = pdf_openstream(&stm, xref, num, gen); + error = pdf_open_stream(&stm, xref, num, gen); if (error) { error = fz_rethrow(error, "cannot open object stream (%d %d R)", num, gen); @@ -759,7 +759,7 @@ pdf_loadobjstm(pdf_xref *xref, int num, int gen, char *buf, int cap) for (i = 0; i < count; i++) { error = pdf_lex(&tok, stm, buf, cap, &n); - if (error || tok != PDF_TINT) + if (error || tok != PDF_TOK_INT) { error = fz_rethrow(error, "corrupt object stream (%d %d R)", num, gen); goto cleanupstm; @@ -767,7 +767,7 @@ pdf_loadobjstm(pdf_xref *xref, int num, int gen, char *buf, int cap) numbuf[i] = atoi(buf); error = pdf_lex(&tok, stm, buf, cap, &n); - if (error || tok != PDF_TINT) + if (error || tok != PDF_TOK_INT) { error = fz_rethrow(error, "corrupt object stream (%d %d R)", num, gen); goto cleanupstm; @@ -781,7 +781,7 @@ pdf_loadobjstm(pdf_xref *xref, int num, int gen, char *buf, int cap) { fz_seek(stm, first + ofsbuf[i], 0); - error = pdf_parsestmobj(&obj, xref, stm, buf, cap); + error = pdf_parse_stm_obj(&obj, xref, stm, buf, cap); if (error) { error = fz_rethrow(error, "cannot parse object %d in stream (%d %d R)", i, num, gen); @@ -790,7 +790,7 @@ pdf_loadobjstm(pdf_xref *xref, int num, int gen, char *buf, int cap) if (numbuf[i] < 1 || numbuf[i] >= xref->len) { - fz_dropobj(obj); + fz_drop_obj(obj); error = fz_throw("object id (%d 0 R) out of range (0..%d)", numbuf[i], xref->len - 1); goto cleanupstm; } @@ -798,19 +798,19 @@ pdf_loadobjstm(pdf_xref *xref, int num, int gen, char *buf, int cap) if (xref->table[numbuf[i]].type == 'o' && xref->table[numbuf[i]].ofs == num) { if (xref->table[numbuf[i]].obj) - fz_dropobj(xref->table[numbuf[i]].obj); + fz_drop_obj(xref->table[numbuf[i]].obj); xref->table[numbuf[i]].obj = obj; } else { - fz_dropobj(obj); + fz_drop_obj(obj); } } fz_close(stm); fz_free(ofsbuf); fz_free(numbuf); - fz_dropobj(objstm); + fz_drop_obj(objstm); return fz_okay; cleanupstm: @@ -818,7 +818,7 @@ cleanupstm: cleanupbuf: fz_free(ofsbuf); fz_free(numbuf); - fz_dropobj(objstm); + fz_drop_obj(objstm); return error; /* already rethrown */ } @@ -827,10 +827,10 @@ cleanupbuf: */ fz_error -pdf_cacheobject(pdf_xref *xref, int num, int gen) +pdf_cache_object(pdf_xref *xref, int num, int gen) { fz_error error; - pdf_xrefentry *x; + pdf_xref_entry *x; int rnum, rgen; if (num < 0 || num >= xref->len) @@ -843,15 +843,15 @@ pdf_cacheobject(pdf_xref *xref, int num, int gen) if (x->type == 'f') { - x->obj = fz_newnull(); + x->obj = fz_new_null(); return fz_okay; } else if (x->type == 'n') { fz_seek(xref->file, x->ofs, 0); - error = pdf_parseindobj(&x->obj, xref, xref->file, xref->scratch, sizeof xref->scratch, - &rnum, &rgen, &x->stmofs); + error = pdf_parse_ind_obj(&x->obj, xref, xref->file, xref->scratch, sizeof xref->scratch, + &rnum, &rgen, &x->stm_ofs); if (error) return fz_rethrow(error, "cannot parse object (%d %d R)", num, gen); @@ -859,13 +859,13 @@ pdf_cacheobject(pdf_xref *xref, int num, int gen) return fz_throw("found object (%d %d R) instead of (%d %d R)", rnum, rgen, num, gen); if (xref->crypt) - pdf_cryptobj(xref->crypt, x->obj, num, gen); + pdf_crypt_obj(xref->crypt, x->obj, num, gen); } else if (x->type == 'o') { if (!x->obj) { - error = pdf_loadobjstm(xref, x->ofs, 0, xref->scratch, sizeof xref->scratch); + error = pdf_load_obj_stm(xref, x->ofs, 0, xref->scratch, sizeof xref->scratch); if (error) return fz_rethrow(error, "cannot load object stream containing object (%d %d R)", num, gen); if (!x->obj) @@ -881,32 +881,32 @@ pdf_cacheobject(pdf_xref *xref, int num, int gen) } fz_error -pdf_loadobject(fz_obj **objp, pdf_xref *xref, int num, int gen) +pdf_load_object(fz_obj **objp, pdf_xref *xref, int num, int gen) { fz_error error; - error = pdf_cacheobject(xref, num, gen); + error = pdf_cache_object(xref, num, gen); if (error) return fz_rethrow(error, "cannot load object (%d %d R) into cache", num, gen); assert(xref->table[num].obj); - *objp = fz_keepobj(xref->table[num].obj); + *objp = fz_keep_obj(xref->table[num].obj); return fz_okay; } fz_obj * -pdf_resolveindirect(fz_obj *ref) +pdf_resolve_indirect(fz_obj *ref) { - if (fz_isindirect(ref)) + if (fz_is_indirect(ref)) { pdf_xref *xref = ref->u.r.xref; - int num = fz_tonum(ref); - int gen = fz_togen(ref); + int num = fz_to_num(ref); + int gen = fz_to_gen(ref); if (xref) { - fz_error error = pdf_cacheobject(xref, num, gen); + fz_error error = pdf_cache_object(xref, num, gen); if (error) { fz_catch(error, "cannot load object (%d %d R) into cache", num, gen); @@ -921,9 +921,9 @@ pdf_resolveindirect(fz_obj *ref) /* Replace numbered object -- for use by pdfclean and similar tools */ void -pdf_updateobject(pdf_xref *xref, int num, int gen, fz_obj *newobj) +pdf_update_object(pdf_xref *xref, int num, int gen, fz_obj *newobj) { - pdf_xrefentry *x; + pdf_xref_entry *x; if (num < 0 || num >= xref->len) { @@ -934,29 +934,29 @@ pdf_updateobject(pdf_xref *xref, int num, int gen, fz_obj *newobj) x = &xref->table[num]; if (x->obj) - fz_dropobj(x->obj); + fz_drop_obj(x->obj); - x->obj = fz_keepobj(newobj); + x->obj = fz_keep_obj(newobj); x->type = 'n'; x->ofs = 0; } /* - * Convenience function to open a file then call pdf_openxrefwithstream. + * Convenience function to open a file then call pdf_open_xref_with_stream. */ fz_error -pdf_openxref(pdf_xref **xrefp, char *filename, char *password) +pdf_open_xref(pdf_xref **xrefp, char *filename, char *password) { fz_error error; pdf_xref *xref; fz_stream *file; - file = fz_openfile(filename); + file = fz_open_file(filename); if (!file) return fz_throw("cannot open file '%s': %s", filename, strerror(errno)); - error = pdf_openxrefwithstream(&xref, file, password); + error = pdf_open_xref_with_stream(&xref, file, password); if (error) return fz_rethrow(error, "cannot load document '%s'", filename); |