1.1 --- a/t2p.c Thu Feb 20 12:21:10 2003 +0000 1.2 +++ b/t2p.c Thu Feb 20 12:44:17 2003 +0000 1.3 @@ -4,7 +4,7 @@ 1.4 * will be compressed using ITU-T T.6 (G4) fax encoding. 1.5 * 1.6 * Main program 1.7 - * $Id: t2p.c,v 1.21 2003/01/21 10:39:55 eric Exp $ 1.8 + * $Id: t2p.c,v 1.22 2003/02/20 04:44:17 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 @@ -20,7 +20,8 @@ 1.13 * 1.14 * You should have received a copy of the GNU General Public License 1.15 * along with this program; if not, write to the Free Software 1.16 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA */ 1.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 1.18 + */ 1.19 1.20 1.21 #include <stdarg.h> 1.22 @@ -28,18 +29,17 @@ 1.23 #include <stdint.h> 1.24 #include <stdio.h> 1.25 #include <stdlib.h> 1.26 +#include <string.h> 1.27 #include <unistd.h> 1.28 1.29 #include <tiffio.h> 1.30 #define TIFF_REVERSE_BITS 1.31 1.32 -#include <panda/functions.h> 1.33 -#include <panda/constants.h> 1.34 - 1.35 #include "bitblt.h" 1.36 #include "semantics.h" 1.37 #include "parser.tab.h" 1.38 #include "t2p.h" 1.39 +#include "pdf.h" 1.40 1.41 1.42 #define MAX_INPUT_FILES 5000 1.43 @@ -55,7 +55,7 @@ 1.44 { 1.45 struct output_file_t *next; 1.46 char *name; 1.47 - panda_pdf *pdf; 1.48 + pdf_file_handle pdf; 1.49 } output_file_t; 1.50 1.51 1.52 @@ -66,7 +66,6 @@ 1.53 TIFF *in; 1.54 output_file_t *output_files; 1.55 output_file_t *out; 1.56 -/* panda_pdf *out; */ 1.57 1.58 1.59 char *progname; 1.60 @@ -87,6 +86,10 @@ 1.61 fprintf (stderr, " %s [options] <input.tif>... -o <output.pdf>\n", progname); 1.62 fprintf (stderr, "options:\n"); 1.63 fprintf (stderr, " -v verbose\n"); 1.64 + fprintf (stderr, " -b fmt create bookmarks\n"); 1.65 + fprintf (stderr, "bookmark format:\n"); 1.66 + fprintf (stderr, " %%F file name\n"); 1.67 + fprintf (stderr, " %%p page number\n"); 1.68 } 1.69 1.70 1.71 @@ -158,7 +161,7 @@ 1.72 for (o = output_files; o; o = n) 1.73 { 1.74 n = o->next; 1.75 - panda_close (o->pdf); 1.76 + pdf_close (o->pdf); 1.77 free (o->name); 1.78 free (o); 1.79 } 1.80 @@ -195,7 +198,7 @@ 1.81 return (0); 1.82 } 1.83 1.84 - o->pdf = panda_open (name, "w"); 1.85 + o->pdf = pdf_create (name); 1.86 if (! o->pdf) 1.87 { 1.88 fprintf (stderr, "can't open output file '%s'\n", name); 1.89 @@ -205,15 +208,15 @@ 1.90 } 1.91 1.92 if (attributes->author) 1.93 - panda_setauthor (o->pdf, attributes->author); 1.94 + pdf_set_author (o->pdf, attributes->author); 1.95 if (attributes->creator) 1.96 - panda_setcreator (o->pdf, attributes->creator); 1.97 + pdf_set_creator (o->pdf, attributes->creator); 1.98 if (attributes->title) 1.99 - panda_settitle (o->pdf, attributes->title); 1.100 + pdf_set_title (o->pdf, attributes->title); 1.101 if (attributes->subject) 1.102 - panda_setsubject (o->pdf, attributes->subject); 1.103 + pdf_set_subject (o->pdf, attributes->subject); 1.104 if (attributes->keywords) 1.105 - panda_setkeywords (o->pdf, attributes->keywords); 1.106 + pdf_set_keywords (o->pdf, attributes->keywords); 1.107 1.108 /* prepend new output file onto list */ 1.109 o->next = output_files; 1.110 @@ -304,23 +307,15 @@ 1.111 float x_resolution, y_resolution; 1.112 float dest_x_resolution, dest_y_resolution; 1.113 1.114 - int width_points, height_points; /* really 1/72 inch units rather than 1.115 - points */ 1.116 + double width_points, height_points; /* really 1/72 inch units rather than 1.117 + points */ 1.118 1.119 Rect rect; 1.120 Bitmap *bitmap; 1.121 1.122 int row; 1.123 1.124 - panda_page *page; 1.125 - 1.126 - int tiff_temp_fd; 1.127 - char tiff_temp_fn [] = "/var/tmp/t2p-XXXXXX\0"; 1.128 - TIFF *tiff_temp; 1.129 - 1.130 - char pagesize [26]; /* Needs to hold two ints of four characters (0..3420), 1.131 - two zeros, three spaces, two brackets, and a NULL. 1.132 - Added an extra ten characters just in case. */ 1.133 + pdf_page_handle page; 1.134 1.135 if (! TIFFSetDirectory (in, image - 1)) 1.136 { 1.137 @@ -406,7 +401,7 @@ 1.138 dest_image_length = image_width; 1.139 dest_x_resolution = y_resolution; 1.140 dest_y_resolution = x_resolution; 1.141 - SWAP (int, width_points, height_points); 1.142 + SWAP (double, width_points, height_points); /* $$$ not yet set!!! */ 1.143 } 1.144 else 1.145 { 1.146 @@ -453,80 +448,32 @@ 1.147 rotate_bitmap (bitmap, 1.148 input_attributes); 1.149 1.150 - tiff_temp_fd = mkstemp (tiff_temp_fn); 1.151 - if (tiff_temp_fd < 0) 1.152 - { 1.153 - fprintf (stderr, "can't create temporary TIFF file\n"); 1.154 - goto fail; 1.155 - } 1.156 - 1.157 - tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); 1.158 - if (! out) 1.159 - { 1.160 - fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); 1.161 - goto fail; 1.162 - } 1.163 - 1.164 - TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, rect_height (& bitmap->rect)); 1.165 - TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, rect_width (& bitmap->rect)); 1.166 - TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); 1.167 - 1.168 - TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, rect_height (& bitmap->rect)); 1.169 - 1.170 - TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 1.171 - TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, dest_x_resolution); 1.172 - TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, dest_y_resolution); 1.173 - 1.174 - TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel); 1.175 - TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 1.176 - TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 1.177 - TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 1.178 - 1.179 #ifdef TIFF_REVERSE_BITS 1.180 reverse_bits ((uint8_t *) bitmap->bits, 1.181 image_length * bitmap->row_words * sizeof (word_type)); 1.182 #endif /* TIFF_REVERSE_BITS */ 1.183 1.184 - for (row = 0; row < rect_height (& bitmap->rect); row++) 1.185 - if (1 != TIFFWriteScanline (tiff_temp, 1.186 - bitmap->bits + row * bitmap->row_words, 1.187 - row, 1.188 - 0)) 1.189 - { 1.190 - fprintf (stderr, "can't write TIFF scanline\n"); 1.191 - goto fail; 1.192 - } 1.193 - 1.194 - TIFFClose (tiff_temp); 1.195 - 1.196 width_points = (rect_width (& bitmap->rect) / dest_x_resolution) * POINTS_PER_INCH; 1.197 height_points = (rect_height (& bitmap->rect) / dest_y_resolution) * POINTS_PER_INCH; 1.198 1.199 - free_bitmap (bitmap); 1.200 - 1.201 if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) 1.202 { 1.203 fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); 1.204 goto fail; 1.205 } 1.206 1.207 - sprintf (pagesize, "[0 0 %d %d]", width_points, height_points); 1.208 + page = pdf_new_page (out->pdf, width_points, height_points); 1.209 1.210 - page = panda_newpage (out->pdf, pagesize); 1.211 - panda_imagebox (out->pdf, 1.212 - page, 1.213 - 0, /* top */ 1.214 - 0, /* left */ 1.215 - height_points, /* bottom */ 1.216 - width_points, /* right */ 1.217 - tiff_temp_fn, 1.218 - panda_image_tiff); 1.219 + pdf_write_g4_fax_image (page, 1.220 + bitmap, 1.221 + 0, /* ImageMask */ 1.222 + 0); /* BlackIs1 */ 1.223 + 1.224 + free_bitmap (bitmap); 1.225 1.226 result = 1; 1.227 1.228 fail: 1.229 - if (tiff_temp_fd) 1.230 - unlink (tiff_temp_fn); 1.231 return (result); 1.232 } 1.233 1.234 @@ -548,6 +495,7 @@ 1.235 fatal (3, "error opening input file \"%s\"\n", in_fn [i]); 1.236 for (ip = 1;; ip++) 1.237 { 1.238 + fprintf (stderr, "processing page %d of file \"%s\"\r", ip, in_fn [i]); 1.239 if (! process_page (ip, input_attributes, NULL)) 1.240 fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]); 1.241 if (last_tiff_page ()) 1.242 @@ -576,12 +524,13 @@ 1.243 { 1.244 char *spec_fn = NULL; 1.245 char *out_fn = NULL; 1.246 + char *bookmark_fmt = NULL; 1.247 int inf_count = 0; 1.248 char *in_fn [MAX_INPUT_FILES]; 1.249 1.250 progname = argv [0]; 1.251 1.252 - panda_init (); 1.253 + pdf_init (); 1.254 1.255 while (--argc) 1.256 { 1.257 @@ -611,6 +560,17 @@ 1.258 else 1.259 fatal (1, "missing filename after \"-s\" option\n"); 1.260 } 1.261 + else if (strcmp (argv [1], "-b") == 0) 1.262 + { 1.263 + if (argc) 1.264 + { 1.265 + argc--; 1.266 + argv++; 1.267 + bookmark_fmt = argv [1]; 1.268 + } 1.269 + else 1.270 + fatal (1, "missing format string after \"-b\" option\n"); 1.271 + } 1.272 else 1.273 fatal (1, "unrecognized option \"%s\"\n", argv [1]); 1.274 }