1
0
mirror of synced 2026-01-12 00:02:50 +00:00

finished implementing page labels.

This commit is contained in:
Eric Smith 2003-03-14 08:24:37 +00:00
parent 251a2dc7ac
commit 815c31a469
11 changed files with 182 additions and 86 deletions

View File

@ -1,6 +1,6 @@
# tumble: build a PDF file from image files
# Makefile
# $Id: Makefile,v 1.31 2003/03/13 03:50:59 eric Exp $
# $Id: Makefile,v 1.32 2003/03/14 00:24:37 eric Exp $
# Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
#
# This program is free software; you can redistribute it and/or modify
@ -55,7 +55,7 @@ YFLAGS = -d -v
# let me know why so I can improve this Makefile.
# -----------------------------------------------------------------------------
VERSION = 0.26
VERSION = 0.27
PACKAGE = tumble
@ -63,7 +63,8 @@ TARGETS = tumble
CSRCS = tumble.c semantics.c \
bitblt.c bitblt_table_gen.c bitblt_g4.c g4_table_gen.c \
pdf.c pdf_util.c pdf_prim.c pdf_bookmark.c pdf_name_tree.c \
pdf.c pdf_util.c pdf_prim.c pdf_name_tree.c \
pdf_bookmark.c pdf_page_label.c \
pdf_text.c pdf_g4.c pdf_jpeg.c
OSRCS = scanner.l parser.y
HDRS = tumble.h semantics.h bitblt.h bitblt_tables.h \
@ -87,7 +88,8 @@ all: $(TARGETS) $(TEST_TARGETS)
tumble: tumble.o scanner.o semantics.o parser.tab.o \
bitblt.o bitblt_g4.o bitblt_tables.o g4_tables.o \
pdf.o pdf_util.o pdf_prim.o pdf_bookmark.o pdf_name_tree.o \
pdf.o pdf_util.o pdf_prim.o pdf_name_tree.o \
pdf_bookmark.o pdf_page_label.o \
pdf_text.o pdf_g4.o pdf_jpeg.o
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
ifndef DEBUG

10
pdf.c
View File

@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* PDF routines
* $Id: pdf.c,v 1.11 2003/03/13 03:44:34 eric Exp $
* $Id: pdf.c,v 1.12 2003/03/14 00:24:37 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -121,9 +121,15 @@ pdf_file_handle pdf_create (char *filename, int page_mode)
void pdf_close (pdf_file_handle pdf_file)
{
/* finalize all data structures */
/* finalize trees, object numbers aren't allocated until this step */
pdf_finalize_name_trees (pdf_file);
/* add the page label number tree, if it exists, to the catalog */
if (pdf_file->page_label_tree)
pdf_set_dict_entry (pdf_file->catalog,
"PageLabels",
pdf_file->page_label_tree->root->dict);
/* write body */
pdf_write_all_ind_obj (pdf_file);

10
pdf.h
View File

@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* PDF routines
* $Id: pdf.h,v 1.9 2003/03/13 00:57:05 eric Exp $
* $Id: pdf.h,v 1.10 2003/03/14 00:24:37 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -90,3 +90,11 @@ pdf_bookmark_handle pdf_new_bookmark (pdf_bookmark_handle parent,
char *title,
bool open,
pdf_page_handle pdf_page);
void pdf_new_page_label (pdf_file_handle pdf_file,
int page_index,
int base,
int count,
char style,
char *prefix);

View File

@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* PDF routines
* $Id: pdf_name_tree.c,v 1.9 2003/03/13 00:57:05 eric Exp $
* $Id: pdf_name_tree.c,v 1.10 2003/03/14 00:24:37 eric Exp $
* Copyright 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -37,31 +37,6 @@
#include "pdf_name_tree.h"
#define MAX_NAME_TREE_NODE_ENTRIES 16
struct pdf_name_tree_node
{
struct pdf_obj *dict; /* indirect reference */
struct pdf_name_tree_node *parent; /* NULL for root */
bool leaf;
int count; /* how many kids or names/numbers are
attached to this 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;
/* 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];
};
struct pdf_name_tree *pdf_new_name_tree (pdf_file_handle pdf_file,
bool number_tree)
{

View File

@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* PDF routines
* $Id: pdf_name_tree.h,v 1.3 2003/03/13 00:57:05 eric Exp $
* $Id: pdf_name_tree.h,v 1.4 2003/03/14 00:24:37 eric Exp $
* Copyright 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -32,6 +32,31 @@ struct pdf_name_tree
};
#define MAX_NAME_TREE_NODE_ENTRIES 32
struct pdf_name_tree_node
{
struct pdf_obj *dict; /* indirect reference */
struct pdf_name_tree_node *parent; /* NULL for root */
bool leaf;
int count; /* how many kids or names/numbers are
attached to this 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;
/* 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];
};
struct pdf_name_tree *pdf_new_name_tree (pdf_file_handle pdf_file,
bool number_tree);

72
pdf_page_label.c Normal file
View File

@ -0,0 +1,72 @@
/*
* tumble: build a PDF file from image files
*
* PDF routines
* $Id: pdf_page_label.c,v 1.1 2003/03/14 00:24:37 eric Exp $
* Copyright 2003 Eric Smith <eric@brouhaha.com>
*
* 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
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bitblt.h"
#include "pdf.h"
#include "pdf_util.h"
#include "pdf_prim.h"
#include "pdf_private.h"
#include "pdf_name_tree.h"
void pdf_new_page_label (pdf_file_handle pdf_file,
int page_index,
int base,
int count,
char style,
char *prefix)
{
struct pdf_obj *label_dict;
char style_str [2] = { style, '\0' };
fprintf (stderr,
"page index %d, count %d, base %d, prefix '%s', style %c\n",
page_index, count, base,
prefix ? prefix : "NULL",
style);
if (! pdf_file->page_label_tree)
{
pdf_file->page_label_tree = pdf_new_name_tree (pdf_file, 1);
}
label_dict = pdf_new_obj (PT_DICTIONARY);
pdf_set_dict_entry (label_dict, "S", pdf_new_name (style_str));
if (prefix)
pdf_set_dict_entry (label_dict, "P", pdf_new_string (prefix));
if (base != 1)
pdf_set_dict_entry (label_dict, "St", pdf_new_integer (base));
pdf_add_number_tree_element (pdf_file->page_label_tree,
page_index,
label_dict);
}

View File

@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* PDF routines
* $Id: pdf_private.h,v 1.7 2003/03/13 00:57:05 eric Exp $
* $Id: pdf_private.h,v 1.8 2003/03/14 00:24:37 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -54,5 +54,6 @@ struct pdf_file
struct pdf_pages *root;
struct pdf_bookmark *outline_root;
struct pdf_obj *trailer_dict;
struct pdf_name_tree *page_label_tree;
struct pdf_name_tree *name_tree_list;
};

View File

@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* Semantic routines for spec file parser
* $Id: semantics.c,v 1.20 2003/03/13 23:08:52 eric Exp $
* $Id: semantics.c,v 1.21 2003/03/14 00:24:37 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -692,11 +692,6 @@ bool process_specs (void)
fprintf (stderr, "error opening PDF file '%s'\n", output_fn);
return (0);
}
page_label = get_output_page_label (page->output_context);
process_page_numbers (page_index,
range_count (page->range),
page->range.first,
page_label);
}
parity = ((image->range.first + i) % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN;
@ -714,9 +709,24 @@ bool process_specs (void)
if (verbose)
fprintf (stderr, "processing image %d\n", image->range.first + i);
if (p)
page_label = NULL;
else
{
page_label = get_output_page_label (page->output_context);
if (page_label)
{
page_label->page_index = page_index;
page_label->base = page->range.first;
page_label->count = range_count (page->range);
}
}
if (! process_page (image->range.first + i,
input_attributes,
p ? NULL : page->bookmark_list))
p ? NULL : page->bookmark_list,
page_label))
{
fprintf (stderr, "error processing image %d\n", image->range.first + i);
return (0);

View File

@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* Semantic routines for spec file parser
* $Id: semantics.h,v 1.13 2003/03/13 00:57:05 eric Exp $
* $Id: semantics.h,v 1.14 2003/03/14 00:24:37 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -46,6 +46,10 @@ typedef struct
{
char *prefix;
char style;
/* the following fields are not filled by the parser: */
int page_index;
int base;
int count;
} page_label_t;

View File

@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* Main program
* $Id: tumble.c,v 1.33 2003/03/13 03:42:46 eric Exp $
* $Id: tumble.c,v 1.34 2003/03/14 00:24:37 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -227,14 +227,6 @@ bool open_pdf_output_file (char *name,
}
void process_page_numbers (int page_index,
int count,
int base,
page_label_t *page_label)
{
}
/* frees original! */
static Bitmap *resize_bitmap (Bitmap *src,
double x_resolution,
@ -287,12 +279,9 @@ bool last_tiff_page (void)
}
bool process_tiff_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks)
static pdf_page_handle process_tiff_page (int image, /* range 1 .. n */
input_attributes_t input_attributes)
{
int result = 0;
uint32_t image_length, image_width;
uint32_t dest_image_length, dest_image_width;
#ifdef CHECK_DEPTH
@ -315,7 +304,7 @@ bool process_tiff_page (int image, /* range 1 .. n */
int row;
pdf_page_handle page;
pdf_page_handle page = NULL;
if (! TIFFSetDirectory (in, image - 1))
{
@ -473,29 +462,22 @@ bool process_tiff_page (int image, /* range 1 .. n */
0); /* BlackIs1 */
#endif
while (bookmarks)
{
/* $$$ need to handle level here */
pdf_new_bookmark (NULL, bookmarks->name, 0, page);
bookmarks = bookmarks->next;
}
result = 1;
if (bitmap)
free_bitmap (bitmap);
return (page);
fail:
if (bitmap)
free_bitmap (bitmap);
return (result);
return (NULL);
}
#if 0
bool process_jpeg_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks)
pdf_page_handle process_jpeg_page (int image, /* range 1 .. n */
input_attributes_t input_attributes)
{
int result = 0;
FILE *f;
pdf_page_handle page;
@ -510,20 +492,36 @@ bool process_jpeg_page (int image, /* range 1 .. n */
width_points, height_points,
f);
return (result);
return (page);
}
#endif
bool process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks)
bookmark_t *bookmarks,
page_label_t *page_label)
{
int result = 0;
pdf_page_handle page;
result = process_tiff_page (image, input_attributes, bookmarks);
page = process_tiff_page (image, input_attributes);
return (result);
while (bookmarks)
{
/* $$$ need to handle level here */
pdf_new_bookmark (NULL, bookmarks->name, 0, page);
bookmarks = bookmarks->next;
}
if (page_label)
pdf_new_page_label (out->pdf,
page_label->page_index,
page_label->base,
page_label->count,
page_label->style,
page_label->prefix);
return (page != NULL);
}
@ -625,7 +623,8 @@ void main_args (char *out_fn,
in_fn [i],
ip);
if (! process_page (ip, input_attributes,
bookmark_fmt ? & bookmark : NULL))
bookmark_fmt ? & bookmark : NULL,
NULL))
fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]);
if (last_tiff_page ())
break;

View File

@ -1,7 +1,7 @@
/*
* tumble: build a PDF file from image files
*
* $Id: tumble.h,v 1.13 2003/03/13 00:57:05 eric Exp $
* $Id: tumble.h,v 1.14 2003/03/14 00:24:37 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -57,13 +57,7 @@ bool open_pdf_output_file (char *name,
pdf_file_attributes_t *attributes);
void process_page_numbers (int page_index,
int count,
int base,
page_label_t *page_label);
bool process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
bookmark_t *bookmarks);
bookmark_t *bookmarks,
page_label_t *page_label);