Skip to content

Commit

Permalink
Add very many enhancements by J. David Bryan.
Browse files Browse the repository at this point in the history
  • Loading branch information
brouhaha committed Jun 24, 2016
1 parent a355304 commit 10c4f68
Show file tree
Hide file tree
Showing 24 changed files with 1,326 additions and 120 deletions.
29 changes: 16 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# 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
#
# 2010-09-02 [JDB] Allow building in a directory separate from the source and
# add PNG and blank-page support files. Also change the
# "include" of dependencies to suppress an error if the
# dependency files are not present.


# Conditionals: uncomment the following defines as nessary. Note that a
Expand All @@ -29,7 +34,7 @@
CTL_LANG=1


CFLAGS = -Wall
CFLAGS = -Wall -Wno-unused-function -Wno-unused-but-set-variable
LDFLAGS =
LDLIBS = -ltiff -ljpeg -lnetpbm -lz -lm

Expand All @@ -49,6 +54,7 @@ LDLIBS := -Wl,-static $(LDLIBS)
endif


LEX = flex
YACC = bison
YFLAGS = -d -v

Expand All @@ -58,18 +64,18 @@ YFLAGS = -d -v
# let me know why so I can improve this Makefile.
# -----------------------------------------------------------------------------

VERSION = 0.33
VERSION = 0.34

PACKAGE = tumble

TARGETS = tumble

CSRCS = tumble.c semantics.c \
tumble_input.c tumble_tiff.c tumble_jpeg.c tumble_pbm.c \
CSRCS = tumble.c semantics.c tumble_input.c \
tumble_tiff.c tumble_jpeg.c tumble_pbm.c tumble_png.c tumble_blank.c \
bitblt.c bitblt_table_gen.c bitblt_g4.c g4_table_gen.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
pdf_text.c pdf_g4.c pdf_jpeg.c pdf_png.c
OSRCS = scanner.l parser.y
HDRS = tumble.h tumble_input.h semantics.h bitblt.h bitblt_tables.h \
pdf.h pdf_private.h pdf_util.h pdf_prim.h pdf_name_tree.h
Expand Down Expand Up @@ -106,22 +112,19 @@ CFLAGS := $(CFLAGS) $(CDEFINES)
all: $(TARGETS) $(TEST_TARGETS)


TUMBLE_OBJS = tumble.o semantics.o \
tumble_input.o tumble_tiff.o tumble_jpeg.o tumble_pbm.o \
TUMBLE_OBJS = tumble.o semantics.o tumble_input.o \
tumble_tiff.o tumble_jpeg.o tumble_pbm.o tumble_png.o tumble_blank.o \
bitblt.o bitblt_g4.o bitblt_tables.o g4_tables.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
pdf_text.o pdf_g4.o pdf_jpeg.o pdf_png.o

ifdef CTL_LANG
TUMBLE_OBJS += scanner.o parser.tab.o
endif

tumble: $(TUMBLE_OBJS)
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
ifndef DEBUG
strip $@
endif


bitblt_tables.h: bitblt_table_gen
Expand Down Expand Up @@ -178,6 +181,6 @@ ALL_CSRCS = $(CSRCS) $(AUTO_CSRCS) $(TEST_CSRCS)
DEPENDS = $(ALL_CSRCS:.c=.d)

%.d: %.c
$(CC) -M -MG $(CFLAGS) $< | sed -e 's@ /[^ ]*@@g' -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $@
$(CC) -M -MG $(CFLAGS) $< | sed -e 's@ \([A-Za-z]\):/@ /\1/@g' -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $@

include $(DEPENDS)
-include $(DEPENDS)
7 changes: 7 additions & 0 deletions bitblt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
* 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
*
* 2009-03-13 [JDB] pm_config.h (part of NETPBM) defines BITS_PER_WORD but
* apparently doesn't use it externally. We undefine it here
* so that our version takes precedence and warnings are not
* generated.
*/

#undef BITS_PER_WORD


typedef struct Point
{
Expand Down
6 changes: 5 additions & 1 deletion bitblt_g4.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
*
* 2007-06-20 [JDB] Fixed a bug wherein "g4_get_pixel" is called with pixel
* index == width, causing an index off the end of the array
* if width % BITS_PER_WORD == 0.
*/


Expand Down Expand Up @@ -303,7 +307,7 @@ void bitblt_write_g4 (Bitmap *bitmap, FILE *f)
word_t *cur_line;
word_t *ref_line; /* reference (previous) row */

temp_buffer = pdf_calloc ((width + BITS_PER_WORD - 1) / BITS_PER_WORD,
temp_buffer = pdf_calloc (width / BITS_PER_WORD + 1,
sizeof (word_t));

cur_line = bitmap->bits;
Expand Down
65 changes: 61 additions & 4 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@
* 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
*/
*
* 2009-03-13 [JDB] Add support for blank pages, overlay images, color
* mapping, color-key masking, and push/pop of input
* contexts.
*/

%{
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "semantics.h"

extern int yylex (void);
%}

%error-verbose

%union {
int integer;
char character;
Expand All @@ -36,6 +44,9 @@
page_size_t size;
range_t range;
page_label_t page_label;
overlay_t overlay;
rgb_t rgb;
rgb_range_t rgb_range;
}

%token <integer> INTEGER
Expand Down Expand Up @@ -63,9 +74,13 @@
%token CROP
%token SIZE
%token RESOLUTION
%token BLANK
%token INPUT

%token TRANSPARENT
%token COLORMAP
%token LABEL
%token OVERLAY
%token PAGE
%token PAGES
%token BOOKMARK
Expand All @@ -89,6 +104,12 @@

%type <size> page_size

%type <rgb> rgb

%type <rgb_range> rgb_range
%type <rgb_range> gray_range
%type <rgb_range> color_range

%%

statements:
Expand Down Expand Up @@ -157,8 +178,21 @@ size_clause:
resolution_clause:
RESOLUTION FLOAT unit ;

rgb_range:
'(' range range range ')' { $$.red = $2; $$.green = $3; $$.blue = $4; }

gray_range:
'(' range ')' { $$.red = $2; $$.green = $2; $$.blue = $2; } ;

color_range:
rgb_range
| gray_range;

transparency_clause:
TRANSPARENT color_range ';' { input_set_transparency ($2); } ;

modifier_clause:
rotate_clause | crop_clause | size_clause | resolution_clause;
rotate_clause | crop_clause | size_clause | resolution_clause | transparency_clause;

modifier_clauses:
modifier_clause
Expand All @@ -175,20 +209,25 @@ part_clause:
modifier_clause_list ';'
{ input_set_modifier_context (INPUT_MODIFIER_ALL); } ;

blank_page_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_clause_list ;

input_clauses:
input_clause
| input_clauses input_clause ;

input_clause_list:
'{' input_clauses '}' ;
'{' { input_push_context (); }
input_clauses '}' { input_pop_context (); } ;

input_statement:
INPUT input_clauses ;
Expand Down Expand Up @@ -218,12 +257,23 @@ label_clause:
| 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 length ',' length ';' { overlay_t overlay = { $2, $4 }; output_overlay (overlay); } ;

page_ranges:
range { output_pages ($1); }
| page_ranges ',' range { output_pages ($3); } ;

page_clause:
PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
PAGE INTEGER { range_t range = { $2, $2 }; output_pages (range); } overlay_clause_list ';' ;

pages_clause:
PAGES page_ranges ';' ;
Expand All @@ -240,8 +290,15 @@ bookmark_clause:
bookmark_name_list
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); } ;

output_clause:
output_file_clause
| colormap_clause
| label_clause
| page_clause | pages_clause
| bookmark_clause
Expand Down
27 changes: 26 additions & 1 deletion pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
* 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
*
* 2005-05-03 [JDB] Add CreationDate and ModDate PDF headers.
* 2014-02-18 [JDB] Use PDF_PRODUCER definition.
*/


#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


#include "bitblt.h"
Expand Down Expand Up @@ -70,6 +74,11 @@ struct pdf_pages *pdf_new_pages (pdf_file_handle pdf_file)
pdf_file_handle pdf_create (char *filename)
{
pdf_file_handle pdf_file;
time_t current_time, adjusted_time;
struct tm *time_and_date;
int gmt_diff;
char tm_string[18], gmt_string[24];
const char tm_format[] = "D:%Y%m%d%H%M%S";

pdf_file = pdf_calloc (1, sizeof (struct pdf_file));

Expand All @@ -88,7 +97,23 @@ pdf_file_handle pdf_create (char *filename)
pdf_set_dict_entry (pdf_file->catalog, "PageLayout", pdf_new_name ("SinglePage"));

pdf_file->info = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY));
pdf_set_info (pdf_file, "Producer", "tumble by Eric Smith -- http://tumble.brouhaha.com/");
pdf_set_info (pdf_file, "Producer", PDF_PRODUCER);

/* Generate CreationDate and ModDate */

current_time = time (NULL);
time_and_date = gmtime (&current_time);
adjusted_time = mktime (time_and_date);
gmt_diff = (int) difftime (current_time, adjusted_time);

time_and_date = localtime (&current_time);

if (strftime (tm_string, sizeof (tm_string), tm_format, time_and_date))
{
sprintf (gmt_string, "%s%+03d'%02d'", tm_string, gmt_diff / 3600, gmt_diff % 60);
pdf_set_info (pdf_file, "CreationDate", gmt_string);
pdf_set_info (pdf_file, "ModDate", gmt_string);
}

pdf_file->trailer_dict = pdf_new_obj (PT_DICTIONARY);
/* Size key will be added later */
Expand Down
Loading

0 comments on commit 10c4f68

Please sign in to comment.