1.1 diff -r 6e306105c128 -r 12bc5088172e tumble.c 1.2 --- a/tumble.c Wed Mar 05 01:58:31 2003 +0000 1.3 +++ b/tumble.c Wed Mar 05 01:58:36 2003 +0000 1.4 @@ -4,7 +4,7 @@ 1.5 * will be compressed using ITU-T T.6 (G4) fax encoding. 1.6 * 1.7 * Main program 1.8 - * $Id: tumble.c,v 1.24 2003/02/21 01:25:47 eric Exp $ 1.9 + * $Id: tumble.c,v 1.25 2003/03/04 17:58:36 eric Exp $ 1.10 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 1.11 * 1.12 * This program is free software; you can redistribute it and/or modify 1.13 @@ -88,7 +88,7 @@ 1.14 fprintf (stderr, " -v verbose\n"); 1.15 fprintf (stderr, " -b fmt create bookmarks\n"); 1.16 fprintf (stderr, "bookmark format:\n"); 1.17 - fprintf (stderr, " %%F file name\n"); 1.18 + fprintf (stderr, " %%F file name (sans suffix)\n"); 1.19 fprintf (stderr, " %%p page number\n"); 1.20 } 1.21 1.22 @@ -311,7 +311,7 @@ 1.23 points */ 1.24 1.25 Rect rect; 1.26 - Bitmap *bitmap; 1.27 + Bitmap *bitmap = NULL; 1.28 1.29 int row; 1.30 1.31 @@ -464,6 +464,7 @@ 1.32 1.33 page = pdf_new_page (out->pdf, width_points, height_points); 1.34 1.35 +#if 0 1.36 pdf_write_g4_fax_image (page, 1.37 0, 0, /* x, y */ 1.38 width_points, height_points, 1.39 @@ -471,21 +472,102 @@ 1.40 0, /* ImageMask */ 1.41 0, 0, 0, /* r, g, b */ 1.42 0); /* BlackIs1 */ 1.43 +#endif 1.44 1.45 - free_bitmap (bitmap); 1.46 + while (bookmarks) 1.47 + { 1.48 + /* $$$ need to handle level here */ 1.49 + pdf_new_bookmark (NULL, bookmarks->name, 0, page); 1.50 + bookmarks = bookmarks->next; 1.51 + } 1.52 1.53 result = 1; 1.54 1.55 fail: 1.56 + if (bitmap) 1.57 + free_bitmap (bitmap); 1.58 + 1.59 return (result); 1.60 } 1.61 1.62 1.63 -void main_args (char *out_fn, int inf_count, char **in_fn) 1.64 +#define MAX_BOOKMARK_NAME_LEN 500 1.65 + 1.66 + 1.67 +static int filename_length_without_suffix (char *in_fn) 1.68 +{ 1.69 + char *p; 1.70 + int len = strlen (in_fn); 1.71 + 1.72 + p = strrchr (in_fn, '.'); 1.73 + if (p && ((strcasecmp (p, ".tif") == 0) || 1.74 + (strcasecmp (p, ".tiff") == 0))) 1.75 + return (p - in_fn); 1.76 + return (len); 1.77 +} 1.78 + 1.79 + 1.80 +/* $$$ this function should ensure that it doesn't overflow the name string! */ 1.81 +static void generate_bookmark_name (char *name, 1.82 + char *bookmark_fmt, 1.83 + char *in_fn, 1.84 + int page) 1.85 +{ 1.86 + bool meta = 0; 1.87 + int len; 1.88 + 1.89 + while (*bookmark_fmt) 1.90 + { 1.91 + if (meta) 1.92 + { 1.93 + meta = 0; 1.94 + switch (*bookmark_fmt) 1.95 + { 1.96 + case '%': 1.97 + *(name++) = '%'; 1.98 + break; 1.99 + case 'F': 1.100 + len = filename_length_without_suffix (in_fn); 1.101 + strncpy (name, in_fn, len); 1.102 + name += len; 1.103 + break; 1.104 + case 'p': 1.105 + sprintf (name, "%d", page); 1.106 + name += strlen (name); 1.107 + break; 1.108 + default: 1.109 + break; 1.110 + } 1.111 + } 1.112 + else 1.113 + switch (*bookmark_fmt) 1.114 + { 1.115 + case '%': 1.116 + meta = 1; 1.117 + break; 1.118 + default: 1.119 + *(name++) = *bookmark_fmt; 1.120 + } 1.121 + bookmark_fmt++; 1.122 + } 1.123 + *bookmark_fmt = '\0'; 1.124 +} 1.125 + 1.126 + 1.127 +void main_args (char *out_fn, 1.128 + int inf_count, 1.129 + char **in_fn, 1.130 + char *bookmark_fmt) 1.131 { 1.132 int i, ip; 1.133 input_attributes_t input_attributes; 1.134 pdf_file_attributes_t output_attributes; 1.135 + bookmark_t bookmark; 1.136 + char bookmark_name [MAX_BOOKMARK_NAME_LEN]; 1.137 + 1.138 + bookmark.next = NULL; 1.139 + bookmark.level = 1; 1.140 + bookmark.name = & bookmark_name [0]; 1.141 1.142 memset (& input_attributes, 0, sizeof (input_attributes)); 1.143 memset (& output_attributes, 0, sizeof (output_attributes)); 1.144 @@ -499,7 +581,13 @@ 1.145 for (ip = 1;; ip++) 1.146 { 1.147 fprintf (stderr, "processing page %d of file \"%s\"\r", ip, in_fn [i]); 1.148 - if (! process_page (ip, input_attributes, NULL)) 1.149 + if (bookmark_fmt) 1.150 + generate_bookmark_name (& bookmark_name [0], 1.151 + bookmark_fmt, 1.152 + in_fn [i], 1.153 + ip); 1.154 + if (! process_page (ip, input_attributes, 1.155 + bookmark_fmt ? & bookmark : NULL)) 1.156 fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]); 1.157 if (last_tiff_page ()) 1.158 break; 1.159 @@ -596,7 +684,7 @@ 1.160 if (spec_fn) 1.161 main_spec (spec_fn); 1.162 else 1.163 - main_args (out_fn, inf_count, in_fn); 1.164 + main_args (out_fn, inf_count, in_fn, bookmark_fmt); 1.165 1.166 close_tiff_input_file (); 1.167 close_pdf_output_files ();