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