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