1 /* 2 * tumble: build a PDF file from image files 3 * 4 * PDF routines 5 * Copyright 2001, 2002, 2003, 2017 Eric Smith <spacewar@gmail.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. Note that permission is 10 * not granted to redistribute this program under the terms of any 11 * other version of the General Public License. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 21 * 22 * 2007-06-28 [JDB] Increase page limits from 45" to 200" square. 23 * 2010-09-02 [JDB] Added support for min-is-black TIFF images. 24 * 2014-02-18 [JDB] Added PDF_PRODUCER definition. 25 */ 26 27 #if !defined(SEMANTICS) 28 typedef struct 29 { 30 int first; 31 int last; 32 } range_t; 33 34 typedef struct 35 { 36 int red; 37 int green; 38 int blue; 39 } rgb_t; 40 41 typedef struct 42 { 43 range_t red; 44 range_t green; 45 range_t blue; 46 } rgb_range_t; 47 48 typedef struct 49 { 50 rgb_t black_map; 51 rgb_t white_map; 52 } colormap_t; 53 #endif 54 55 /* Acrobat default units aren't really points, but they're close. */ 56 #define POINTS_PER_INCH 72.0 57 58 /* Page size for Acrobat Reader 4.0 and later is 200 x 200 inches. 59 Old limit of 45 inches applied to Acrobat Reader 3.x only. */ 60 #define PAGE_MAX_INCHES 200 61 #define PAGE_MAX_POINTS (PAGE_MAX_INCHES * POINTS_PER_INCH) 62 63 64 typedef struct pdf_file *pdf_file_handle; 65 66 typedef struct pdf_page *pdf_page_handle; 67 68 typedef struct pdf_bookmark *pdf_bookmark_handle; 69 70 71 #define PDF_PAGE_MODE_USE_NONE 0 72 #define PDF_PAGE_MODE_USE_OUTLINES 1 /* if no outlines, will use NONE */ 73 #define PDF_PAGE_MODE_USE_THUMBS 2 /* not yet implemented */ 74 75 76 void pdf_init (void); 77 78 pdf_file_handle pdf_create (char *filename); 79 80 void pdf_close (pdf_file_handle pdf_file, int page_mode); 81 82 #define AS_STR(S) #S 83 #define TO_STR(S) AS_STR(S) 84 85 #define PDF_PRODUCER "tumble " TO_STR(TUMBLE_VERSION) \ 86 " by Eric Smith (modified by J. David Bryan)" 87 88 void pdf_set_author (pdf_file_handle pdf_file, char *author); 89 void pdf_set_creator (pdf_file_handle pdf_file, char *creator); 90 void pdf_set_producer (pdf_file_handle pdf_file, char *producer); 91 void pdf_set_title (pdf_file_handle pdf_file, char *title); 92 void pdf_set_subject (pdf_file_handle pdf_file, char *subject); 93 void pdf_set_keywords (pdf_file_handle pdf_file, char *keywords); 94 95 96 /* width and height in units of 1/72 inch */ 97 pdf_page_handle pdf_new_page (pdf_file_handle pdf_file, 98 double width, 99 double height); 100 101 void pdf_close_page (pdf_page_handle pdf_page); 102 103 104 void pdf_write_text (pdf_page_handle pdf_page); 105 106 107 /* The length of the data must be Rows * rowbytes. 108 Note that rowbytes must be at least (Columns+7)/8, but may be arbitrarily 109 large. */ 110 void pdf_write_g4_fax_image (pdf_page_handle pdf_page, 111 double x, 112 double y, 113 double width, 114 double height, 115 bool negative, 116 Bitmap *bitmap, 117 colormap_t *colormap, 118 rgb_range_t *transparency); 119 120 121 void pdf_write_jpeg_image (pdf_page_handle pdf_page, 122 double x, 123 double y, 124 double width, 125 double height, 126 bool color, 127 uint32_t width_samples, 128 uint32_t height_samples, 129 rgb_range_t *transparency, 130 FILE *f); 131 132 133 void pdf_write_png_image (pdf_page_handle pdf_page, 134 double x, 135 double y, 136 double width, 137 double height, 138 int color, 139 char *pal, 140 int palent, 141 int bpp, 142 uint32_t width_samples, 143 uint32_t height_samples, 144 rgb_range_t *transparency, 145 FILE *f); 146 147 148 void pdf_set_page_number (pdf_page_handle pdf_page, char *page_number); 149 150 /* Create a new bookmark, under the specified parent, or at the top 151 level if parent is NULL. */ 152 pdf_bookmark_handle pdf_new_bookmark (pdf_bookmark_handle parent, 153 char *title, 154 bool open, 155 pdf_page_handle pdf_page); 156 157 158 void pdf_new_page_label (pdf_file_handle pdf_file, 159 int page_index, 160 int base, 161 int count, 162 char style, 163 char *prefix); 164