-
Notifications
You must be signed in to change notification settings - Fork 7
/
tumble_blank.c
146 lines (120 loc) · 3.59 KB
/
tumble_blank.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* tumble: build a PDF file from image files
*
* $Id: tumble_blank.c ... Exp $
* Copyright ...
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. Note that permission is
* not granted to redistribute this program under the terms of any
* other version of the General Public License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
*
* 2007-05-07 [JDB] New file to add support for blank pages.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "semantics.h"
#include "tumble.h"
#include "bitblt.h"
#include "pdf.h"
#include "pdf_util.h"
#include "pdf_prim.h"
#include "pdf_private.h"
#include "tumble_input.h"
struct pdf_blank_page
{
double width;
double height;
double x;
double y;
double red;
double green;
double blue;
};
static bool match_blank_suffix (char *suffix)
{
return false;
}
static bool close_blank_input_file (void)
{
return true;
}
static bool open_blank_input_file (FILE *f, char *name)
{
return true;
}
static bool last_blank_input_page (void)
{
return true;
}
static bool get_blank_image_info (int image,
input_attributes_t input_attributes,
image_info_t *image_info)
{
if (input_attributes.has_page_size)
{
image_info->width_points = input_attributes.page_size.width * POINTS_PER_INCH;
image_info->height_points = input_attributes.page_size.height * POINTS_PER_INCH;
return true;
}
else
return false;
}
static void pdf_write_blank_content_callback (pdf_file_handle pdf_file,
pdf_obj_handle stream,
void *app_data)
{
struct pdf_blank_page *page = app_data;
pdf_stream_printf (pdf_file, stream,
"%g %g %g rg\r\n%g %g %g %g re\r\nf\r\n",
page->red, page->green, page->blue,
page->x, page->y,
page->width, page->height);
}
static bool process_blank_image (int image, /* range 1 .. n */
input_attributes_t input_attributes,
image_info_t *image_info,
pdf_page_handle pdf_page,
output_attributes_t output_attributes)
{
struct pdf_blank_page *page;
/* If colormap set, use "white" color and draw rectangle to cover page. */
if (output_attributes.colormap)
{
page = pdf_calloc (1, sizeof (struct pdf_blank_page));
page->width = image_info->width_points;
page->height = image_info->height_points;
page->x = 0;
page->y = 0;
page->red = (double) output_attributes.colormap->white_map.red / 255.0;
page->green = (double) output_attributes.colormap->white_map.green / 255.0;
page->blue = (double) output_attributes.colormap->white_map.blue / 255.0;
pdf_obj_handle content_stream = pdf_new_ind_ref(pdf_page->pdf_file,
pdf_new_stream (pdf_page->pdf_file,
pdf_new_obj (PT_DICTIONARY),
& pdf_write_blank_content_callback,
page));
pdf_page_add_content_stream(pdf_page, content_stream);
}
return true;
}
input_handler_t blank_handler =
{
match_blank_suffix,
open_blank_input_file,
close_blank_input_file,
last_blank_input_page,
get_blank_image_info,
process_blank_image
};