diff --git a/pdf.c b/pdf.c index e486694..517239b 100644 --- a/pdf.c +++ b/pdf.c @@ -4,7 +4,7 @@ * will be compressed using ITU-T T.6 (G4) fax encoding. * * PDF routines - * $Id: pdf.c,v 1.7 2003/03/12 03:17:00 eric Exp $ + * $Id: pdf.c,v 1.8 2003/03/12 22:56:57 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -181,7 +181,7 @@ pdf_page_handle pdf_new_page (pdf_file_handle pdf_file, pdf_add_array_elem (page->media_box, pdf_new_real (height)); page->procset = pdf_new_obj (PT_ARRAY); - pdf_add_array_elem (page->procset, pdf_new_name ("PDF")); + pdf_add_array_elem_unique (page->procset, pdf_new_name ("PDF")); page->resources = pdf_new_obj (PT_DICTIONARY); pdf_set_dict_entry (page->resources, "ProcSet", page->procset); diff --git a/pdf_g4.c b/pdf_g4.c index 195e1b9..b5a5dee 100644 --- a/pdf_g4.c +++ b/pdf_g4.c @@ -4,7 +4,7 @@ * will be compressed using ITU-T T.6 (G4) fax encoding. * * PDF routines - * $Id: pdf_g4.c,v 1.12 2003/03/11 23:53:55 eric Exp $ + * $Id: pdf_g4.c,v 1.13 2003/03/12 22:56:57 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -101,6 +101,8 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page, struct pdf_obj *content_stream; + pdf_add_array_elem_unique (pdf_page->procset, pdf_new_name ("ImageB")); + image = pdf_calloc (1, sizeof (struct pdf_g4_image)); image->width = width; diff --git a/pdf_prim.c b/pdf_prim.c index 300531c..cc29009 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.9 2003/03/11 23:43:56 eric Exp $ + * $Id: pdf_prim.c,v 1.10 2003/03/12 22:56:57 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -192,6 +192,32 @@ void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val) } +void pdf_add_array_elem_unique (struct pdf_obj *array_obj, struct pdf_obj *val) +{ + struct pdf_array_elem *elem; + + if (array_obj->type == PT_IND_REF) + array_obj = pdf_deref_ind_obj (array_obj); + + pdf_assert (array_obj->type == PT_ARRAY); + + for (elem = array_obj->val.array.first; elem; elem = elem->next) + if (pdf_compare_obj (val, elem->val) == 0) + return; + + elem = pdf_calloc (1, sizeof (struct pdf_array_elem)); + + elem->val = ref (val); + + if (! array_obj->val.array.first) + array_obj->val.array.first = elem; + else + array_obj->val.array.last->next = elem; + + array_obj->val.array.last = elem; +} + + struct pdf_obj *pdf_new_obj (pdf_obj_type type) { struct pdf_obj *obj = pdf_calloc (1, sizeof (struct pdf_obj)); @@ -374,6 +400,8 @@ int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2) return (0); case PT_STRING: return (strcmp (o1->val.string, o2->val.string)); + case PT_NAME: + return (strcmp (o1->val.name, o2->val.name)); default: pdf_fatal ("invalid object type for comparison\n"); } diff --git a/pdf_prim.h b/pdf_prim.h index b08c533..15d56e1 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.8 2003/03/11 23:43:56 eric Exp $ + * $Id: pdf_prim.h,v 1.9 2003/03/12 22:56:57 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -52,6 +52,11 @@ typedef void (*pdf_stream_write_callback)(pdf_file_handle pdf_file, void *app_data); +/* returns -1 if o1 < 02, 0 if o1 == o2, 1 if o1 > o2 */ +/* only works for integer, real, string, and name objects */ +int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2); + + void pdf_set_dict_entry (struct pdf_obj *dict_obj, char *key, struct pdf_obj *val); struct pdf_obj *pdf_get_dict_entry (struct pdf_obj *dict_obj, char *key); @@ -59,6 +64,14 @@ struct pdf_obj *pdf_get_dict_entry (struct pdf_obj *dict_obj, char *key); void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val); +/* Following is intended for things like ProcSet in which an array object + is used to represent a set. Only works if all objects in array, and + the element to be added are of scalar types (types that are supported + by pdf_compare_obj. Not efficient for large arrays as it does a + comaprison to every element. */ +void pdf_add_array_elem_unique (struct pdf_obj *array_obj, struct pdf_obj *val); + + /* Create a new object that will NOT be used indirectly */ struct pdf_obj *pdf_new_obj (pdf_obj_type type); @@ -88,10 +101,6 @@ 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,