1 /*
2 * tumble: build a PDF file from image files
3 *
4 * $Id: tumble_blank.c ... Exp $
5 * Copyright ...
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-05-07 [JDB] New file to add support for blank pages.
23 */
24
25
26 #include <stdbool.h>
27 #include <stdint.h>
28 #include <stdio.h>
29
30
31 #include "semantics.h"
32 #include "tumble.h"
33 #include "bitblt.h"
34 #include "pdf.h"
35 #include "pdf_util.h"
36 #include "pdf_prim.h"
37 #include "pdf_private.h"
38 #include "tumble_input.h"
39
40
41 struct pdf_blank_page
42 {
43 double width;
44 double height;
45 double x;
46 double y;
47 double red;
48 double green;
49 double blue;
50 };
51
52
match_blank_suffix(char * suffix)53 static bool match_blank_suffix (char *suffix)
54 {
55 return (0);
56 }
57
close_blank_input_file(void)58 static bool close_blank_input_file (void)
59 {
60 return (1);
61 }
62
63
open_blank_input_file(FILE * f,char * name)64 static bool open_blank_input_file (FILE *f, char *name)
65 {
66 return (1);
67 }
68
69
last_blank_input_page(void)70 static bool last_blank_input_page (void)
71 {
72 return (1);
73 }
74
75
get_blank_image_info(int image,input_attributes_t input_attributes,image_info_t * image_info)76 static bool get_blank_image_info (int image,
77 input_attributes_t input_attributes,
78 image_info_t *image_info)
79 {
80 if (input_attributes.has_page_size)
81 {
82 image_info->width_points = input_attributes.page_size.width * POINTS_PER_INCH;
83 image_info->height_points = input_attributes.page_size.height * POINTS_PER_INCH;
84 return (1);
85 }
86 else
87 return (0);
88 }
89
90
pdf_write_blank_content_callback(pdf_file_handle pdf_file,struct pdf_obj * stream,void * app_data)91 static void pdf_write_blank_content_callback (pdf_file_handle pdf_file,
92 struct pdf_obj *stream,
93 void *app_data)
94 {
95 struct pdf_blank_page *page = app_data;
96
97 pdf_stream_printf (pdf_file, stream,
98 "%g %g %g rg\r\n%g %g %g %g re\r\nf\r\n",
99 page->red, page->green, page->blue,
100 page->x, page->y,
101 page->width, page->height);
102 }
103
104
process_blank_image(int image,input_attributes_t input_attributes,image_info_t * image_info,pdf_page_handle pdf_page,position_t position)105 static bool process_blank_image (int image, /* range 1 .. n */
106 input_attributes_t input_attributes,
107 image_info_t *image_info,
108 pdf_page_handle pdf_page,
109 position_t position)
110 {
111 struct pdf_blank_page *page;
112 struct pdf_obj *content_stream;
113
114 /* If colormap set, use "white" color and draw rectangle to cover page. */
115
116 if (input_attributes.colormap)
117 {
118 page = pdf_calloc (1, sizeof (struct pdf_blank_page));
119
120 page->width = image_info->width_points;
121 page->height = image_info->height_points;
122 page->x = 0;
123 page->y = 0;
124 page->red = (double) input_attributes.colormap->white_map.red / 255.0;
125 page->green = (double) input_attributes.colormap->white_map.green / 255.0;
126 page->blue = (double) input_attributes.colormap->white_map.blue / 255.0;
127
128 content_stream = pdf_new_ind_ref (pdf_page->pdf_file,
129 pdf_new_stream (pdf_page->pdf_file,
130 pdf_new_obj (PT_DICTIONARY),
131 & pdf_write_blank_content_callback,
132 page));
133
134 pdf_set_dict_entry (pdf_page->page_dict, "Contents", content_stream);
135 pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
136 }
137 return (1);
138 }
139
140
141 input_handler_t blank_handler =
142 {
143 match_blank_suffix,
144 open_blank_input_file,
145 close_blank_input_file,
146 last_blank_input_page,
147 get_blank_image_info,
148 process_blank_image
149 };
150