Added imagemask support. Style changes.
This commit is contained in:
parent
d452544805
commit
2337b1def4
92
parser.y
92
parser.y
@ -69,6 +69,7 @@
|
||||
%token FILE_KEYWORD
|
||||
%token IMAGE
|
||||
%token IMAGES
|
||||
%token IMAGEMASK
|
||||
%token ROTATE
|
||||
%token CROP
|
||||
%token SIZE
|
||||
@ -116,7 +117,8 @@ statements:
|
||||
| statements statement ;
|
||||
|
||||
statement:
|
||||
input_statement
|
||||
/* empty: null statement */
|
||||
| input_statement
|
||||
| output_statement ;
|
||||
|
||||
|
||||
@ -130,16 +132,16 @@ image_ranges:
|
||||
|
||||
|
||||
input_file_clause:
|
||||
FILE_KEYWORD STRING ';' { input_set_file ($2); } ;
|
||||
FILE_KEYWORD STRING { input_set_file ($2); } ;
|
||||
|
||||
image_clause:
|
||||
IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
|
||||
IMAGE INTEGER { range_t range = { $2, $2 }; input_images (range); } ;
|
||||
|
||||
images_clause:
|
||||
IMAGES image_ranges ';' ;
|
||||
IMAGES image_ranges ;
|
||||
|
||||
rotate_clause:
|
||||
ROTATE INTEGER ';' { input_set_rotation ($2); } ;
|
||||
ROTATE INTEGER { input_set_rotation ($2); } ;
|
||||
|
||||
unit:
|
||||
/* empty */ /* default to INCH */ { $$ = 1.0; }
|
||||
@ -150,10 +152,10 @@ length:
|
||||
FLOAT unit { $$ = $1 * $2; } ;
|
||||
|
||||
crop_clause:
|
||||
CROP PAGE_SIZE ';'
|
||||
| CROP PAGE_SIZE orientation ';'
|
||||
| CROP length ',' length ';'
|
||||
| CROP length ',' length ',' length ',' length ';' ;
|
||||
CROP PAGE_SIZE
|
||||
| CROP PAGE_SIZE orientation
|
||||
| CROP length ',' length
|
||||
| CROP length ',' length ',' length ',' length ;
|
||||
|
||||
orientation:
|
||||
PORTRAIT { $$ = 0; }
|
||||
@ -172,7 +174,7 @@ page_size:
|
||||
| length ',' length { $$.width = $1; $$.height = $3; } ;
|
||||
|
||||
size_clause:
|
||||
SIZE page_size ';' { input_set_page_size ($2); } ;
|
||||
SIZE page_size { input_set_page_size ($2); } ;
|
||||
|
||||
resolution_clause:
|
||||
RESOLUTION FLOAT unit ;
|
||||
@ -188,36 +190,40 @@ color_range:
|
||||
| gray_range;
|
||||
|
||||
transparency_clause:
|
||||
TRANSPARENT color_range ';' { input_set_transparency ($2); } ;
|
||||
TRANSPARENT color_range { input_set_transparency ($2); } ;
|
||||
|
||||
modifier_clause:
|
||||
rotate_clause | crop_clause | size_clause | resolution_clause | transparency_clause;
|
||||
rotate_clause ';'
|
||||
| crop_clause ';'
|
||||
| size_clause ';'
|
||||
| resolution_clause ';'
|
||||
| transparency_clause ';' ;
|
||||
|
||||
modifier_clauses:
|
||||
modifier_clause
|
||||
| modifier_clauses modifier_clause;
|
||||
| modifier_clauses modifier_clause ;
|
||||
|
||||
modifier_clause_list:
|
||||
'{' modifier_clauses '}' ;
|
||||
|
||||
part_clause:
|
||||
ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
|
||||
modifier_clause_list ';'
|
||||
modifier_clause_list
|
||||
{ input_set_modifier_context (INPUT_MODIFIER_ALL); }
|
||||
| EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
|
||||
modifier_clause_list ';'
|
||||
modifier_clause_list
|
||||
{ input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
|
||||
|
||||
blank_page_clause:
|
||||
BLANK { input_set_file (NULL); } size_clause ;
|
||||
BLANK { input_set_file (NULL); } size_clause;
|
||||
|
||||
input_clause:
|
||||
input_file_clause
|
||||
| image_clause
|
||||
| images_clause
|
||||
| part_clause
|
||||
| modifier_clause
|
||||
| blank_page_clause
|
||||
input_file_clause ';'
|
||||
| image_clause ';'
|
||||
| images_clause ';'
|
||||
| part_clause ';'
|
||||
| modifier_clauses ';'
|
||||
| blank_page_clause ';'
|
||||
| input_clause_list ;
|
||||
|
||||
input_clauses:
|
||||
@ -229,7 +235,7 @@ input_clause_list:
|
||||
input_clauses '}' { input_pop_context (); } ;
|
||||
|
||||
input_statement:
|
||||
INPUT input_clauses ;
|
||||
INPUT '{' input_clauses '}' ;
|
||||
|
||||
pdf_file_attribute:
|
||||
AUTHOR STRING { output_set_author ($2); }
|
||||
@ -248,34 +254,37 @@ pdf_file_attributes:
|
||||
|
||||
output_file_clause:
|
||||
FILE_KEYWORD STRING { output_set_file ($2); }
|
||||
pdf_file_attributes ';' ;
|
||||
pdf_file_attributes ;
|
||||
|
||||
label_clause:
|
||||
LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
|
||||
| LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
|
||||
| LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
|
||||
| LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
|
||||
LABEL { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
|
||||
| LABEL STRING { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
|
||||
| LABEL CHARACTER { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
|
||||
| LABEL STRING ',' CHARACTER { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
|
||||
|
||||
overlay_clause_list:
|
||||
/* empty */
|
||||
| '{' overlay_clauses '}' ;
|
||||
|
||||
overlay_clauses:
|
||||
overlay_clause
|
||||
| overlay_clauses overlay_clause ;
|
||||
overlay_clause ';'
|
||||
| overlay_clauses overlay_clause ';' ;
|
||||
|
||||
overlay_clause:
|
||||
OVERLAY length ',' length ';' { overlay_t overlay = { $2, $4 }; output_overlay (overlay); } ;
|
||||
OVERLAY length ',' length { overlay_t overlay = { .imagemask = false,
|
||||
.position.x = $2,
|
||||
.position.y = $4 }; output_overlay (overlay); }
|
||||
| IMAGEMASK rgb { output_imagemask($2); } ;
|
||||
|
||||
page_ranges:
|
||||
range { output_pages ($1); }
|
||||
| page_ranges ',' range { output_pages ($3); } ;
|
||||
|
||||
page_clause:
|
||||
PAGE INTEGER { range_t range = { $2, $2 }; output_pages (range); } overlay_clause_list ';' ;
|
||||
PAGE INTEGER { range_t range = { $2, $2 }; output_pages (range); } overlay_clause_list ;
|
||||
|
||||
pages_clause:
|
||||
PAGES page_ranges ';' ;
|
||||
PAGES page_ranges ;
|
||||
|
||||
bookmark_name:
|
||||
STRING { output_set_bookmark ($1); } ;
|
||||
@ -287,20 +296,21 @@ bookmark_name_list:
|
||||
bookmark_clause:
|
||||
BOOKMARK { output_push_context (); bookmark_level++; }
|
||||
bookmark_name_list
|
||||
output_clause_list ';' { bookmark_level--; output_pop_context (); } ;
|
||||
output_clause_list { bookmark_level--; output_pop_context (); } ;
|
||||
|
||||
rgb:
|
||||
'(' INTEGER INTEGER INTEGER ')' { $$.red = $2; $$.green = $3; $$.blue = $4; } ;
|
||||
|
||||
colormap_clause:
|
||||
COLORMAP rgb ',' rgb ';' { output_set_colormap ($2, $4); } ;
|
||||
COLORMAP rgb ',' rgb { output_set_colormap ($2, $4); } ;
|
||||
|
||||
output_clause:
|
||||
output_file_clause
|
||||
| colormap_clause
|
||||
| label_clause
|
||||
| page_clause | pages_clause
|
||||
| bookmark_clause
|
||||
output_file_clause ';'
|
||||
| colormap_clause ';'
|
||||
| label_clause ';'
|
||||
| page_clause ';'
|
||||
| pages_clause ';'
|
||||
| bookmark_clause ';'
|
||||
| output_clause_list ;
|
||||
|
||||
output_clauses:
|
||||
@ -312,4 +322,4 @@ output_clause_list:
|
||||
output_clauses '}' { output_pop_context (); } ;
|
||||
|
||||
output_statement:
|
||||
OUTPUT output_clauses ;
|
||||
OUTPUT '{' output_clauses '}' ;
|
||||
|
||||
4
pdf.c
4
pdf.c
@ -76,7 +76,7 @@ pdf_file_handle pdf_create (char *filename)
|
||||
time_t current_time, adjusted_time;
|
||||
struct tm *time_and_date;
|
||||
int gmt_diff;
|
||||
char tm_string[18], gmt_string[24];
|
||||
char tm_string[18], gmt_string[25];
|
||||
const char tm_format[] = "D:%Y%m%d%H%M%S";
|
||||
|
||||
pdf_file = pdf_calloc (1, sizeof (struct pdf_file));
|
||||
@ -240,7 +240,7 @@ pdf_page_handle pdf_new_page (pdf_file_handle pdf_file,
|
||||
|
||||
if (pdf_get_integer (pdf_file->root->count) == 0)
|
||||
{
|
||||
struct pdf_obj *dest_array = pdf_new_obj (PT_ARRAY);
|
||||
pdf_obj_handle dest_array = pdf_new_obj (PT_ARRAY);
|
||||
pdf_add_array_elem (dest_array, page->page_dict);
|
||||
pdf_add_array_elem (dest_array, pdf_new_name ("Fit"));
|
||||
pdf_set_dict_entry (pdf_file->catalog, "OpenAction", dest_array);
|
||||
|
||||
32
pdf.h
32
pdf.h
@ -24,33 +24,10 @@
|
||||
* 2014-02-18 [JDB] Added PDF_PRODUCER definition.
|
||||
*/
|
||||
|
||||
#if !defined(SEMANTICS)
|
||||
typedef struct
|
||||
{
|
||||
int first;
|
||||
int last;
|
||||
} range_t;
|
||||
#ifndef PDF_H
|
||||
#define PDF_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
} rgb_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
range_t red;
|
||||
range_t green;
|
||||
range_t blue;
|
||||
} rgb_range_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
rgb_t black_map;
|
||||
rgb_t white_map;
|
||||
} colormap_t;
|
||||
#endif
|
||||
#include "semantics.h"
|
||||
|
||||
/* Acrobat default units aren't really points, but they're close. */
|
||||
#define POINTS_PER_INCH 72.0
|
||||
@ -114,6 +91,7 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page,
|
||||
double height,
|
||||
bool negative,
|
||||
Bitmap *bitmap,
|
||||
overlay_t *overlay,
|
||||
colormap_t *colormap,
|
||||
rgb_range_t *transparency);
|
||||
|
||||
@ -161,3 +139,5 @@ void pdf_new_page_label (pdf_file_handle pdf_file,
|
||||
int count,
|
||||
char style,
|
||||
char *prefix);
|
||||
|
||||
#endif // PDF_H
|
||||
|
||||
@ -37,8 +37,8 @@
|
||||
|
||||
struct pdf_bookmark
|
||||
{
|
||||
struct pdf_obj *dict; /* indirect reference */
|
||||
struct pdf_obj *count;
|
||||
pdf_obj_handle dict; /* indirect reference */
|
||||
pdf_obj_handle count;
|
||||
bool open;
|
||||
|
||||
struct pdf_bookmark *first;
|
||||
@ -83,7 +83,7 @@ pdf_bookmark_handle pdf_new_bookmark (pdf_bookmark_handle parent,
|
||||
struct pdf_bookmark *root;
|
||||
struct pdf_bookmark *entry;
|
||||
|
||||
struct pdf_obj *dest_array;
|
||||
pdf_obj_handle dest_array;
|
||||
|
||||
root = pdf_file->outline_root;
|
||||
if (! root)
|
||||
|
||||
69
pdf_g4.c
69
pdf_g4.c
@ -49,11 +49,13 @@ struct pdf_g4_image
|
||||
unsigned long Rows;
|
||||
Bitmap *bitmap;
|
||||
char XObject_name [4];
|
||||
bool imagemask;
|
||||
double fg_red, fg_green, fg_blue; // only if imagemask
|
||||
};
|
||||
|
||||
|
||||
static void pdf_write_g4_content_callback (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data)
|
||||
{
|
||||
struct pdf_g4_image *image = app_data;
|
||||
@ -63,13 +65,19 @@ static void pdf_write_g4_content_callback (pdf_file_handle pdf_file,
|
||||
image->width, image->height,
|
||||
image->x, image->y);
|
||||
|
||||
pdf_write_name (pdf_file, image->XObject_name);
|
||||
pdf_stream_printf (pdf_file, stream, "Do Q\r\n");
|
||||
if (image->imagemask)
|
||||
{
|
||||
// set nonstroking color in DeviceRGB color space
|
||||
pdf_stream_printf(pdf_file, stream, "%g %g %g rg ", image->fg_red, image->fg_green, image->fg_blue);
|
||||
}
|
||||
|
||||
pdf_write_name(pdf_file, image->XObject_name);
|
||||
pdf_stream_printf(pdf_file, stream, "Do Q\r\n");
|
||||
}
|
||||
|
||||
|
||||
static void pdf_write_g4_fax_image_callback (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data)
|
||||
{
|
||||
struct pdf_g4_image *image = app_data;
|
||||
@ -85,26 +93,27 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page,
|
||||
double height,
|
||||
bool negative,
|
||||
Bitmap *bitmap,
|
||||
overlay_t *overlay,
|
||||
colormap_t *colormap,
|
||||
rgb_range_t *transparency)
|
||||
{
|
||||
struct pdf_g4_image *image;
|
||||
|
||||
struct pdf_obj *stream;
|
||||
struct pdf_obj *stream_dict;
|
||||
struct pdf_obj *decode_parms;
|
||||
|
||||
struct pdf_obj *content_stream;
|
||||
|
||||
struct pdf_obj *contents;
|
||||
struct pdf_obj *mask;
|
||||
pdf_obj_handle stream;
|
||||
pdf_obj_handle stream_dict;
|
||||
pdf_obj_handle decode_parms;
|
||||
|
||||
typedef char MAP_STRING[6];
|
||||
|
||||
MAP_STRING color_index;
|
||||
static MAP_STRING last_color_index;
|
||||
static struct pdf_obj *color_space;
|
||||
static pdf_obj_handle color_space;
|
||||
|
||||
if (transparency && (overlay && overlay->imagemask))
|
||||
{
|
||||
fprintf(stderr, "Can't use transparency or color map with an image mask.\n");
|
||||
exit(2); // XXX should be a failure return value
|
||||
}
|
||||
|
||||
pdf_add_array_elem_unique (pdf_page->procset, pdf_new_name ("ImageB"));
|
||||
|
||||
@ -119,6 +128,14 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page,
|
||||
image->Columns = bitmap->rect.max.x - bitmap->rect.min.x;
|
||||
image->Rows = bitmap->rect.max.y - bitmap->rect.min.y;
|
||||
|
||||
if (overlay && overlay->imagemask)
|
||||
{
|
||||
image->imagemask = true;
|
||||
image->fg_red = overlay->foreground.red / 255.0;
|
||||
image->fg_green = overlay->foreground.green / 255.0;
|
||||
image->fg_blue = overlay->foreground.blue / 255.0;
|
||||
}
|
||||
|
||||
stream_dict = pdf_new_obj (PT_DICTIONARY);
|
||||
|
||||
stream = pdf_new_ind_ref (pdf_page->pdf_file,
|
||||
@ -132,13 +149,21 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page,
|
||||
|
||||
pdf_set_dict_entry (stream_dict, "Type", pdf_new_name ("XObject"));
|
||||
pdf_set_dict_entry (stream_dict, "Subtype", pdf_new_name ("Image"));
|
||||
pdf_set_dict_entry (stream_dict, "Name", pdf_new_name (& image->XObject_name [0]));
|
||||
// Name entry was required in PDF 1.0, obsolete in subsequent versions
|
||||
//pdf_set_dict_entry (stream_dict, "Name", pdf_new_name (& image->XObject_name [0]));
|
||||
pdf_set_dict_entry (stream_dict, "Width", pdf_new_integer (image->Columns));
|
||||
pdf_set_dict_entry (stream_dict, "Height", pdf_new_integer (image->Rows));
|
||||
pdf_set_dict_entry (stream_dict, "BitsPerComponent", pdf_new_integer (1));
|
||||
|
||||
if (overlay && overlay->imagemask)
|
||||
{
|
||||
pdf_set_dict_entry (stream_dict, "ImageMask", pdf_new_bool (true));
|
||||
}
|
||||
|
||||
if (transparency)
|
||||
{
|
||||
pdf_obj_handle mask;
|
||||
|
||||
mask = pdf_new_obj (PT_ARRAY);
|
||||
|
||||
pdf_add_array_elem (mask, pdf_new_integer (transparency->red.first));
|
||||
@ -147,6 +172,8 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page,
|
||||
pdf_set_dict_entry (stream_dict, "Mask", mask);
|
||||
}
|
||||
|
||||
if (! (overlay && overlay->imagemask))
|
||||
{
|
||||
if (colormap)
|
||||
{
|
||||
color_index [0] = (char) colormap->black_map.red;
|
||||
@ -174,6 +201,7 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page,
|
||||
}
|
||||
else
|
||||
pdf_set_dict_entry (stream_dict, "ColorSpace", pdf_new_name ("DeviceGray"));
|
||||
}
|
||||
|
||||
decode_parms = pdf_new_obj (PT_DICTIONARY);
|
||||
|
||||
@ -200,20 +228,11 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page,
|
||||
get the actual data */
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, stream);
|
||||
|
||||
content_stream = pdf_new_ind_ref (pdf_page->pdf_file,
|
||||
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_g4_content_callback,
|
||||
image));
|
||||
|
||||
contents = pdf_get_dict_entry (pdf_page->page_dict, "Contents");
|
||||
|
||||
if (! contents)
|
||||
contents = pdf_new_obj (PT_ARRAY);
|
||||
|
||||
pdf_add_array_elem (contents, content_stream);
|
||||
pdf_set_dict_entry (pdf_page->page_dict, "Contents", contents);
|
||||
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
|
||||
pdf_page_add_content_stream(pdf_page, content_stream);
|
||||
}
|
||||
|
||||
|
||||
25
pdf_jpeg.c
25
pdf_jpeg.c
@ -51,7 +51,7 @@ struct pdf_jpeg_image
|
||||
|
||||
|
||||
static void pdf_write_jpeg_content_callback (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data)
|
||||
{
|
||||
struct pdf_jpeg_image *image = app_data;
|
||||
@ -68,7 +68,7 @@ static void pdf_write_jpeg_content_callback (pdf_file_handle pdf_file,
|
||||
#define JPEG_BUFFER_SIZE 8192
|
||||
|
||||
static void pdf_write_jpeg_image_callback (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data)
|
||||
{
|
||||
struct pdf_jpeg_image *image = app_data;
|
||||
@ -109,13 +109,10 @@ void pdf_write_jpeg_image (pdf_page_handle pdf_page,
|
||||
{
|
||||
struct pdf_jpeg_image *image;
|
||||
|
||||
struct pdf_obj *stream;
|
||||
struct pdf_obj *stream_dict;
|
||||
pdf_obj_handle stream;
|
||||
pdf_obj_handle stream_dict;
|
||||
|
||||
struct pdf_obj *content_stream;
|
||||
|
||||
struct pdf_obj *contents;
|
||||
struct pdf_obj *mask;
|
||||
pdf_obj_handle mask;
|
||||
|
||||
image = pdf_calloc (1, sizeof (struct pdf_jpeg_image));
|
||||
|
||||
@ -174,19 +171,11 @@ void pdf_write_jpeg_image (pdf_page_handle pdf_page,
|
||||
get the actual data */
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, stream);
|
||||
|
||||
content_stream = pdf_new_ind_ref (pdf_page->pdf_file,
|
||||
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_jpeg_content_callback,
|
||||
image));
|
||||
|
||||
contents = pdf_get_dict_entry (pdf_page->page_dict, "Contents");
|
||||
|
||||
if (! contents)
|
||||
contents = pdf_new_obj (PT_ARRAY);
|
||||
|
||||
pdf_add_array_elem (contents, content_stream);
|
||||
pdf_set_dict_entry (pdf_page->page_dict, "Contents", contents);
|
||||
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
|
||||
pdf_page_add_content_stream(pdf_page, content_stream);
|
||||
}
|
||||
|
||||
@ -107,10 +107,10 @@ static void pdf_split_name_tree_node (struct pdf_name_tree *tree,
|
||||
j * sizeof (struct pdf_name_tree_node *));
|
||||
memcpy (& new_node->keys [0],
|
||||
& node->keys [i],
|
||||
j * sizeof (struct pdf_obj *));
|
||||
j * sizeof (pdf_obj_handle ));
|
||||
memcpy (& new_node->values [0],
|
||||
& node->values [i],
|
||||
j * sizeof (struct pdf_obj *));
|
||||
j * sizeof (pdf_obj_handle ));
|
||||
|
||||
node->count = i;
|
||||
new_node->count = j;
|
||||
@ -163,8 +163,8 @@ static void pdf_split_name_tree_node (struct pdf_name_tree *tree,
|
||||
|
||||
|
||||
static void pdf_add_tree_element (struct pdf_name_tree *tree,
|
||||
struct pdf_obj *key,
|
||||
struct pdf_obj *val)
|
||||
pdf_obj_handle key,
|
||||
pdf_obj_handle val)
|
||||
{
|
||||
struct pdf_name_tree_node *node;
|
||||
int i;
|
||||
@ -197,10 +197,10 @@ static void pdf_add_tree_element (struct pdf_name_tree *tree,
|
||||
{
|
||||
memmove (& node->keys [i+1],
|
||||
& node->keys [i],
|
||||
(node->count - i) * sizeof (struct pdf_obj *));
|
||||
(node->count - i) * sizeof (pdf_obj_handle ));
|
||||
memmove (& node->values [i+1],
|
||||
& node->values [i],
|
||||
(node->count - i) * sizeof (struct pdf_obj *));
|
||||
(node->count - i) * sizeof (pdf_obj_handle ));
|
||||
}
|
||||
|
||||
node->keys [i] = key;
|
||||
@ -232,18 +232,18 @@ static void pdf_add_tree_element (struct pdf_name_tree *tree,
|
||||
|
||||
void pdf_add_name_tree_element (struct pdf_name_tree *tree,
|
||||
char *key,
|
||||
struct pdf_obj *val)
|
||||
pdf_obj_handle val)
|
||||
{
|
||||
struct pdf_obj *key_obj = pdf_new_string (key);
|
||||
pdf_obj_handle key_obj = pdf_new_string (key);
|
||||
pdf_add_tree_element (tree, key_obj, val);
|
||||
}
|
||||
|
||||
|
||||
void pdf_add_number_tree_element (struct pdf_name_tree *tree,
|
||||
long key,
|
||||
struct pdf_obj *val)
|
||||
pdf_obj_handle val)
|
||||
{
|
||||
struct pdf_obj *key_obj = pdf_new_integer (key);
|
||||
pdf_obj_handle key_obj = pdf_new_integer (key);
|
||||
pdf_add_tree_element (tree, key_obj, val);
|
||||
}
|
||||
|
||||
@ -258,7 +258,7 @@ static void pdf_finalize_name_tree_node (struct pdf_name_tree *tree,
|
||||
if (node->leaf)
|
||||
{
|
||||
/* write Names or Nums array */
|
||||
struct pdf_obj *names = pdf_new_obj (PT_ARRAY);
|
||||
pdf_obj_handle names = pdf_new_obj (PT_ARRAY);
|
||||
for (i = 0; i < node->count; i++)
|
||||
{
|
||||
pdf_add_array_elem (names, node->keys [i]);
|
||||
@ -272,7 +272,7 @@ static void pdf_finalize_name_tree_node (struct pdf_name_tree *tree,
|
||||
{
|
||||
/* finalize the children first so that their dict ind ref is
|
||||
available */
|
||||
struct pdf_obj *kids;
|
||||
pdf_obj_handle kids;
|
||||
|
||||
for (i = 0; i < node->count; i++)
|
||||
pdf_finalize_name_tree_node (tree, node->kids [i]);
|
||||
@ -287,7 +287,7 @@ static void pdf_finalize_name_tree_node (struct pdf_name_tree *tree,
|
||||
if (node->parent)
|
||||
{
|
||||
/* write Limits array */
|
||||
struct pdf_obj *limits = pdf_new_obj (PT_ARRAY);
|
||||
pdf_obj_handle limits = pdf_new_obj (PT_ARRAY);
|
||||
pdf_add_array_elem (limits, node->min_key);
|
||||
pdf_add_array_elem (limits, node->max_key);
|
||||
pdf_set_dict_entry (node->dict, "Limits", limits);
|
||||
|
||||
@ -36,7 +36,7 @@ struct pdf_name_tree
|
||||
|
||||
struct pdf_name_tree_node
|
||||
{
|
||||
struct pdf_obj *dict; /* indirect reference */
|
||||
pdf_obj_handle dict; /* indirect reference */
|
||||
|
||||
struct pdf_name_tree_node *parent; /* NULL for root */
|
||||
bool leaf;
|
||||
@ -46,13 +46,13 @@ struct pdf_name_tree_node
|
||||
|
||||
struct pdf_name_tree_node *kids [MAX_NAME_TREE_NODE_ENTRIES]; /* non-leaf only */
|
||||
|
||||
struct pdf_obj *min_key;
|
||||
struct pdf_obj *max_key;
|
||||
pdf_obj_handle min_key;
|
||||
pdf_obj_handle max_key;
|
||||
|
||||
/* following fields valid in leaf nodes only: */
|
||||
|
||||
struct pdf_obj *keys [MAX_NAME_TREE_NODE_ENTRIES];
|
||||
struct pdf_obj *values [MAX_NAME_TREE_NODE_ENTRIES];
|
||||
pdf_obj_handle keys [MAX_NAME_TREE_NODE_ENTRIES];
|
||||
pdf_obj_handle values [MAX_NAME_TREE_NODE_ENTRIES];
|
||||
};
|
||||
|
||||
|
||||
@ -62,12 +62,12 @@ struct pdf_name_tree *pdf_new_name_tree (pdf_file_handle pdf_file,
|
||||
|
||||
void pdf_add_name_tree_element (struct pdf_name_tree *tree,
|
||||
char *key,
|
||||
struct pdf_obj *val);
|
||||
pdf_obj_handle val);
|
||||
|
||||
|
||||
void pdf_add_number_tree_element (struct pdf_name_tree *tree,
|
||||
long key,
|
||||
struct pdf_obj *val);
|
||||
pdf_obj_handle val);
|
||||
|
||||
|
||||
void pdf_finalize_name_trees (pdf_file_handle pdf_file);
|
||||
|
||||
@ -48,7 +48,7 @@ void pdf_new_page_label (pdf_file_handle pdf_file,
|
||||
char style,
|
||||
char *prefix)
|
||||
{
|
||||
struct pdf_obj *label_dict;
|
||||
pdf_obj_handle label_dict;
|
||||
char style_str [2] = { style, '\0' };
|
||||
|
||||
if (! pdf_file->page_label_tree)
|
||||
|
||||
29
pdf_png.c
29
pdf_png.c
@ -53,7 +53,7 @@ struct pdf_png_image
|
||||
|
||||
|
||||
static void pdf_write_png_content_callback (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data)
|
||||
{
|
||||
struct pdf_png_image *image = app_data;
|
||||
@ -68,7 +68,7 @@ static void pdf_write_png_content_callback (pdf_file_handle pdf_file,
|
||||
|
||||
|
||||
static void pdf_write_png_image_callback (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data)
|
||||
{
|
||||
struct pdf_png_image *image = app_data;
|
||||
@ -130,14 +130,11 @@ void pdf_write_png_image (pdf_page_handle pdf_page,
|
||||
{
|
||||
struct pdf_png_image *image;
|
||||
|
||||
struct pdf_obj *stream;
|
||||
struct pdf_obj *stream_dict;
|
||||
struct pdf_obj *flateparams;
|
||||
pdf_obj_handle stream;
|
||||
pdf_obj_handle stream_dict;
|
||||
pdf_obj_handle flateparams;
|
||||
|
||||
struct pdf_obj *content_stream;
|
||||
|
||||
struct pdf_obj *contents;
|
||||
struct pdf_obj *mask;
|
||||
pdf_obj_handle mask;
|
||||
|
||||
image = pdf_calloc (1, sizeof (struct pdf_png_image));
|
||||
|
||||
@ -194,7 +191,7 @@ void pdf_write_png_image (pdf_page_handle pdf_page,
|
||||
}
|
||||
|
||||
if(palent) {
|
||||
struct pdf_obj *space;
|
||||
pdf_obj_handle space;
|
||||
space = pdf_new_obj (PT_ARRAY);
|
||||
pdf_add_array_elem (space, pdf_new_name ("Indexed"));
|
||||
pdf_add_array_elem (space, pdf_new_name ("DeviceRGB"));
|
||||
@ -215,19 +212,11 @@ void pdf_write_png_image (pdf_page_handle pdf_page,
|
||||
get the actual data */
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, stream);
|
||||
|
||||
content_stream = pdf_new_ind_ref (pdf_page->pdf_file,
|
||||
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_png_content_callback,
|
||||
image));
|
||||
|
||||
contents = pdf_get_dict_entry (pdf_page->page_dict, "Contents");
|
||||
|
||||
if (! contents)
|
||||
contents = pdf_new_obj (PT_ARRAY);
|
||||
|
||||
pdf_add_array_elem (contents, content_stream);
|
||||
pdf_set_dict_entry (pdf_page->page_dict, "Contents", contents);
|
||||
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
|
||||
pdf_page_add_content_stream(pdf_page, content_stream);
|
||||
}
|
||||
|
||||
125
pdf_prim.c
125
pdf_prim.c
@ -41,7 +41,7 @@
|
||||
struct pdf_array_elem
|
||||
{
|
||||
struct pdf_array_elem *next;
|
||||
struct pdf_obj *val;
|
||||
pdf_obj_handle val;
|
||||
};
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ struct pdf_dict_entry
|
||||
{
|
||||
struct pdf_dict_entry *next;
|
||||
char *key;
|
||||
struct pdf_obj *val;
|
||||
pdf_obj_handle val;
|
||||
};
|
||||
|
||||
|
||||
@ -68,20 +68,20 @@ struct pdf_dict
|
||||
|
||||
struct pdf_stream
|
||||
{
|
||||
struct pdf_obj *stream_dict;
|
||||
struct pdf_obj *length;
|
||||
pdf_obj_handle stream_dict;
|
||||
pdf_obj_handle length;
|
||||
pdf_stream_write_callback callback;
|
||||
void *app_data; /* arg to pass to callback */
|
||||
struct pdf_obj *filters; /* name or array of names */
|
||||
struct pdf_obj *decode_parms;
|
||||
pdf_obj_handle filters; /* name or array of names */
|
||||
pdf_obj_handle decode_parms;
|
||||
};
|
||||
|
||||
|
||||
struct pdf_obj
|
||||
{
|
||||
/* these fields only apply to indirectly referenced objects */
|
||||
struct pdf_obj *prev;
|
||||
struct pdf_obj *next;
|
||||
pdf_obj_handle prev;
|
||||
pdf_obj_handle next;
|
||||
unsigned long obj_num;
|
||||
unsigned long obj_gen;
|
||||
long int file_offset;
|
||||
@ -98,7 +98,7 @@ struct pdf_obj
|
||||
} string;
|
||||
long integer;
|
||||
double real;
|
||||
struct pdf_obj *ind_ref;
|
||||
pdf_obj_handle ind_ref;
|
||||
struct pdf_dict dict;
|
||||
struct pdf_array array;
|
||||
struct pdf_stream stream;
|
||||
@ -106,14 +106,14 @@ struct pdf_obj
|
||||
};
|
||||
|
||||
|
||||
struct pdf_obj *ref (struct pdf_obj *obj)
|
||||
pdf_obj_handle ref (pdf_obj_handle obj)
|
||||
{
|
||||
obj->ref_count++;
|
||||
return (obj);
|
||||
}
|
||||
|
||||
|
||||
void unref (struct pdf_obj *obj)
|
||||
void unref (pdf_obj_handle obj)
|
||||
{
|
||||
if ((--obj->ref_count) == 0)
|
||||
{
|
||||
@ -122,14 +122,14 @@ void unref (struct pdf_obj *obj)
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_deref_ind_obj (struct pdf_obj *ind_obj)
|
||||
pdf_obj_handle pdf_deref_ind_obj (pdf_obj_handle ind_obj)
|
||||
{
|
||||
pdf_assert (ind_obj->type == PT_IND_REF);
|
||||
return (ind_obj->val.ind_ref);
|
||||
}
|
||||
|
||||
|
||||
void pdf_set_dict_entry (struct pdf_obj *dict_obj, char *key, struct pdf_obj *val)
|
||||
void pdf_set_dict_entry (pdf_obj_handle dict_obj, char *key, pdf_obj_handle val)
|
||||
{
|
||||
struct pdf_dict_entry *entry;
|
||||
|
||||
@ -158,7 +158,7 @@ void pdf_set_dict_entry (struct pdf_obj *dict_obj, char *key, struct pdf_obj *va
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_get_dict_entry (struct pdf_obj *dict_obj, char *key)
|
||||
pdf_obj_handle pdf_get_dict_entry (pdf_obj_handle dict_obj, char *key)
|
||||
{
|
||||
struct pdf_dict_entry *entry;
|
||||
|
||||
@ -175,7 +175,7 @@ struct pdf_obj *pdf_get_dict_entry (struct pdf_obj *dict_obj, char *key)
|
||||
}
|
||||
|
||||
|
||||
void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val)
|
||||
void pdf_add_array_elem (pdf_obj_handle array_obj, pdf_obj_handle val)
|
||||
{
|
||||
struct pdf_array_elem *elem = pdf_calloc (1, sizeof (struct pdf_array_elem));
|
||||
|
||||
@ -195,7 +195,7 @@ void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val)
|
||||
}
|
||||
|
||||
|
||||
void pdf_add_array_elem_unique (struct pdf_obj *array_obj, struct pdf_obj *val)
|
||||
void pdf_add_array_elem_unique (pdf_obj_handle array_obj, pdf_obj_handle val)
|
||||
{
|
||||
struct pdf_array_elem *elem;
|
||||
|
||||
@ -221,42 +221,42 @@ void pdf_add_array_elem_unique (struct pdf_obj *array_obj, struct pdf_obj *val)
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_obj (pdf_obj_type type)
|
||||
pdf_obj_handle pdf_new_obj (pdf_obj_type type)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_calloc (1, sizeof (struct pdf_obj));
|
||||
pdf_obj_handle obj = pdf_calloc (1, sizeof (struct pdf_obj));
|
||||
obj->type = type;
|
||||
return (obj);
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_bool (bool val)
|
||||
pdf_obj_handle pdf_new_bool (bool val)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_new_obj (PT_BOOL);
|
||||
pdf_obj_handle obj = pdf_new_obj (PT_BOOL);
|
||||
obj->val.boolean = val;
|
||||
return (obj);
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_name (char *name)
|
||||
pdf_obj_handle pdf_new_name (char *name)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_new_obj (PT_NAME);
|
||||
pdf_obj_handle obj = pdf_new_obj (PT_NAME);
|
||||
obj->val.name = pdf_strdup (name);
|
||||
return (obj);
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_string (char *str)
|
||||
pdf_obj_handle pdf_new_string (char *str)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_new_obj (PT_STRING);
|
||||
pdf_obj_handle obj = pdf_new_obj (PT_STRING);
|
||||
obj->val.string.content = pdf_strdup (str);
|
||||
obj->val.string.length = strlen(str);
|
||||
return (obj);
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_string_n (char *str, int n)
|
||||
pdf_obj_handle pdf_new_string_n (char *str, int n)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_new_obj (PT_STRING);
|
||||
pdf_obj_handle obj = pdf_new_obj (PT_STRING);
|
||||
obj->val.string.length = n;
|
||||
obj->val.string.content = pdf_calloc (1,n);
|
||||
memcpy(obj->val.string.content, str, n);
|
||||
@ -264,28 +264,28 @@ struct pdf_obj *pdf_new_string_n (char *str, int n)
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_integer (long val)
|
||||
pdf_obj_handle pdf_new_integer (long val)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_new_obj (PT_INTEGER);
|
||||
pdf_obj_handle obj = pdf_new_obj (PT_INTEGER);
|
||||
obj->val.integer = val;
|
||||
return (obj);
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_real (double val)
|
||||
pdf_obj_handle pdf_new_real (double val)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_new_obj (PT_REAL);
|
||||
pdf_obj_handle obj = pdf_new_obj (PT_REAL);
|
||||
obj->val.real = val;
|
||||
return (obj);
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_stream (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream_dict,
|
||||
pdf_obj_handle pdf_new_stream (pdf_file_handle pdf_file,
|
||||
pdf_obj_handle stream_dict,
|
||||
pdf_stream_write_callback callback,
|
||||
void *app_data)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_new_obj (PT_STREAM);
|
||||
pdf_obj_handle obj = pdf_new_obj (PT_STREAM);
|
||||
|
||||
obj->val.stream.stream_dict = stream_dict;
|
||||
obj->val.stream.length = pdf_new_ind_ref (pdf_file, pdf_new_integer (0));
|
||||
@ -298,9 +298,9 @@ struct pdf_obj *pdf_new_stream (pdf_file_handle pdf_file,
|
||||
|
||||
|
||||
/* $$$ currently limited to one filter per stream */
|
||||
void pdf_stream_add_filter (struct pdf_obj *stream,
|
||||
void pdf_stream_add_filter (pdf_obj_handle stream,
|
||||
char *filter_name,
|
||||
struct pdf_obj *decode_parms)
|
||||
pdf_obj_handle decode_parms)
|
||||
{
|
||||
if (stream->type == PT_IND_REF)
|
||||
stream = pdf_deref_ind_obj (stream);
|
||||
@ -313,9 +313,9 @@ void pdf_stream_add_filter (struct pdf_obj *stream,
|
||||
}
|
||||
|
||||
|
||||
struct pdf_obj *pdf_new_ind_ref (pdf_file_handle pdf_file, struct pdf_obj *obj)
|
||||
pdf_obj_handle pdf_new_ind_ref (pdf_file_handle pdf_file, pdf_obj_handle obj)
|
||||
{
|
||||
struct pdf_obj *ind_obj;
|
||||
pdf_obj_handle ind_obj;
|
||||
|
||||
pdf_assert (obj->type != PT_IND_REF);
|
||||
|
||||
@ -346,7 +346,7 @@ struct pdf_obj *pdf_new_ind_ref (pdf_file_handle pdf_file, struct pdf_obj *obj)
|
||||
}
|
||||
|
||||
|
||||
long pdf_get_integer (struct pdf_obj *obj)
|
||||
long pdf_get_integer (pdf_obj_handle obj)
|
||||
{
|
||||
if (obj->type == PT_IND_REF)
|
||||
obj = pdf_deref_ind_obj (obj);
|
||||
@ -356,7 +356,7 @@ long pdf_get_integer (struct pdf_obj *obj)
|
||||
return (obj->val.integer);
|
||||
}
|
||||
|
||||
void pdf_set_integer (struct pdf_obj *obj, long val)
|
||||
void pdf_set_integer (pdf_obj_handle obj, long val)
|
||||
{
|
||||
if (obj->type == PT_IND_REF)
|
||||
obj = pdf_deref_ind_obj (obj);
|
||||
@ -367,7 +367,7 @@ void pdf_set_integer (struct pdf_obj *obj, long val)
|
||||
}
|
||||
|
||||
|
||||
double pdf_get_real (struct pdf_obj *obj)
|
||||
double pdf_get_real (pdf_obj_handle obj)
|
||||
{
|
||||
if (obj->type == PT_IND_REF)
|
||||
obj = pdf_deref_ind_obj (obj);
|
||||
@ -377,7 +377,7 @@ double pdf_get_real (struct pdf_obj *obj)
|
||||
return (obj->val.real);
|
||||
}
|
||||
|
||||
void pdf_set_real (struct pdf_obj *obj, double val)
|
||||
void pdf_set_real (pdf_obj_handle obj, double val)
|
||||
{
|
||||
if (obj->type == PT_IND_REF)
|
||||
obj = pdf_deref_ind_obj (obj);
|
||||
@ -388,7 +388,7 @@ void pdf_set_real (struct pdf_obj *obj, double val)
|
||||
}
|
||||
|
||||
|
||||
int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2)
|
||||
int pdf_compare_obj (pdf_obj_handle o1, pdf_obj_handle o2)
|
||||
{
|
||||
if (o1->type == PT_IND_REF)
|
||||
o1 = pdf_deref_ind_obj (o1);
|
||||
@ -527,14 +527,14 @@ void pdf_write_real (pdf_file_handle pdf_file, double num)
|
||||
}
|
||||
|
||||
|
||||
void pdf_write_ind_ref (pdf_file_handle pdf_file, struct pdf_obj *ind_obj)
|
||||
void pdf_write_ind_ref (pdf_file_handle pdf_file, pdf_obj_handle ind_obj)
|
||||
{
|
||||
struct pdf_obj *obj = pdf_deref_ind_obj (ind_obj);
|
||||
pdf_obj_handle obj = pdf_deref_ind_obj (ind_obj);
|
||||
fprintf (pdf_file->f, "%ld %ld R ", obj->obj_num, obj->obj_gen);
|
||||
}
|
||||
|
||||
|
||||
void pdf_write_array (pdf_file_handle pdf_file, struct pdf_obj *array_obj)
|
||||
void pdf_write_array (pdf_file_handle pdf_file, pdf_obj_handle array_obj)
|
||||
{
|
||||
struct pdf_array_elem *elem;
|
||||
|
||||
@ -550,7 +550,7 @@ void pdf_write_array (pdf_file_handle pdf_file, struct pdf_obj *array_obj)
|
||||
}
|
||||
|
||||
|
||||
void pdf_write_dict (pdf_file_handle pdf_file, struct pdf_obj *dict_obj)
|
||||
void pdf_write_dict (pdf_file_handle pdf_file, pdf_obj_handle dict_obj)
|
||||
{
|
||||
struct pdf_dict_entry *entry;
|
||||
|
||||
@ -569,7 +569,7 @@ void pdf_write_dict (pdf_file_handle pdf_file, struct pdf_obj *dict_obj)
|
||||
|
||||
|
||||
void pdf_stream_write_data (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
char *data,
|
||||
unsigned long len)
|
||||
{
|
||||
@ -585,7 +585,7 @@ void pdf_stream_write_data (pdf_file_handle pdf_file,
|
||||
|
||||
|
||||
void pdf_stream_printf (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -596,7 +596,7 @@ void pdf_stream_printf (pdf_file_handle pdf_file,
|
||||
}
|
||||
|
||||
|
||||
void pdf_write_stream (pdf_file_handle pdf_file, struct pdf_obj *stream)
|
||||
void pdf_write_stream (pdf_file_handle pdf_file, pdf_obj_handle stream)
|
||||
{
|
||||
unsigned long begin_pos, end_pos;
|
||||
|
||||
@ -616,7 +616,7 @@ void pdf_write_stream (pdf_file_handle pdf_file, struct pdf_obj *stream)
|
||||
}
|
||||
|
||||
|
||||
void pdf_write_obj (pdf_file_handle pdf_file, struct pdf_obj *obj)
|
||||
void pdf_write_obj (pdf_file_handle pdf_file, pdf_obj_handle obj)
|
||||
{
|
||||
switch (obj->type)
|
||||
{
|
||||
@ -659,9 +659,9 @@ void pdf_write_obj (pdf_file_handle pdf_file, struct pdf_obj *obj)
|
||||
}
|
||||
|
||||
|
||||
void pdf_write_ind_obj (pdf_file_handle pdf_file, struct pdf_obj *ind_obj)
|
||||
void pdf_write_ind_obj (pdf_file_handle pdf_file, pdf_obj_handle ind_obj)
|
||||
{
|
||||
struct pdf_obj *obj;
|
||||
pdf_obj_handle obj;
|
||||
|
||||
if (ind_obj->type == PT_IND_REF)
|
||||
obj = pdf_deref_ind_obj (ind_obj);
|
||||
@ -677,7 +677,7 @@ void pdf_write_ind_obj (pdf_file_handle pdf_file, struct pdf_obj *ind_obj)
|
||||
|
||||
void pdf_write_all_ind_obj (pdf_file_handle pdf_file)
|
||||
{
|
||||
struct pdf_obj *ind_obj;
|
||||
pdf_obj_handle ind_obj;
|
||||
for (ind_obj = pdf_file->first_ind_obj; ind_obj; ind_obj = ind_obj->next)
|
||||
if (! ind_obj->file_offset)
|
||||
pdf_write_ind_obj (pdf_file, ind_obj);
|
||||
@ -686,7 +686,7 @@ void pdf_write_all_ind_obj (pdf_file_handle pdf_file)
|
||||
|
||||
unsigned long pdf_write_xref (pdf_file_handle pdf_file)
|
||||
{
|
||||
struct pdf_obj *ind_obj;
|
||||
pdf_obj_handle ind_obj;
|
||||
pdf_file->xref_offset = ftell (pdf_file->f);
|
||||
fprintf (pdf_file->f, "xref\r\n");
|
||||
fprintf (pdf_file->f, "0 %ld\r\n", pdf_file->last_ind_obj->obj_num + 1);
|
||||
@ -698,7 +698,7 @@ unsigned long pdf_write_xref (pdf_file_handle pdf_file)
|
||||
|
||||
|
||||
/* this isn't really a PDF primitive data type */
|
||||
char pdf_new_XObject (pdf_page_handle pdf_page, struct pdf_obj *ind_ref)
|
||||
char pdf_new_XObject (pdf_page_handle pdf_page, pdf_obj_handle ind_ref)
|
||||
{
|
||||
char XObject_name [4] = "Im ";
|
||||
|
||||
@ -716,3 +716,18 @@ char pdf_new_XObject (pdf_page_handle pdf_page, struct pdf_obj *ind_ref)
|
||||
}
|
||||
|
||||
|
||||
void pdf_page_add_content_stream(pdf_page_handle pdf_page,
|
||||
pdf_obj_handle content_stream)
|
||||
{
|
||||
pdf_obj_handle contents;
|
||||
contents = pdf_get_dict_entry (pdf_page->page_dict, "Contents");
|
||||
|
||||
if (! contents)
|
||||
contents = pdf_new_obj (PT_ARRAY);
|
||||
|
||||
pdf_add_array_elem (contents, content_stream);
|
||||
pdf_set_dict_entry (pdf_page->page_dict, "Contents", contents);
|
||||
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
|
||||
}
|
||||
|
||||
|
||||
69
pdf_prim.h
69
pdf_prim.h
@ -23,6 +23,8 @@
|
||||
* pdf_write_name().
|
||||
*/
|
||||
|
||||
#ifndef PDF_PRIM_H
|
||||
#define PDF_PRIM_H
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@ -44,24 +46,24 @@ typedef enum
|
||||
} pdf_obj_type;
|
||||
|
||||
|
||||
struct pdf_obj;
|
||||
typedef struct pdf_obj *pdf_obj_handle;
|
||||
|
||||
|
||||
typedef void (*pdf_stream_write_callback)(pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data);
|
||||
|
||||
|
||||
/* returns -1 if o1 < 02, 0 if o1 == o2, 1 if o1 > o2 */
|
||||
/* only works for integer, real, string, and name objects */
|
||||
int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2);
|
||||
int pdf_compare_obj (pdf_obj_handle o1, pdf_obj_handle o2);
|
||||
|
||||
|
||||
void pdf_set_dict_entry (struct pdf_obj *dict_obj, char *key, struct pdf_obj *val);
|
||||
struct pdf_obj *pdf_get_dict_entry (struct pdf_obj *dict_obj, char *key);
|
||||
void pdf_set_dict_entry (pdf_obj_handle dict_obj, char *key, pdf_obj_handle val);
|
||||
pdf_obj_handle pdf_get_dict_entry (pdf_obj_handle dict_obj, char *key);
|
||||
|
||||
|
||||
void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val);
|
||||
void pdf_add_array_elem (pdf_obj_handle array_obj, pdf_obj_handle val);
|
||||
|
||||
|
||||
/* Following is intended for things like ProcSet in which an array object
|
||||
@ -69,44 +71,44 @@ void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val);
|
||||
the element to be added are of scalar types (types that are supported
|
||||
by pdf_compare_obj. Not efficient for large arrays as it does a
|
||||
comaprison to every element. */
|
||||
void pdf_add_array_elem_unique (struct pdf_obj *array_obj, struct pdf_obj *val);
|
||||
void pdf_add_array_elem_unique (pdf_obj_handle array_obj, pdf_obj_handle val);
|
||||
|
||||
|
||||
/* Create a new object that will NOT be used indirectly */
|
||||
struct pdf_obj *pdf_new_obj (pdf_obj_type type);
|
||||
pdf_obj_handle pdf_new_obj (pdf_obj_type type);
|
||||
|
||||
struct pdf_obj *pdf_new_bool (bool val);
|
||||
pdf_obj_handle pdf_new_bool (bool val);
|
||||
|
||||
struct pdf_obj *pdf_new_name (char *name);
|
||||
pdf_obj_handle pdf_new_name (char *name);
|
||||
|
||||
struct pdf_obj *pdf_new_string (char *str);
|
||||
pdf_obj_handle pdf_new_string (char *str);
|
||||
|
||||
struct pdf_obj *pdf_new_string_n (char *str, int n);
|
||||
pdf_obj_handle pdf_new_string_n (char *str, int n);
|
||||
|
||||
struct pdf_obj *pdf_new_integer (long val);
|
||||
pdf_obj_handle pdf_new_integer (long val);
|
||||
|
||||
struct pdf_obj *pdf_new_real (double val);
|
||||
pdf_obj_handle pdf_new_real (double val);
|
||||
|
||||
|
||||
/* Create a new indirect object */
|
||||
struct pdf_obj *pdf_new_ind_ref (pdf_file_handle pdf_file, struct pdf_obj *obj);
|
||||
pdf_obj_handle pdf_new_ind_ref (pdf_file_handle pdf_file, pdf_obj_handle obj);
|
||||
|
||||
/* get the object referenced by an indirect reference */
|
||||
struct pdf_obj *pdf_deref_ind_obj (struct pdf_obj *ind_obj);
|
||||
pdf_obj_handle pdf_deref_ind_obj (pdf_obj_handle ind_obj);
|
||||
|
||||
|
||||
long pdf_get_integer (struct pdf_obj *obj);
|
||||
void pdf_set_integer (struct pdf_obj *obj, long val);
|
||||
long pdf_get_integer (pdf_obj_handle obj);
|
||||
void pdf_set_integer (pdf_obj_handle obj, long val);
|
||||
|
||||
|
||||
double pdf_get_real (struct pdf_obj *obj);
|
||||
void pdf_set_real (struct pdf_obj *obj, double val);
|
||||
double pdf_get_real (pdf_obj_handle obj);
|
||||
void pdf_set_real (pdf_obj_handle obj, double val);
|
||||
|
||||
|
||||
/* The callback will be called when the stream data is to be written to the
|
||||
file. app_data will be passed as an argument to the callback. */
|
||||
struct pdf_obj *pdf_new_stream (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream_dict,
|
||||
pdf_obj_handle pdf_new_stream (pdf_file_handle pdf_file,
|
||||
pdf_obj_handle stream_dict,
|
||||
pdf_stream_write_callback callback,
|
||||
void *app_data);
|
||||
|
||||
@ -114,32 +116,32 @@ struct pdf_obj *pdf_new_stream (pdf_file_handle pdf_file,
|
||||
to write the actual stream data. */
|
||||
|
||||
void pdf_stream_flush_bits (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream);
|
||||
pdf_obj_handle stream);
|
||||
|
||||
void pdf_stream_write_data (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
char *data,
|
||||
unsigned long len);
|
||||
|
||||
void pdf_stream_printf (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
char *fmt, ...);
|
||||
|
||||
|
||||
void pdf_stream_add_filter (struct pdf_obj *stream,
|
||||
void pdf_stream_add_filter (pdf_obj_handle stream,
|
||||
char *filter_name,
|
||||
struct pdf_obj *decode_parms);
|
||||
pdf_obj_handle decode_parms);
|
||||
|
||||
|
||||
/* Write the object to the file */
|
||||
void pdf_write_obj (pdf_file_handle pdf_file, struct pdf_obj *obj);
|
||||
void pdf_write_obj (pdf_file_handle pdf_file, pdf_obj_handle obj);
|
||||
|
||||
|
||||
/* Write the indirect object to the file. For most objects this should
|
||||
be done by pdf_write_all_ind_obj() when the file is being closed, but for
|
||||
large objects such as streams, it's probably better to do it as soon as the
|
||||
object is complete. */
|
||||
void pdf_write_ind_obj (pdf_file_handle pdf_file, struct pdf_obj *ind_obj);
|
||||
void pdf_write_ind_obj (pdf_file_handle pdf_file, pdf_obj_handle ind_obj);
|
||||
|
||||
|
||||
/* Write all indirect objects that haven't already been written to the file. */
|
||||
@ -155,4 +157,11 @@ void pdf_write_name (pdf_file_handle pdf_file, char *s);
|
||||
|
||||
|
||||
/* this isn't really a PDF primitive data type */
|
||||
char pdf_new_XObject (pdf_page_handle pdf_page, struct pdf_obj *ind_ref);
|
||||
char pdf_new_XObject (pdf_page_handle pdf_page, pdf_obj_handle ind_ref);
|
||||
|
||||
|
||||
void pdf_page_add_content_stream(pdf_page_handle pdf_page,
|
||||
pdf_obj_handle content_stream);
|
||||
|
||||
|
||||
#endif // PDF_PRIM_H
|
||||
|
||||
@ -24,35 +24,35 @@
|
||||
struct pdf_page
|
||||
{
|
||||
pdf_file_handle pdf_file;
|
||||
struct pdf_obj *page_dict;
|
||||
struct pdf_obj *media_box;
|
||||
struct pdf_obj *procset;
|
||||
struct pdf_obj *resources;
|
||||
pdf_obj_handle page_dict;
|
||||
pdf_obj_handle media_box;
|
||||
pdf_obj_handle procset;
|
||||
pdf_obj_handle resources;
|
||||
|
||||
char last_XObject_name;
|
||||
struct pdf_obj *XObject_dict;
|
||||
pdf_obj_handle XObject_dict;
|
||||
};
|
||||
|
||||
|
||||
struct pdf_pages
|
||||
{
|
||||
struct pdf_obj *pages_dict;
|
||||
struct pdf_obj *kids;
|
||||
struct pdf_obj *count;
|
||||
pdf_obj_handle pages_dict;
|
||||
pdf_obj_handle kids;
|
||||
pdf_obj_handle count;
|
||||
};
|
||||
|
||||
|
||||
struct pdf_file
|
||||
{
|
||||
FILE *f;
|
||||
struct pdf_obj *first_ind_obj;
|
||||
struct pdf_obj *last_ind_obj;
|
||||
pdf_obj_handle first_ind_obj;
|
||||
pdf_obj_handle last_ind_obj;
|
||||
long int xref_offset;
|
||||
struct pdf_obj *catalog;
|
||||
struct pdf_obj *info;
|
||||
pdf_obj_handle catalog;
|
||||
pdf_obj_handle info;
|
||||
struct pdf_pages *root;
|
||||
struct pdf_bookmark *outline_root;
|
||||
struct pdf_obj *trailer_dict;
|
||||
pdf_obj_handle trailer_dict;
|
||||
struct pdf_name_tree *page_label_tree;
|
||||
struct pdf_name_tree *name_tree_list;
|
||||
};
|
||||
|
||||
17
pdf_text.c
17
pdf_text.c
@ -37,7 +37,7 @@
|
||||
|
||||
|
||||
static void pdf_write_text_content_callback (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data)
|
||||
{
|
||||
pdf_stream_printf (pdf_file, stream,
|
||||
@ -45,9 +45,9 @@ static void pdf_write_text_content_callback (pdf_file_handle pdf_file,
|
||||
}
|
||||
|
||||
|
||||
static struct pdf_obj *pdf_create_font (pdf_page_handle pdf_page)
|
||||
static pdf_obj_handle pdf_create_font (pdf_page_handle pdf_page)
|
||||
{
|
||||
struct pdf_obj *font = pdf_new_ind_ref (pdf_page->pdf_file,
|
||||
pdf_obj_handle font = pdf_new_ind_ref (pdf_page->pdf_file,
|
||||
pdf_new_obj (PT_DICTIONARY));
|
||||
pdf_set_dict_entry (font, "Type", pdf_new_name ("Font"));
|
||||
pdf_set_dict_entry (font, "Subtype", pdf_new_name ("Type1"));
|
||||
@ -60,9 +60,8 @@ static struct pdf_obj *pdf_create_font (pdf_page_handle pdf_page)
|
||||
|
||||
void pdf_write_text (pdf_page_handle pdf_page)
|
||||
{
|
||||
struct pdf_obj *font;
|
||||
struct pdf_obj *font_dict;
|
||||
struct pdf_obj *content_stream;
|
||||
pdf_obj_handle font;
|
||||
pdf_obj_handle font_dict;
|
||||
|
||||
font = pdf_create_font (pdf_page);
|
||||
|
||||
@ -75,14 +74,12 @@ void pdf_write_text (pdf_page_handle pdf_page)
|
||||
|
||||
pdf_add_array_elem_unique (pdf_page->procset, pdf_new_name ("Text"));
|
||||
|
||||
content_stream = pdf_new_ind_ref (pdf_page->pdf_file,
|
||||
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_text_content_callback,
|
||||
NULL));
|
||||
|
||||
pdf_set_dict_entry (pdf_page->page_dict, "Contents", content_stream);
|
||||
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
|
||||
pdf_page_add_content_stream(pdf_page, content_stream);
|
||||
}
|
||||
|
||||
|
||||
83
scanner.l
83
scanner.l
@ -51,66 +51,67 @@ dot [\.]
|
||||
|
||||
%%
|
||||
|
||||
[\,;{}()] { return (yytext [0]); }
|
||||
{dot}{dot} { LDBG(("elipsis\n")); return (ELIPSIS); }
|
||||
[\,;{}()] { return yytext [0]; }
|
||||
{dot}{dot} { LDBG(("elipsis\n")); return ELIPSIS; }
|
||||
|
||||
/* decimal integer */
|
||||
{digit}+ { yylval.integer = atoi (yytext); LDBG(("integer %d\n", yylval.integer)); return (INTEGER); }
|
||||
{digit}+ { yylval.integer = atoi (yytext); LDBG(("integer %d\n", yylval.integer)); return INTEGER; }
|
||||
|
||||
/* floating point number - tricky to make sure it doesn't grab an integer
|
||||
followed by an elipsis */
|
||||
-?{digit}+\.{digit}+ { yylval.fp = atof (yytext); return (FLOAT); }
|
||||
-?{digit}+\./[^.] { yylval.fp = atof (yytext); return (FLOAT); }
|
||||
-?{digit}+\.{digit}+ { yylval.fp = atof (yytext); return FLOAT; }
|
||||
-?{digit}+\./[^.] { yylval.fp = atof (yytext); return FLOAT; }
|
||||
|
||||
a { yylval.size.width = 8.5;
|
||||
yylval.size.height = 11.0;
|
||||
return (PAGE_SIZE); }
|
||||
return PAGE_SIZE; }
|
||||
b { yylval.size.width = 11.0;
|
||||
yylval.size.height = 17.0;
|
||||
return (PAGE_SIZE); }
|
||||
return PAGE_SIZE; }
|
||||
c { yylval.size.width = 17.0;
|
||||
yylval.size.height = 22.0;
|
||||
return (PAGE_SIZE); }
|
||||
return PAGE_SIZE; }
|
||||
d { yylval.size.width = 22.0;
|
||||
yylval.size.height = 34.0;
|
||||
return (PAGE_SIZE); }
|
||||
return PAGE_SIZE; }
|
||||
e { yylval.size.width = 34.0;
|
||||
yylval.size.height = 44.0;
|
||||
return (PAGE_SIZE); }
|
||||
return PAGE_SIZE; }
|
||||
|
||||
all { return (ALL); }
|
||||
author { return (AUTHOR); }
|
||||
blank { return (BLANK); }
|
||||
bookmark { return (BOOKMARK); }
|
||||
cm { return (CM); }
|
||||
colormap { return (COLORMAP); }
|
||||
creator { return (CREATOR); }
|
||||
crop { return (CROP); }
|
||||
even { return (EVEN); }
|
||||
file { return (FILE_KEYWORD); }
|
||||
image { return (IMAGE); }
|
||||
images { return (IMAGES); }
|
||||
inch { return (INCH); }
|
||||
input { return (INPUT); }
|
||||
keywords { return (KEYWORDS); }
|
||||
label { return (LABEL); }
|
||||
landscape { return (LANDSCAPE); }
|
||||
odd { return (ODD); }
|
||||
output { return (OUTPUT); }
|
||||
overlay { return (OVERLAY); }
|
||||
page { return (PAGE); }
|
||||
pages { return (PAGES); }
|
||||
portrait { return (PORTRAIT) ; }
|
||||
resolution { return (RESOLUTION) ; }
|
||||
rotate { return (ROTATE); }
|
||||
size { return (SIZE); }
|
||||
subject { return (SUBJECT); }
|
||||
title { return (TITLE); }
|
||||
transparent { return (TRANSPARENT); }
|
||||
all { return ALL; }
|
||||
author { return AUTHOR; }
|
||||
blank { return BLANK; }
|
||||
bookmark { return BOOKMARK; }
|
||||
cm { return CM; }
|
||||
colormap { return COLORMAP; }
|
||||
creator { return CREATOR; }
|
||||
crop { return CROP; }
|
||||
even { return EVEN; }
|
||||
file { return FILE_KEYWORD; }
|
||||
imagemask { return IMAGEMASK; }
|
||||
image { return IMAGE; }
|
||||
images { return IMAGES; }
|
||||
inch { return INCH; }
|
||||
input { return INPUT; }
|
||||
keywords { return KEYWORDS; }
|
||||
label { return LABEL; }
|
||||
landscape { return LANDSCAPE; }
|
||||
odd { return ODD; }
|
||||
output { return OUTPUT; }
|
||||
overlay { return OVERLAY; }
|
||||
page { return PAGE; }
|
||||
pages { return PAGES; }
|
||||
portrait { return PORTRAIT ; }
|
||||
resolution { return RESOLUTION ; }
|
||||
rotate { return ROTATE; }
|
||||
size { return SIZE; }
|
||||
subject { return SUBJECT; }
|
||||
title { return TITLE; }
|
||||
transparent { return TRANSPARENT; }
|
||||
|
||||
'[^\n']' {
|
||||
yylval.character = yytext [1];
|
||||
return (CHARACTER);
|
||||
return CHARACTER;
|
||||
}
|
||||
|
||||
\"[^\n"]*\" {
|
||||
@ -119,7 +120,7 @@ transparent { return (TRANSPARENT); }
|
||||
memcpy (yylval.string, yytext + 1, len);
|
||||
yylval.string [len] = '\0';
|
||||
LDBG (("string \"%s\"\n", yylval.string));
|
||||
return (STRING);
|
||||
return STRING;
|
||||
}
|
||||
|
||||
[ \t]+ /* whitespace */
|
||||
|
||||
70
semantics.c
70
semantics.c
@ -467,9 +467,8 @@ void output_pages (range_t range)
|
||||
void output_overlay (overlay_t overlay)
|
||||
{
|
||||
output_pages (last_output_page->range);
|
||||
last_output_page->has_overlay = 1;
|
||||
last_output_page->overlay.left = overlay.left;
|
||||
last_output_page->overlay.top = overlay.top;
|
||||
last_output_page->has_overlay = true;
|
||||
last_output_page->overlay = overlay;
|
||||
}
|
||||
|
||||
void output_set_colormap (rgb_t black_color, rgb_t white_color)
|
||||
@ -480,6 +479,14 @@ void output_set_colormap (rgb_t black_color, rgb_t white_color)
|
||||
last_output_context->colormap.white_map = white_color;
|
||||
}
|
||||
|
||||
void output_imagemask (rgb_t foreground_color)
|
||||
{
|
||||
output_pages (last_output_page->range);
|
||||
last_output_page->has_overlay = true;
|
||||
last_output_page->overlay.imagemask = true;
|
||||
last_output_page->overlay.foreground = foreground_color;
|
||||
}
|
||||
|
||||
void yyerror (const char *s)
|
||||
{
|
||||
fprintf (stderr, "%d: %s\n", line, s);
|
||||
@ -489,7 +496,7 @@ static char *get_input_filename (input_context_t *context)
|
||||
{
|
||||
for (; context; context = context->parent)
|
||||
if ((context->input_file) || (context->is_blank))
|
||||
return (context->input_file);
|
||||
return context->input_file;
|
||||
fprintf (stderr, "no input file name found\n");
|
||||
exit (2);
|
||||
}
|
||||
@ -503,15 +510,15 @@ static bool get_input_rotation (input_context_t *context,
|
||||
if (context->modifiers [type].has_rotation)
|
||||
{
|
||||
* rotation = context->modifiers [type].rotation;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
if (context->modifiers [INPUT_MODIFIER_ALL].has_rotation)
|
||||
{
|
||||
* rotation = context->modifiers [INPUT_MODIFIER_ALL].rotation;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return (0); /* default */
|
||||
return false; /* default */
|
||||
}
|
||||
|
||||
static rgb_range_t *get_input_transparency (input_context_t *context,
|
||||
@ -540,22 +547,22 @@ static bool get_input_page_size (input_context_t *context,
|
||||
if (context->modifiers [type].has_page_size)
|
||||
{
|
||||
* page_size = context->modifiers [type].page_size;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
if (context->modifiers [INPUT_MODIFIER_ALL].has_page_size)
|
||||
{
|
||||
* page_size = context->modifiers [INPUT_MODIFIER_ALL].page_size;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return (0); /* default */
|
||||
return false; /* default */
|
||||
}
|
||||
|
||||
static char *get_output_filename (output_context_t *context)
|
||||
{
|
||||
for (; context; context = context->parent)
|
||||
if (context->output_file)
|
||||
return (context->output_file);
|
||||
return context->output_file;
|
||||
fprintf (stderr, "no output file found\n");
|
||||
exit (2);
|
||||
}
|
||||
@ -564,7 +571,7 @@ static pdf_file_attributes_t *get_output_file_attributes (output_context_t *cont
|
||||
{
|
||||
for (; context; context = context->parent)
|
||||
if (context->output_file)
|
||||
return (& context->file_attributes);
|
||||
return & context->file_attributes;
|
||||
fprintf (stderr, "no output file found\n");
|
||||
exit (2);
|
||||
}
|
||||
@ -573,16 +580,16 @@ static page_label_t *get_output_page_label (output_context_t *context)
|
||||
{
|
||||
for (; context; context = context->parent)
|
||||
if (context->has_page_label)
|
||||
return (& context->page_label);
|
||||
return (NULL); /* default */
|
||||
return & context->page_label;
|
||||
return NULL; /* default */
|
||||
}
|
||||
|
||||
static colormap_t *get_output_colormap (output_context_t *context)
|
||||
{
|
||||
for (; context; context = context->parent)
|
||||
if (context->has_colormap)
|
||||
return (& context->colormap);
|
||||
return (NULL); /* default */
|
||||
return & context->colormap;
|
||||
return NULL; /* default */
|
||||
}
|
||||
|
||||
|
||||
@ -670,7 +677,7 @@ void dump_output_tree (void)
|
||||
|
||||
static inline int range_count (range_t range)
|
||||
{
|
||||
return ((range.last - range.first) + 1);
|
||||
return (range.last - range.first) + 1;
|
||||
}
|
||||
|
||||
|
||||
@ -717,7 +724,7 @@ bool parse_control_file (char *fn)
|
||||
if (yyin)
|
||||
fclose (yyin);
|
||||
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool omit_label (page_label_t *page_label)
|
||||
@ -747,6 +754,7 @@ bool process_controls (void)
|
||||
input_attributes_t input_attributes;
|
||||
input_modifier_type_t parity;
|
||||
page_label_t *page_label;
|
||||
output_attributes_t output_attributes;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -758,7 +766,7 @@ bool process_controls (void)
|
||||
else
|
||||
image = first_input_image;
|
||||
if (! image)
|
||||
return (1); /* done */
|
||||
return true; /* done */
|
||||
i = 0;
|
||||
input_fn = get_input_filename (image->input_context);
|
||||
if (verbose)
|
||||
@ -771,7 +779,7 @@ bool process_controls (void)
|
||||
if (! open_input_file (input_fn))
|
||||
{
|
||||
fprintf (stderr, "error opening input file '%s'\n", input_fn);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -790,7 +798,7 @@ bool process_controls (void)
|
||||
get_output_file_attributes (page->output_context)))
|
||||
{
|
||||
fprintf (stderr, "error opening PDF file '%s'\n", output_fn);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -809,14 +817,21 @@ bool process_controls (void)
|
||||
|
||||
input_attributes.transparency = get_input_transparency (image->input_context, parity);
|
||||
|
||||
memset (& output_attributes, 0, sizeof (output_attributes));
|
||||
output_attributes.colormap = get_output_colormap (page->output_context);
|
||||
|
||||
// really an output attribute, but we don't have such an thing
|
||||
input_attributes.colormap = get_output_colormap (page->output_context);
|
||||
if (page->has_overlay)
|
||||
output_attributes.overlay = & page->overlay;
|
||||
|
||||
if (verbose)
|
||||
fprintf (stderr, "processing image %d\n", image->range.first + i);
|
||||
{
|
||||
fprintf(stderr, "processing image %d", image->range.first + i);
|
||||
if (page->has_overlay)
|
||||
fprintf(stderr, " overlay");
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
if (p)
|
||||
if (p || page->has_overlay)
|
||||
page_label = NULL;
|
||||
else
|
||||
{
|
||||
@ -836,11 +851,10 @@ bool process_controls (void)
|
||||
input_attributes,
|
||||
p ? NULL : page->bookmark_list,
|
||||
page_label,
|
||||
page->has_overlay ? & page->overlay : NULL,
|
||||
input_attributes.transparency))
|
||||
output_attributes))
|
||||
{
|
||||
fprintf (stderr, "error processing image %d\n", image->range.first + i);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
p++;
|
||||
|
||||
17
semantics.h
17
semantics.h
@ -24,8 +24,8 @@
|
||||
* contexts.
|
||||
*/
|
||||
|
||||
// HACK! rgb_t and colormap_t have to appear here and in pdf_g4! See pdf.h
|
||||
#define SEMANTICS
|
||||
#ifndef SEMANTICS_H
|
||||
#define SEMANTICS_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -63,8 +63,13 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double left;
|
||||
double top;
|
||||
bool imagemask;
|
||||
|
||||
// if not imagemask
|
||||
position_t position;
|
||||
|
||||
// if imagemask
|
||||
rgb_t foreground;
|
||||
} overlay_t;
|
||||
|
||||
typedef struct
|
||||
@ -91,7 +96,6 @@ typedef struct
|
||||
int count;
|
||||
} page_label_t;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INPUT_MODIFIER_ALL,
|
||||
@ -144,8 +148,11 @@ void output_pages (range_t range);
|
||||
void output_overlay (overlay_t overlay);
|
||||
void output_transparency (rgb_range_t rgb_range);
|
||||
void output_set_colormap (rgb_t black_color, rgb_t white_color);
|
||||
void output_imagemask (rgb_t foreground_color);
|
||||
|
||||
|
||||
/* functions to be called from main program: */
|
||||
bool parse_control_file (char *fn);
|
||||
bool process_controls (void);
|
||||
|
||||
#endif // SEMANTICS_H
|
||||
|
||||
79
tumble.c
79
tumble.c
@ -132,7 +132,7 @@ bool close_pdf_output_files (void)
|
||||
}
|
||||
out = NULL;
|
||||
output_files = NULL;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool open_pdf_output_file (char *name,
|
||||
@ -141,18 +141,18 @@ bool open_pdf_output_file (char *name,
|
||||
output_file_t *o;
|
||||
|
||||
if (out && (strcmp (name, out->name) == 0))
|
||||
return (1);
|
||||
return true;
|
||||
for (o = output_files; o; o = o->next)
|
||||
if (strcmp (name, o->name) == 0)
|
||||
{
|
||||
out = o;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
o = calloc (1, sizeof (output_file_t));
|
||||
if (! o)
|
||||
{
|
||||
fprintf (stderr, "can't calloc output file struct for '%s'\n", name);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
o->name = strdup (name);
|
||||
@ -160,7 +160,7 @@ bool open_pdf_output_file (char *name,
|
||||
{
|
||||
fprintf (stderr, "can't strdup output filename '%s'\n", name);
|
||||
free (o);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
o->pdf = pdf_create (name);
|
||||
@ -169,7 +169,7 @@ bool open_pdf_output_file (char *name,
|
||||
fprintf (stderr, "can't open output file '%s'\n", name);
|
||||
free (o->name);
|
||||
free (o);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attributes->author)
|
||||
@ -188,7 +188,7 @@ bool open_pdf_output_file (char *name,
|
||||
output_files = o;
|
||||
|
||||
out = o;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -202,28 +202,37 @@ bool process_page (int image, /* range 1 .. n */
|
||||
input_attributes_t input_attributes,
|
||||
bookmark_t *bookmarks,
|
||||
page_label_t *page_label,
|
||||
overlay_t *overlay,
|
||||
rgb_range_t *transparency)
|
||||
output_attributes_t output_attributes)
|
||||
{
|
||||
pdf_page_handle page;
|
||||
image_info_t image_info;
|
||||
position_t position;
|
||||
|
||||
if (! get_image_info (image, input_attributes, & image_info))
|
||||
return (0);
|
||||
return false;
|
||||
|
||||
if (overlay)
|
||||
output_attributes.position.x = 0.0;
|
||||
output_attributes.position.y = 0.0;
|
||||
|
||||
if (output_attributes.overlay)
|
||||
{
|
||||
page = last_page;
|
||||
position.x = overlay->left * POINTS_PER_INCH;
|
||||
position.y = last_size.height - image_info.height_points - overlay->top * POINTS_PER_INCH;
|
||||
|
||||
if (verbose)
|
||||
fprintf (stderr, "overlaying image at %.3f, %.3f\n", position.x, position.y);
|
||||
|
||||
if (transparency)
|
||||
if (output_attributes.overlay->imagemask)
|
||||
{
|
||||
input_attributes.transparency = transparency;
|
||||
if (verbose)
|
||||
fprintf (stderr, "overlaying imagemask with fg (%d %d %d)\n",
|
||||
output_attributes.overlay->foreground.red,
|
||||
output_attributes.overlay->foreground.green,
|
||||
output_attributes.overlay->foreground.blue);
|
||||
}
|
||||
else
|
||||
{
|
||||
output_attributes.position.x = output_attributes.overlay->position.x * POINTS_PER_INCH;
|
||||
output_attributes.position.y = last_size.height - image_info.height_points - output_attributes.overlay->position.y * POINTS_PER_INCH;
|
||||
if (verbose)
|
||||
fprintf (stderr, "overlaying image at %.3f, %.3f\n",
|
||||
output_attributes.position.x,
|
||||
output_attributes.position.y);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -233,15 +242,17 @@ bool process_page (int image, /* range 1 .. n */
|
||||
image_info.height_points);
|
||||
last_size.width = image_info.width_points;
|
||||
last_size.height = image_info.height_points;
|
||||
position.x = 0.0;
|
||||
position.y = 0.0;
|
||||
}
|
||||
|
||||
if (! process_image (image, input_attributes, & image_info, page, position))
|
||||
return (0);
|
||||
if (! process_image (image,
|
||||
input_attributes,
|
||||
& image_info,
|
||||
page,
|
||||
output_attributes))
|
||||
return false;
|
||||
|
||||
if (overlay)
|
||||
return (page != NULL);
|
||||
if (output_attributes.overlay)
|
||||
return page != NULL; // not creating a new page, so no bookmarks or page label
|
||||
|
||||
while (bookmarks)
|
||||
{
|
||||
@ -271,7 +282,7 @@ bool process_page (int image, /* range 1 .. n */
|
||||
page_label->style,
|
||||
page_label->prefix);
|
||||
|
||||
return (page != NULL);
|
||||
return page != NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -285,8 +296,8 @@ static int filename_length_without_suffix (char *in_fn)
|
||||
|
||||
p = strrchr (in_fn, '.');
|
||||
if (p && match_input_suffix (p))
|
||||
return (p - in_fn);
|
||||
return (len);
|
||||
return p - in_fn;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
@ -344,7 +355,8 @@ void main_args (char *out_fn,
|
||||
{
|
||||
int i, ip;
|
||||
input_attributes_t input_attributes;
|
||||
pdf_file_attributes_t output_attributes;
|
||||
output_attributes_t output_attributes;
|
||||
pdf_file_attributes_t pdf_file_attributes;
|
||||
bookmark_t bookmark;
|
||||
char bookmark_name [MAX_BOOKMARK_NAME_LEN];
|
||||
|
||||
@ -354,8 +366,9 @@ void main_args (char *out_fn,
|
||||
|
||||
memset (& input_attributes, 0, sizeof (input_attributes));
|
||||
memset (& output_attributes, 0, sizeof (output_attributes));
|
||||
memset (& pdf_file_attributes, 0, sizeof (pdf_file_attributes));
|
||||
|
||||
if (! open_pdf_output_file (out_fn, & output_attributes))
|
||||
if (! open_pdf_output_file (out_fn, & pdf_file_attributes))
|
||||
fatal (3, "error opening output file \"%s\"\n", out_fn);
|
||||
for (i = 0; i < inf_count; i++)
|
||||
{
|
||||
@ -369,11 +382,11 @@ void main_args (char *out_fn,
|
||||
bookmark_fmt,
|
||||
in_fn [i],
|
||||
ip);
|
||||
if (! process_page (ip, input_attributes,
|
||||
if (! process_page (ip,
|
||||
input_attributes,
|
||||
bookmark_fmt ? & bookmark : NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL))
|
||||
output_attributes))
|
||||
fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]);
|
||||
if (last_input_page ())
|
||||
break;
|
||||
|
||||
13
tumble.h
13
tumble.h
@ -41,11 +41,15 @@ typedef struct
|
||||
crop_t crop;
|
||||
|
||||
rgb_range_t *transparency;
|
||||
|
||||
colormap_t *colormap; // really an output attribute, but we don't have such a thing
|
||||
|
||||
} input_attributes_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
colormap_t *colormap;
|
||||
position_t position; // position of image on page XXX should also have scale
|
||||
overlay_t *overlay;
|
||||
} output_attributes_t;
|
||||
|
||||
|
||||
bool open_input_file (char *name);
|
||||
bool close_input_file (void);
|
||||
@ -68,5 +72,4 @@ bool process_page (int image, /* range 1 .. n */
|
||||
input_attributes_t input_attributes,
|
||||
bookmark_t *bookmarks,
|
||||
page_label_t *page_label,
|
||||
overlay_t *overlay,
|
||||
rgb_range_t *transparency);
|
||||
output_attributes_t output_attributes);
|
||||
|
||||
@ -52,24 +52,24 @@ struct pdf_blank_page
|
||||
|
||||
static bool match_blank_suffix (char *suffix)
|
||||
{
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool close_blank_input_file (void)
|
||||
{
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool open_blank_input_file (FILE *f, char *name)
|
||||
{
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool last_blank_input_page (void)
|
||||
{
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -81,15 +81,15 @@ static bool get_blank_image_info (int image,
|
||||
{
|
||||
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 (1);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void pdf_write_blank_content_callback (pdf_file_handle pdf_file,
|
||||
struct pdf_obj *stream,
|
||||
pdf_obj_handle stream,
|
||||
void *app_data)
|
||||
{
|
||||
struct pdf_blank_page *page = app_data;
|
||||
@ -106,14 +106,13 @@ 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,
|
||||
position_t position)
|
||||
output_attributes_t output_attributes)
|
||||
{
|
||||
struct pdf_blank_page *page;
|
||||
struct pdf_obj *content_stream;
|
||||
|
||||
/* If colormap set, use "white" color and draw rectangle to cover page. */
|
||||
|
||||
if (input_attributes.colormap)
|
||||
if (output_attributes.colormap)
|
||||
{
|
||||
page = pdf_calloc (1, sizeof (struct pdf_blank_page));
|
||||
|
||||
@ -121,20 +120,18 @@ static bool process_blank_image (int image, /* range 1 .. n */
|
||||
page->height = image_info->height_points;
|
||||
page->x = 0;
|
||||
page->y = 0;
|
||||
page->red = (double) input_attributes.colormap->white_map.red / 255.0;
|
||||
page->green = (double) input_attributes.colormap->white_map.green / 255.0;
|
||||
page->blue = (double) input_attributes.colormap->white_map.blue / 255.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;
|
||||
|
||||
content_stream = pdf_new_ind_ref (pdf_page->pdf_file,
|
||||
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_set_dict_entry (pdf_page->page_dict, "Contents", content_stream);
|
||||
pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
|
||||
pdf_page_add_content_stream(pdf_page, content_stream);
|
||||
}
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -64,8 +64,8 @@ bool match_input_suffix (char *suffix)
|
||||
int i;
|
||||
for (i = 0; i < input_handler_count; i++)
|
||||
if (input_handlers [i]->match_suffix (suffix))
|
||||
return (1);
|
||||
return (0);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -78,13 +78,13 @@ bool open_input_file (char *name)
|
||||
if (in)
|
||||
close_input_file ();
|
||||
current_input_handler = & blank_handler;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in)
|
||||
{
|
||||
if (strcmp (name, in_filename) == 0)
|
||||
return (1);
|
||||
return true;
|
||||
close_input_file ();
|
||||
}
|
||||
in_filename = strdup (name);
|
||||
@ -109,13 +109,13 @@ bool open_input_file (char *name)
|
||||
goto fail;
|
||||
}
|
||||
current_input_handler = input_handlers [i];
|
||||
return (1);
|
||||
return true;
|
||||
|
||||
fail:
|
||||
if (in)
|
||||
fclose (in);
|
||||
in = NULL;
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -138,15 +138,15 @@ bool close_input_file (void)
|
||||
in = NULL;
|
||||
}
|
||||
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool last_input_page (void)
|
||||
{
|
||||
if (! current_input_handler)
|
||||
return (0);
|
||||
return (current_input_handler->last_input_page ());
|
||||
return false;
|
||||
return current_input_handler->last_input_page ();
|
||||
}
|
||||
|
||||
|
||||
@ -155,23 +155,23 @@ bool get_image_info (int image,
|
||||
image_info_t *image_info)
|
||||
{
|
||||
if (! current_input_handler)
|
||||
return (0);
|
||||
return (current_input_handler->get_image_info (image,
|
||||
return false;
|
||||
return current_input_handler->get_image_info (image,
|
||||
input_attributes,
|
||||
image_info));
|
||||
image_info);
|
||||
}
|
||||
|
||||
bool process_image (int image,
|
||||
input_attributes_t input_attributes,
|
||||
image_info_t *image_info,
|
||||
pdf_page_handle page,
|
||||
position_t position)
|
||||
output_attributes_t output_attributes)
|
||||
{
|
||||
if (! current_input_handler)
|
||||
return (0);
|
||||
return (current_input_handler->process_image (image,
|
||||
return false;
|
||||
return current_input_handler->process_image (image,
|
||||
input_attributes,
|
||||
image_info,
|
||||
page,
|
||||
position));
|
||||
output_attributes);
|
||||
}
|
||||
|
||||
@ -45,7 +45,8 @@ typedef struct
|
||||
input_attributes_t input_attributes,
|
||||
image_info_t *image_info,
|
||||
pdf_page_handle page,
|
||||
position_t position);
|
||||
output_attributes_t output_attributes
|
||||
);
|
||||
} input_handler_t;
|
||||
|
||||
|
||||
@ -63,7 +64,7 @@ bool process_image (int image,
|
||||
input_attributes_t input_attributes,
|
||||
image_info_t *image_info,
|
||||
pdf_page_handle page,
|
||||
position_t position);
|
||||
output_attributes_t output_attributes);
|
||||
|
||||
|
||||
void init_tiff_handler (void);
|
||||
|
||||
@ -50,7 +50,7 @@ static bool match_jpeg_suffix (char *suffix)
|
||||
|
||||
static bool close_jpeg_input_file (void)
|
||||
{
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -61,12 +61,12 @@ static bool open_jpeg_input_file (FILE *f, char *name)
|
||||
|
||||
l = fread (& buf [0], 1, sizeof (buf), f);
|
||||
if (l != sizeof (buf))
|
||||
return (0);
|
||||
return false;
|
||||
|
||||
rewind (f);
|
||||
|
||||
if ((buf [0] != 0xff) || (buf [1] != 0xd8))
|
||||
return (0);
|
||||
return false;
|
||||
|
||||
cinfo.err = jpeg_std_error (& jerr);
|
||||
jpeg_create_decompress (& cinfo);
|
||||
@ -79,13 +79,13 @@ static bool open_jpeg_input_file (FILE *f, char *name)
|
||||
|
||||
jpeg_f = f;
|
||||
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool last_jpeg_input_page (void)
|
||||
{
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -112,7 +112,7 @@ static bool get_jpeg_image_info (int image,
|
||||
{
|
||||
fprintf (stderr, "JPEG grayscale image has %d components, should have 1\n",
|
||||
cinfo.num_components);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
image_info->color = 0;
|
||||
break;
|
||||
@ -122,13 +122,13 @@ static bool get_jpeg_image_info (int image,
|
||||
{
|
||||
fprintf (stderr, "JPEG RGB or YCbCr image has %d components, should have 3\n",
|
||||
cinfo.num_components);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
image_info->color = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "JPEG color space %d not supported\n", cinfo.jpeg_color_space);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
image_info->width_samples = cinfo.image_width;
|
||||
image_info->height_samples = cinfo.image_height;
|
||||
@ -145,7 +145,7 @@ static bool get_jpeg_image_info (int image,
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "JFIF density unit %d not supported\n", cinfo.density_unit);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
image_info->width_points = ((image_info->width_samples * POINTS_PER_INCH) /
|
||||
(cinfo.X_density * unit));
|
||||
@ -159,7 +159,7 @@ static bool get_jpeg_image_info (int image,
|
||||
image_info->height_points = (image_info->height_samples * POINTS_PER_INCH) / 300.0;
|
||||
}
|
||||
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -167,10 +167,10 @@ static bool process_jpeg_image (int image, /* range 1 .. n */
|
||||
input_attributes_t input_attributes,
|
||||
image_info_t *image_info,
|
||||
pdf_page_handle page,
|
||||
position_t position)
|
||||
output_attributes_t output_attributes)
|
||||
{
|
||||
pdf_write_jpeg_image (page,
|
||||
position.x, position.y,
|
||||
output_attributes.position.x, output_attributes.position.y,
|
||||
image_info->width_points,
|
||||
image_info->height_points,
|
||||
image_info->color,
|
||||
@ -179,7 +179,7 @@ static bool process_jpeg_image (int image, /* range 1 .. n */
|
||||
input_attributes.transparency,
|
||||
jpeg_f);
|
||||
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
25
tumble_pbm.c
25
tumble_pbm.c
@ -62,14 +62,14 @@ static pbm_info_t pbm;
|
||||
|
||||
static bool match_pbm_suffix (char *suffix)
|
||||
{
|
||||
return (strcasecmp (suffix, ".pbm") == 0);
|
||||
return strcasecmp (suffix, ".pbm") == 0;
|
||||
}
|
||||
|
||||
|
||||
static bool close_pbm_input_file (void)
|
||||
{
|
||||
pbm.f = NULL;
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -80,26 +80,26 @@ static bool open_pbm_input_file (FILE *f, char *name)
|
||||
|
||||
l = fread (& buf [0], 1, sizeof (buf), f);
|
||||
if (l != sizeof (buf))
|
||||
return (0);
|
||||
return false;
|
||||
|
||||
rewind (f);
|
||||
|
||||
if (! (((buf [0] == 'P') && (buf [1] == '1')) ||
|
||||
((buf [0] == 'P') && (buf [1] == '4'))))
|
||||
return (0);
|
||||
return false;
|
||||
|
||||
pbm.f = f;
|
||||
|
||||
pbm_readpbminit (f, & pbm.cols, & pbm.rows, & pbm.format);
|
||||
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool last_pbm_input_page (void)
|
||||
{
|
||||
/* only handle single-page PBM files for now */
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -140,12 +140,12 @@ static bool get_pbm_image_info (int image,
|
||||
(image_info->width_points > PAGE_MAX_POINTS))
|
||||
{
|
||||
fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
image_info->negative = false;
|
||||
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -153,7 +153,7 @@ static bool process_pbm_image (int image, /* range 1 .. n */
|
||||
input_attributes_t input_attributes,
|
||||
image_info_t *image_info,
|
||||
pdf_page_handle page,
|
||||
position_t position)
|
||||
output_attributes_t output_attributes)
|
||||
{
|
||||
bool result = 0;
|
||||
Rect rect;
|
||||
@ -210,11 +210,12 @@ static bool process_pbm_image (int image, /* range 1 .. n */
|
||||
rotate_bitmap (bitmap, input_attributes.rotation);
|
||||
|
||||
pdf_write_g4_fax_image (page,
|
||||
position.x, position.y,
|
||||
output_attributes.position.x, output_attributes.position.y,
|
||||
image_info->width_points, image_info->height_points,
|
||||
image_info->negative,
|
||||
bitmap,
|
||||
input_attributes.colormap,
|
||||
output_attributes.overlay,
|
||||
output_attributes.colormap,
|
||||
input_attributes.transparency);
|
||||
|
||||
result = 1;
|
||||
@ -222,7 +223,7 @@ static bool process_pbm_image (int image, /* range 1 .. n */
|
||||
fail:
|
||||
if (bitmap)
|
||||
free_bitmap (bitmap);
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
12
tumble_png.c
12
tumble_png.c
@ -50,12 +50,12 @@ static struct {
|
||||
|
||||
static bool match_png_suffix (char *suffix)
|
||||
{
|
||||
return (strcasecmp (suffix, ".png") == 0);
|
||||
return strcasecmp (suffix, ".png") == 0;
|
||||
}
|
||||
|
||||
static bool close_png_input_file (void)
|
||||
{
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
#define BENUM(p) (((p)[0]<<24)+((p)[1]<<16)+((p)[2]<<8)+(p)[3])
|
||||
@ -178,7 +178,7 @@ static bool get_png_image_info (int image,
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "PNG color type %d not supported\n", cinfo.color);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
image_info->width_samples = width;
|
||||
image_info->height_samples = height;
|
||||
@ -204,10 +204,10 @@ static bool process_png_image (int image, /* range 1 .. n */
|
||||
input_attributes_t input_attributes,
|
||||
image_info_t *image_info,
|
||||
pdf_page_handle page,
|
||||
position_t position)
|
||||
output_attributes_t output_attributes)
|
||||
{
|
||||
pdf_write_png_image (page,
|
||||
position.x, position.y,
|
||||
output_attributes.position.x, output_attributes.position.y,
|
||||
image_info->width_points,
|
||||
image_info->height_points,
|
||||
cinfo.color,
|
||||
@ -219,7 +219,7 @@ static bool process_png_image (int image, /* range 1 .. n */
|
||||
input_attributes.transparency,
|
||||
png_f);
|
||||
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ static bool match_tiff_suffix (char *suffix)
|
||||
static bool close_tiff_input_file (void)
|
||||
{
|
||||
TIFFClose (tiff_in);
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -76,13 +76,13 @@ static bool open_tiff_input_file (FILE *f, char *name)
|
||||
|
||||
l = fread (& buf [0], 1, sizeof (buf), f);
|
||||
if (l != sizeof (buf))
|
||||
return (0);
|
||||
return false;
|
||||
|
||||
rewind (f);
|
||||
|
||||
if (! (((buf [0] == 0x49) && (buf [1] == 0x49)) ||
|
||||
((buf [0] == 0x4d) && (buf [1] == 0x4d))))
|
||||
return (0);
|
||||
return false;
|
||||
|
||||
// At this point we expect never to use f (C stream) again,
|
||||
// and rewind() isn't guaranteed to have had any effect on
|
||||
@ -121,15 +121,15 @@ static bool open_tiff_input_file (FILE *f, char *name)
|
||||
fprintf(stderr, "can't lseek() back to original file offset.");
|
||||
exit (2);
|
||||
}
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool last_tiff_input_page (void)
|
||||
{
|
||||
return (TIFFLastDirectory (tiff_in));
|
||||
return TIFFLastDirectory (tiff_in);
|
||||
}
|
||||
|
||||
|
||||
@ -155,37 +155,37 @@ static bool get_tiff_image_info (int image,
|
||||
if (! TIFFSetDirectory (tiff_in, image - 1))
|
||||
{
|
||||
fprintf (stderr, "can't find page %d of input file\n", image);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
if (1 != TIFFGetField (tiff_in, TIFFTAG_IMAGELENGTH, & image_height))
|
||||
{
|
||||
fprintf (stderr, "can't get image height\n");
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
if (1 != TIFFGetField (tiff_in, TIFFTAG_IMAGEWIDTH, & image_width))
|
||||
{
|
||||
fprintf (stderr, "can't get image width\n");
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (1 != TIFFGetField (tiff_in, TIFFTAG_SAMPLESPERPIXEL, & samples_per_pixel))
|
||||
{
|
||||
fprintf (stderr, "can't get samples per pixel\n");
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef CHECK_DEPTH
|
||||
if (1 != TIFFGetField (tiff_in, TIFFTAG_IMAGEDEPTH, & image_depth))
|
||||
{
|
||||
fprintf (stderr, "can't get image depth\n");
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (1 != TIFFGetField (tiff_in, TIFFTAG_BITSPERSAMPLE, & bits_per_sample))
|
||||
{
|
||||
fprintf (stderr, "can't get bits per sample\n");
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (1 != TIFFGetField (tiff_in, TIFFTAG_PHOTOMETRIC, & photometric_interpretation))
|
||||
@ -198,7 +198,7 @@ static bool get_tiff_image_info (int image,
|
||||
(photometric_interpretation != PHOTOMETRIC_MINISBLACK))
|
||||
{
|
||||
fprintf(stderr, "photometric interpretation value %u is invalid\n", photometric_interpretation);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (1 != TIFFGetField (tiff_in, TIFFTAG_PLANARCONFIG, & planar_config))
|
||||
@ -214,27 +214,27 @@ static bool get_tiff_image_info (int image,
|
||||
if (samples_per_pixel != 1)
|
||||
{
|
||||
fprintf (stderr, "samples per pixel %u, must be 1\n", samples_per_pixel);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef CHECK_DEPTH
|
||||
if (image_depth != 1)
|
||||
{
|
||||
fprintf (stderr, "image depth %u, must be 1\n", image_depth);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bits_per_sample != 1)
|
||||
{
|
||||
fprintf (stderr, "bits per sample %u, must be 1\n", bits_per_sample);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (planar_config != 1)
|
||||
{
|
||||
fprintf (stderr, "planar config %u, must be 1\n", planar_config);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input_attributes.has_resolution)
|
||||
@ -266,12 +266,12 @@ static bool get_tiff_image_info (int image,
|
||||
(image_info->width_points > PAGE_MAX_POINTS))
|
||||
{
|
||||
fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES);
|
||||
return (0);
|
||||
return false;
|
||||
}
|
||||
|
||||
image_info->negative = (photometric_interpretation == PHOTOMETRIC_MINISBLACK);
|
||||
|
||||
return (1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -281,7 +281,7 @@ static bool process_tiff_image (int image, /* range 1 .. n */
|
||||
input_attributes_t input_attributes,
|
||||
image_info_t *image_info,
|
||||
pdf_page_handle page,
|
||||
position_t position)
|
||||
output_attributes_t output_attributes)
|
||||
{
|
||||
bool result = 0;
|
||||
Rect rect;
|
||||
@ -336,24 +336,21 @@ static bool process_tiff_image (int image, /* range 1 .. n */
|
||||
|
||||
rotate_bitmap (bitmap, input_attributes.rotation);
|
||||
|
||||
#if 0
|
||||
pdf_write_text (page);
|
||||
#else
|
||||
pdf_write_g4_fax_image (page,
|
||||
position.x, position.y,
|
||||
output_attributes.position.x, output_attributes.position.y,
|
||||
image_info->width_points, image_info->height_points,
|
||||
image_info->negative,
|
||||
bitmap,
|
||||
input_attributes.colormap,
|
||||
output_attributes.overlay,
|
||||
output_attributes.colormap,
|
||||
input_attributes.transparency);
|
||||
#endif
|
||||
|
||||
result = 1;
|
||||
|
||||
fail:
|
||||
if (bitmap)
|
||||
free_bitmap (bitmap);
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user