diff --git a/pdf_prim.c b/pdf_prim.c index a1f76bc..fee83c3 100644 --- a/pdf_prim.c +++ b/pdf_prim.c @@ -4,7 +4,7 @@ * will be compressed using ITU-T T.6 (G4) fax encoding. * * PDF routines - * $Id: pdf_prim.c,v 1.6 2003/03/04 17:58:36 eric Exp $ + * $Id: pdf_prim.c,v 1.7 2003/03/07 03:02:31 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -357,6 +357,38 @@ void pdf_set_real (struct pdf_obj *obj, double val) } +int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2) +{ + if (o1->type == PT_IND_REF) + o1 = pdf_deref_ind_obj (o1); + + if (o2->type == PT_IND_REF) + o2 = pdf_deref_ind_obj (o2); + + pdf_assert (o1->type == o2->type); + + switch (o1->type) + { + case PT_INTEGER: + if (o1->val.integer < o2->val.integer) + return (-1); + if (o1->val.integer > o2->val.integer) + return (1); + return (0); + case PT_REAL: + if (o1->val.real < o2->val.real) + return (-1); + if (o1->val.real > o2->val.real) + return (1); + return (0); + case PT_STRING: + return (strcmp (o1->val.string, o2->val.string)); + default: + pdf_fatal ("invalid object type for comparison\n"); + } +} + + static int name_char_needs_quoting (char c) { return ((c < '!') || (c > '~') || (c == '/') || (c == '\\') || diff --git a/pdf_prim.h b/pdf_prim.h index 6bce5f6..a6a410c 100644 --- a/pdf_prim.h +++ b/pdf_prim.h @@ -4,7 +4,7 @@ * will be compressed using ITU-T T.6 (G4) fax encoding. * * PDF routines - * $Id: pdf_prim.h,v 1.5 2003/03/04 17:58:36 eric Exp $ + * $Id: pdf_prim.h,v 1.6 2003/03/07 03:02:31 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -88,6 +88,10 @@ double pdf_get_real (struct pdf_obj *obj); void pdf_set_real (struct pdf_obj *obj, double val); +/* returns -1 if o1 < 02, 0 if o1 == o2, 1 if o1 > o2 */ +int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2); + + /* The callback will be called when the stream data is to be written to the file. app_data will be passed as an argument to the callback. */ struct pdf_obj *pdf_new_stream (pdf_file_handle pdf_file,