Fri, 14 Mar 2003 08:24:37 +0000
finished implementing page labels.
Makefile | file | annotate | diff | revisions | |
pdf.c | file | annotate | diff | revisions | |
pdf.h | file | annotate | diff | revisions | |
pdf_name_tree.c | file | annotate | diff | revisions | |
pdf_name_tree.h | file | annotate | diff | revisions | |
pdf_page_label.c | file | annotate | diff | revisions | |
pdf_private.h | file | annotate | diff | revisions | |
semantics.c | file | annotate | diff | revisions | |
semantics.h | file | annotate | diff | revisions | |
tumble.c | file | annotate | diff | revisions | |
tumble.h | file | annotate | diff | revisions |
1.1 diff -r d47b66e1722f -r 4b8c80d77f76 Makefile 1.2 --- a/Makefile Fri Mar 14 07:08:52 2003 +0000 1.3 +++ b/Makefile Fri Mar 14 08:24:37 2003 +0000 1.4 @@ -1,6 +1,6 @@ 1.5 # tumble: build a PDF file from image files 1.6 # Makefile 1.7 -# $Id: Makefile,v 1.31 2003/03/13 03:50:59 eric Exp $ 1.8 +# $Id: Makefile,v 1.32 2003/03/14 00:24:37 eric Exp $ 1.9 # Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 1.10 # 1.11 # This program is free software; you can redistribute it and/or modify 1.12 @@ -55,7 +55,7 @@ 1.13 # let me know why so I can improve this Makefile. 1.14 # ----------------------------------------------------------------------------- 1.15 1.16 -VERSION = 0.26 1.17 +VERSION = 0.27 1.18 1.19 PACKAGE = tumble 1.20 1.21 @@ -63,7 +63,8 @@ 1.22 1.23 CSRCS = tumble.c semantics.c \ 1.24 bitblt.c bitblt_table_gen.c bitblt_g4.c g4_table_gen.c \ 1.25 - pdf.c pdf_util.c pdf_prim.c pdf_bookmark.c pdf_name_tree.c \ 1.26 + pdf.c pdf_util.c pdf_prim.c pdf_name_tree.c \ 1.27 + pdf_bookmark.c pdf_page_label.c \ 1.28 pdf_text.c pdf_g4.c pdf_jpeg.c 1.29 OSRCS = scanner.l parser.y 1.30 HDRS = tumble.h semantics.h bitblt.h bitblt_tables.h \ 1.31 @@ -87,7 +88,8 @@ 1.32 1.33 tumble: tumble.o scanner.o semantics.o parser.tab.o \ 1.34 bitblt.o bitblt_g4.o bitblt_tables.o g4_tables.o \ 1.35 - pdf.o pdf_util.o pdf_prim.o pdf_bookmark.o pdf_name_tree.o \ 1.36 + pdf.o pdf_util.o pdf_prim.o pdf_name_tree.o \ 1.37 + pdf_bookmark.o pdf_page_label.o \ 1.38 pdf_text.o pdf_g4.o pdf_jpeg.o 1.39 $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ 1.40 ifndef DEBUG
2.1 diff -r d47b66e1722f -r 4b8c80d77f76 pdf.c 2.2 --- a/pdf.c Fri Mar 14 07:08:52 2003 +0000 2.3 +++ b/pdf.c Fri Mar 14 08:24:37 2003 +0000 2.4 @@ -2,7 +2,7 @@ 2.5 * tumble: build a PDF file from image files 2.6 * 2.7 * PDF routines 2.8 - * $Id: pdf.c,v 1.11 2003/03/13 03:44:34 eric Exp $ 2.9 + * $Id: pdf.c,v 1.12 2003/03/14 00:24:37 eric Exp $ 2.10 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 2.11 * 2.12 * This program is free software; you can redistribute it and/or modify 2.13 @@ -121,9 +121,15 @@ 2.14 2.15 void pdf_close (pdf_file_handle pdf_file) 2.16 { 2.17 - /* finalize all data structures */ 2.18 + /* finalize trees, object numbers aren't allocated until this step */ 2.19 pdf_finalize_name_trees (pdf_file); 2.20 2.21 + /* add the page label number tree, if it exists, to the catalog */ 2.22 + if (pdf_file->page_label_tree) 2.23 + pdf_set_dict_entry (pdf_file->catalog, 2.24 + "PageLabels", 2.25 + pdf_file->page_label_tree->root->dict); 2.26 + 2.27 /* write body */ 2.28 pdf_write_all_ind_obj (pdf_file); 2.29
3.1 diff -r d47b66e1722f -r 4b8c80d77f76 pdf.h 3.2 --- a/pdf.h Fri Mar 14 07:08:52 2003 +0000 3.3 +++ b/pdf.h Fri Mar 14 08:24:37 2003 +0000 3.4 @@ -2,7 +2,7 @@ 3.5 * tumble: build a PDF file from image files 3.6 * 3.7 * PDF routines 3.8 - * $Id: pdf.h,v 1.9 2003/03/13 00:57:05 eric Exp $ 3.9 + * $Id: pdf.h,v 1.10 2003/03/14 00:24:37 eric Exp $ 3.10 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 3.11 * 3.12 * This program is free software; you can redistribute it and/or modify 3.13 @@ -90,3 +90,11 @@ 3.14 char *title, 3.15 bool open, 3.16 pdf_page_handle pdf_page); 3.17 + 3.18 + 3.19 +void pdf_new_page_label (pdf_file_handle pdf_file, 3.20 + int page_index, 3.21 + int base, 3.22 + int count, 3.23 + char style, 3.24 + char *prefix);
4.1 diff -r d47b66e1722f -r 4b8c80d77f76 pdf_name_tree.c 4.2 --- a/pdf_name_tree.c Fri Mar 14 07:08:52 2003 +0000 4.3 +++ b/pdf_name_tree.c Fri Mar 14 08:24:37 2003 +0000 4.4 @@ -2,7 +2,7 @@ 4.5 * tumble: build a PDF file from image files 4.6 * 4.7 * PDF routines 4.8 - * $Id: pdf_name_tree.c,v 1.9 2003/03/13 00:57:05 eric Exp $ 4.9 + * $Id: pdf_name_tree.c,v 1.10 2003/03/14 00:24:37 eric Exp $ 4.10 * Copyright 2003 Eric Smith <eric@brouhaha.com> 4.11 * 4.12 * This program is free software; you can redistribute it and/or modify 4.13 @@ -37,31 +37,6 @@ 4.14 #include "pdf_name_tree.h" 4.15 4.16 4.17 -#define MAX_NAME_TREE_NODE_ENTRIES 16 4.18 - 4.19 - 4.20 -struct pdf_name_tree_node 4.21 -{ 4.22 - struct pdf_obj *dict; /* indirect reference */ 4.23 - 4.24 - struct pdf_name_tree_node *parent; /* NULL for root */ 4.25 - bool leaf; 4.26 - 4.27 - int count; /* how many kids or names/numbers are 4.28 - attached to this node */ 4.29 - 4.30 - struct pdf_name_tree_node *kids [MAX_NAME_TREE_NODE_ENTRIES]; /* non-leaf only */ 4.31 - 4.32 - struct pdf_obj *min_key; 4.33 - struct pdf_obj *max_key; 4.34 - 4.35 - /* following fields valid in leaf nodes only: */ 4.36 - 4.37 - struct pdf_obj *keys [MAX_NAME_TREE_NODE_ENTRIES]; 4.38 - struct pdf_obj *values [MAX_NAME_TREE_NODE_ENTRIES]; 4.39 -}; 4.40 - 4.41 - 4.42 struct pdf_name_tree *pdf_new_name_tree (pdf_file_handle pdf_file, 4.43 bool number_tree) 4.44 {
5.1 diff -r d47b66e1722f -r 4b8c80d77f76 pdf_name_tree.h 5.2 --- a/pdf_name_tree.h Fri Mar 14 07:08:52 2003 +0000 5.3 +++ b/pdf_name_tree.h Fri Mar 14 08:24:37 2003 +0000 5.4 @@ -2,7 +2,7 @@ 5.5 * tumble: build a PDF file from image files 5.6 * 5.7 * PDF routines 5.8 - * $Id: pdf_name_tree.h,v 1.3 2003/03/13 00:57:05 eric Exp $ 5.9 + * $Id: pdf_name_tree.h,v 1.4 2003/03/14 00:24:37 eric Exp $ 5.10 * Copyright 2003 Eric Smith <eric@brouhaha.com> 5.11 * 5.12 * This program is free software; you can redistribute it and/or modify 5.13 @@ -32,6 +32,31 @@ 5.14 }; 5.15 5.16 5.17 +#define MAX_NAME_TREE_NODE_ENTRIES 32 5.18 + 5.19 + 5.20 +struct pdf_name_tree_node 5.21 +{ 5.22 + struct pdf_obj *dict; /* indirect reference */ 5.23 + 5.24 + struct pdf_name_tree_node *parent; /* NULL for root */ 5.25 + bool leaf; 5.26 + 5.27 + int count; /* how many kids or names/numbers are 5.28 + attached to this node */ 5.29 + 5.30 + struct pdf_name_tree_node *kids [MAX_NAME_TREE_NODE_ENTRIES]; /* non-leaf only */ 5.31 + 5.32 + struct pdf_obj *min_key; 5.33 + struct pdf_obj *max_key; 5.34 + 5.35 + /* following fields valid in leaf nodes only: */ 5.36 + 5.37 + struct pdf_obj *keys [MAX_NAME_TREE_NODE_ENTRIES]; 5.38 + struct pdf_obj *values [MAX_NAME_TREE_NODE_ENTRIES]; 5.39 +}; 5.40 + 5.41 + 5.42 struct pdf_name_tree *pdf_new_name_tree (pdf_file_handle pdf_file, 5.43 bool number_tree); 5.44
6.1 diff -r d47b66e1722f -r 4b8c80d77f76 pdf_page_label.c 6.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 +++ b/pdf_page_label.c Fri Mar 14 08:24:37 2003 +0000 6.4 @@ -0,0 +1,72 @@ 6.5 +/* 6.6 + * tumble: build a PDF file from image files 6.7 + * 6.8 + * PDF routines 6.9 + * $Id: pdf_page_label.c,v 1.1 2003/03/14 00:24:37 eric Exp $ 6.10 + * Copyright 2003 Eric Smith <eric@brouhaha.com> 6.11 + * 6.12 + * This program is free software; you can redistribute it and/or modify 6.13 + * it under the terms of the GNU General Public License version 2 as 6.14 + * published by the Free Software Foundation. Note that permission is 6.15 + * not granted to redistribute this program under the terms of any 6.16 + * other version of the General Public License. 6.17 + * 6.18 + * This program is distributed in the hope that it will be useful, 6.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 6.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6.21 + * GNU General Public License for more details. 6.22 + * 6.23 + * You should have received a copy of the GNU General Public License 6.24 + * along with this program; if not, write to the Free Software 6.25 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 6.26 + */ 6.27 + 6.28 + 6.29 +#include <stdbool.h> 6.30 +#include <stdint.h> 6.31 +#include <stdio.h> 6.32 +#include <stdlib.h> 6.33 +#include <string.h> 6.34 + 6.35 + 6.36 +#include "bitblt.h" 6.37 +#include "pdf.h" 6.38 +#include "pdf_util.h" 6.39 +#include "pdf_prim.h" 6.40 +#include "pdf_private.h" 6.41 +#include "pdf_name_tree.h" 6.42 + 6.43 + 6.44 +void pdf_new_page_label (pdf_file_handle pdf_file, 6.45 + int page_index, 6.46 + int base, 6.47 + int count, 6.48 + char style, 6.49 + char *prefix) 6.50 +{ 6.51 + struct pdf_obj *label_dict; 6.52 + char style_str [2] = { style, '\0' }; 6.53 + 6.54 + fprintf (stderr, 6.55 + "page index %d, count %d, base %d, prefix '%s', style %c\n", 6.56 + page_index, count, base, 6.57 + prefix ? prefix : "NULL", 6.58 + style); 6.59 + 6.60 + if (! pdf_file->page_label_tree) 6.61 + { 6.62 + pdf_file->page_label_tree = pdf_new_name_tree (pdf_file, 1); 6.63 + } 6.64 + 6.65 + label_dict = pdf_new_obj (PT_DICTIONARY); 6.66 + pdf_set_dict_entry (label_dict, "S", pdf_new_name (style_str)); 6.67 + if (prefix) 6.68 + pdf_set_dict_entry (label_dict, "P", pdf_new_string (prefix)); 6.69 + if (base != 1) 6.70 + pdf_set_dict_entry (label_dict, "St", pdf_new_integer (base)); 6.71 + 6.72 + pdf_add_number_tree_element (pdf_file->page_label_tree, 6.73 + page_index, 6.74 + label_dict); 6.75 +} 6.76 +
7.1 diff -r d47b66e1722f -r 4b8c80d77f76 pdf_private.h 7.2 --- a/pdf_private.h Fri Mar 14 07:08:52 2003 +0000 7.3 +++ b/pdf_private.h Fri Mar 14 08:24:37 2003 +0000 7.4 @@ -2,7 +2,7 @@ 7.5 * tumble: build a PDF file from image files 7.6 * 7.7 * PDF routines 7.8 - * $Id: pdf_private.h,v 1.7 2003/03/13 00:57:05 eric Exp $ 7.9 + * $Id: pdf_private.h,v 1.8 2003/03/14 00:24:37 eric Exp $ 7.10 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 7.11 * 7.12 * This program is free software; you can redistribute it and/or modify 7.13 @@ -54,5 +54,6 @@ 7.14 struct pdf_pages *root; 7.15 struct pdf_bookmark *outline_root; 7.16 struct pdf_obj *trailer_dict; 7.17 + struct pdf_name_tree *page_label_tree; 7.18 struct pdf_name_tree *name_tree_list; 7.19 };
8.1 diff -r d47b66e1722f -r 4b8c80d77f76 semantics.c 8.2 --- a/semantics.c Fri Mar 14 07:08:52 2003 +0000 8.3 +++ b/semantics.c Fri Mar 14 08:24:37 2003 +0000 8.4 @@ -2,7 +2,7 @@ 8.5 * tumble: build a PDF file from image files 8.6 * 8.7 * Semantic routines for spec file parser 8.8 - * $Id: semantics.c,v 1.20 2003/03/13 23:08:52 eric Exp $ 8.9 + * $Id: semantics.c,v 1.21 2003/03/14 00:24:37 eric Exp $ 8.10 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 8.11 * 8.12 * This program is free software; you can redistribute it and/or modify 8.13 @@ -692,11 +692,6 @@ 8.14 fprintf (stderr, "error opening PDF file '%s'\n", output_fn); 8.15 return (0); 8.16 } 8.17 - page_label = get_output_page_label (page->output_context); 8.18 - process_page_numbers (page_index, 8.19 - range_count (page->range), 8.20 - page->range.first, 8.21 - page_label); 8.22 } 8.23 8.24 parity = ((image->range.first + i) % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN; 8.25 @@ -714,9 +709,24 @@ 8.26 8.27 if (verbose) 8.28 fprintf (stderr, "processing image %d\n", image->range.first + i); 8.29 + 8.30 + if (p) 8.31 + page_label = NULL; 8.32 + else 8.33 + { 8.34 + page_label = get_output_page_label (page->output_context); 8.35 + if (page_label) 8.36 + { 8.37 + page_label->page_index = page_index; 8.38 + page_label->base = page->range.first; 8.39 + page_label->count = range_count (page->range); 8.40 + } 8.41 + } 8.42 + 8.43 if (! process_page (image->range.first + i, 8.44 input_attributes, 8.45 - p ? NULL : page->bookmark_list)) 8.46 + p ? NULL : page->bookmark_list, 8.47 + page_label)) 8.48 { 8.49 fprintf (stderr, "error processing image %d\n", image->range.first + i); 8.50 return (0);
9.1 diff -r d47b66e1722f -r 4b8c80d77f76 semantics.h 9.2 --- a/semantics.h Fri Mar 14 07:08:52 2003 +0000 9.3 +++ b/semantics.h Fri Mar 14 08:24:37 2003 +0000 9.4 @@ -2,7 +2,7 @@ 9.5 * tumble: build a PDF file from image files 9.6 * 9.7 * Semantic routines for spec file parser 9.8 - * $Id: semantics.h,v 1.13 2003/03/13 00:57:05 eric Exp $ 9.9 + * $Id: semantics.h,v 1.14 2003/03/14 00:24:37 eric Exp $ 9.10 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 9.11 * 9.12 * This program is free software; you can redistribute it and/or modify 9.13 @@ -46,6 +46,10 @@ 9.14 { 9.15 char *prefix; 9.16 char style; 9.17 + /* the following fields are not filled by the parser: */ 9.18 + int page_index; 9.19 + int base; 9.20 + int count; 9.21 } page_label_t; 9.22 9.23
10.1 diff -r d47b66e1722f -r 4b8c80d77f76 tumble.c 10.2 --- a/tumble.c Fri Mar 14 07:08:52 2003 +0000 10.3 +++ b/tumble.c Fri Mar 14 08:24:37 2003 +0000 10.4 @@ -2,7 +2,7 @@ 10.5 * tumble: build a PDF file from image files 10.6 * 10.7 * Main program 10.8 - * $Id: tumble.c,v 1.33 2003/03/13 03:42:46 eric Exp $ 10.9 + * $Id: tumble.c,v 1.34 2003/03/14 00:24:37 eric Exp $ 10.10 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 10.11 * 10.12 * This program is free software; you can redistribute it and/or modify 10.13 @@ -227,14 +227,6 @@ 10.14 } 10.15 10.16 10.17 -void process_page_numbers (int page_index, 10.18 - int count, 10.19 - int base, 10.20 - page_label_t *page_label) 10.21 -{ 10.22 -} 10.23 - 10.24 - 10.25 /* frees original! */ 10.26 static Bitmap *resize_bitmap (Bitmap *src, 10.27 double x_resolution, 10.28 @@ -287,12 +279,9 @@ 10.29 } 10.30 10.31 10.32 -bool process_tiff_page (int image, /* range 1 .. n */ 10.33 - input_attributes_t input_attributes, 10.34 - bookmark_t *bookmarks) 10.35 +static pdf_page_handle process_tiff_page (int image, /* range 1 .. n */ 10.36 + input_attributes_t input_attributes) 10.37 { 10.38 - int result = 0; 10.39 - 10.40 uint32_t image_length, image_width; 10.41 uint32_t dest_image_length, dest_image_width; 10.42 #ifdef CHECK_DEPTH 10.43 @@ -315,7 +304,7 @@ 10.44 10.45 int row; 10.46 10.47 - pdf_page_handle page; 10.48 + pdf_page_handle page = NULL; 10.49 10.50 if (! TIFFSetDirectory (in, image - 1)) 10.51 { 10.52 @@ -473,29 +462,22 @@ 10.53 0); /* BlackIs1 */ 10.54 #endif 10.55 10.56 - while (bookmarks) 10.57 - { 10.58 - /* $$$ need to handle level here */ 10.59 - pdf_new_bookmark (NULL, bookmarks->name, 0, page); 10.60 - bookmarks = bookmarks->next; 10.61 - } 10.62 - 10.63 - result = 1; 10.64 + if (bitmap) 10.65 + free_bitmap (bitmap); 10.66 + return (page); 10.67 10.68 fail: 10.69 if (bitmap) 10.70 free_bitmap (bitmap); 10.71 10.72 - return (result); 10.73 + return (NULL); 10.74 } 10.75 10.76 10.77 #if 0 10.78 -bool process_jpeg_page (int image, /* range 1 .. n */ 10.79 - input_attributes_t input_attributes, 10.80 - bookmark_t *bookmarks) 10.81 +pdf_page_handle process_jpeg_page (int image, /* range 1 .. n */ 10.82 + input_attributes_t input_attributes) 10.83 { 10.84 - int result = 0; 10.85 FILE *f; 10.86 pdf_page_handle page; 10.87 10.88 @@ -510,20 +492,36 @@ 10.89 width_points, height_points, 10.90 f); 10.91 10.92 - return (result); 10.93 + return (page); 10.94 } 10.95 #endif 10.96 10.97 10.98 bool process_page (int image, /* range 1 .. n */ 10.99 input_attributes_t input_attributes, 10.100 - bookmark_t *bookmarks) 10.101 + bookmark_t *bookmarks, 10.102 + page_label_t *page_label) 10.103 { 10.104 - int result = 0; 10.105 + pdf_page_handle page; 10.106 + 10.107 + page = process_tiff_page (image, input_attributes); 10.108 10.109 - result = process_tiff_page (image, input_attributes, bookmarks); 10.110 + while (bookmarks) 10.111 + { 10.112 + /* $$$ need to handle level here */ 10.113 + pdf_new_bookmark (NULL, bookmarks->name, 0, page); 10.114 + bookmarks = bookmarks->next; 10.115 + } 10.116 10.117 - return (result); 10.118 + if (page_label) 10.119 + pdf_new_page_label (out->pdf, 10.120 + page_label->page_index, 10.121 + page_label->base, 10.122 + page_label->count, 10.123 + page_label->style, 10.124 + page_label->prefix); 10.125 + 10.126 + return (page != NULL); 10.127 } 10.128 10.129 10.130 @@ -625,7 +623,8 @@ 10.131 in_fn [i], 10.132 ip); 10.133 if (! process_page (ip, input_attributes, 10.134 - bookmark_fmt ? & bookmark : NULL)) 10.135 + bookmark_fmt ? & bookmark : NULL, 10.136 + NULL)) 10.137 fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]); 10.138 if (last_tiff_page ()) 10.139 break;
11.1 diff -r d47b66e1722f -r 4b8c80d77f76 tumble.h 11.2 --- a/tumble.h Fri Mar 14 07:08:52 2003 +0000 11.3 +++ b/tumble.h Fri Mar 14 08:24:37 2003 +0000 11.4 @@ -1,7 +1,7 @@ 11.5 /* 11.6 * tumble: build a PDF file from image files 11.7 * 11.8 - * $Id: tumble.h,v 1.13 2003/03/13 00:57:05 eric Exp $ 11.9 + * $Id: tumble.h,v 1.14 2003/03/14 00:24:37 eric Exp $ 11.10 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 11.11 * 11.12 * This program is free software; you can redistribute it and/or modify 11.13 @@ -57,13 +57,7 @@ 11.14 pdf_file_attributes_t *attributes); 11.15 11.16 11.17 -void process_page_numbers (int page_index, 11.18 - int count, 11.19 - int base, 11.20 - page_label_t *page_label); 11.21 - 11.22 - 11.23 - 11.24 bool process_page (int image, /* range 1 .. n */ 11.25 input_attributes_t input_attributes, 11.26 - bookmark_t *bookmarks); 11.27 + bookmark_t *bookmarks, 11.28 + page_label_t *page_label);