Skip to content

Commit

Permalink
replaced page_number_format with page_label matching how PDF names
Browse files Browse the repository at this point in the history
and stores them.
  • Loading branch information
brouhaha committed Dec 31, 2001
1 parent 7ea2d3c commit 504bb09
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 28 deletions.
91 changes: 82 additions & 9 deletions semantics.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "type.h"
#include "semantics.h"
#include "parser.tab.h"
#include "tiff2pdf.h"


typedef struct
Expand Down Expand Up @@ -53,7 +54,9 @@ typedef struct output_context_t
char *output_file;
bookmark_t *first_bookmark;
bookmark_t *last_bookmark;
char *page_number_format;

boolean has_page_label;
page_label_t page_label;
} output_context_t;


Expand Down Expand Up @@ -312,10 +315,11 @@ void output_set_bookmark (char *name)
last_output_context->last_bookmark = new_bookmark;
}

void output_set_page_number_format (char *format)
void output_set_page_label (page_label_t label)
{
output_clone ();
last_output_context->page_number_format = format;
last_output_context->has_page_label = 1;
last_output_context->page_label = label;
}

static void increment_output_page_count (int count)
Expand Down Expand Up @@ -408,11 +412,11 @@ static char *get_output_file (output_context_t *context)
exit (2);
}

static char *get_output_page_number_format (output_context_t *context)
static page_label_t *get_output_page_label (output_context_t *context)
{
for (; context; context = context->parent)
if (context->page_number_format)
return (context->page_number_format);
if (context->has_page_label)
return (& context->page_label);
return (NULL); /* default */
}

Expand Down Expand Up @@ -447,18 +451,87 @@ void dump_output_tree (void)
if (page->bookmark_list)
{
for (bookmark = page->bookmark_list; bookmark; bookmark = bookmark->next)
printf ("bookmark %d '%s'\n", bookmark->level, bookmark->name);
printf ("bookmark %d \"%s\"\n", bookmark->level, bookmark->name);
}
for (i = page->range.first; i <= page->range.last; i++)
{
printf ("file '%s' ", get_output_file (page->output_context));
printf ("format '%s' ", get_output_page_number_format (page->output_context));
page_label_t *label = get_output_page_label (page->output_context);
printf ("file \"%s\" ", get_output_file (page->output_context));
if (label)
{
printf ("label ");
if (label->prefix)
printf ("\"%s\" ", label->prefix);
if (label->style)
printf ("'%c' ", label->style);
}
printf ("page %d\n", i);
}
}
}
#endif /* SEMANTIC_DEBUG */


static inline int range_count (range_t range)
{
return ((range.last - range.first) + 1);
}


void doit (void)
{
input_image_t *image = NULL;
output_page_t *page = NULL;
int i = 0;
int p = 0;
int page_index = 0;
input_attributes_t input_attributes;
input_modifier_type_t parity;
page_label_t *page_label;

for (;;)
{
if ((! image) || (i >= range_count (image->range)))
{
if (image)
image = image->next;
else
image = first_input_image;
if (! image)
return;
i = 0;
}

if ((! page) || (p >= range_count (page->range)))
{
if (page)
page = page->next;
else
page = first_output_page;
p = 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;

memset (& input_attributes, 0, sizeof (input_attributes));
input_attributes.rotation = get_input_rotation (image->input_context,
parity);;

process_page (image->range.first + i,
input_attributes,
page->bookmark_list);
i++;
p++;
page_index++;
}
}


boolean parse_spec_file (char *fn)
{
boolean result = 0;
Expand Down
8 changes: 7 additions & 1 deletion semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ typedef struct
double bottom;
} crop_t;

typedef struct
{
char *prefix;
char style;
} page_label_t;


typedef enum
{
Expand Down Expand Up @@ -56,5 +62,5 @@ void output_push_context (void);
void output_pop_context (void);
void output_set_file (char *name);
void output_set_bookmark (char *name);
void output_set_page_number_format (char *format);
void output_set_page_label (page_label_t label);
void output_pages (range_t range);
12 changes: 10 additions & 2 deletions t2p.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4
* Main program
* $Id: t2p.c,v 1.6 2001/12/31 00:25:04 eric Exp $
* $Id: t2p.c,v 1.7 2001/12/31 08:44:24 eric Exp $
* Copyright 2001 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -80,9 +80,17 @@ boolean open_pdf_output_file (char *name)
}


void process_page_numbers (int page_index,
int count,
int base,
page_label_t *page_label)
{
}


boolean process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
output_attributes_t output_attributes)
bookmark_t *bookmarks)
{
u32 image_length, image_width;
#ifdef CHECK_DEPTH
Expand Down
13 changes: 6 additions & 7 deletions t2p.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ typedef struct
crop_t crop;
} input_attributes_t;

typedef struct
{
char *page_number;
bookmark_t *bookmarks;
} output_attributes_t;

boolean open_tiff_input_file (char *name);
boolean close_tiff_input_file (void);

boolean open_pdf_output_file (char *name);
boolean close_pdf_output_file (void);

void process_page_numbers (int page_index,
int count,
int base,
page_label_t *page_label);

boolean process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
output_attributes_t output_attributes);
bookmark_t *bookmarks);
12 changes: 10 additions & 2 deletions tumble.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4
* Main program
* $Id: tumble.c,v 1.6 2001/12/31 00:25:04 eric Exp $
* $Id: tumble.c,v 1.7 2001/12/31 08:44:24 eric Exp $
* Copyright 2001 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -80,9 +80,17 @@ boolean open_pdf_output_file (char *name)
}


void process_page_numbers (int page_index,
int count,
int base,
page_label_t *page_label)
{
}


boolean process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
output_attributes_t output_attributes)
bookmark_t *bookmarks)
{
u32 image_length, image_width;
#ifdef CHECK_DEPTH
Expand Down
13 changes: 6 additions & 7 deletions tumble.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ typedef struct
crop_t crop;
} input_attributes_t;

typedef struct
{
char *page_number;
bookmark_t *bookmarks;
} output_attributes_t;

boolean open_tiff_input_file (char *name);
boolean close_tiff_input_file (void);

boolean open_pdf_output_file (char *name);
boolean close_pdf_output_file (void);

void process_page_numbers (int page_index,
int count,
int base,
page_label_t *page_label);

boolean process_page (int image, /* range 1 .. n */
input_attributes_t input_attributes,
output_attributes_t output_attributes);
bookmark_t *bookmarks);

0 comments on commit 504bb09

Please sign in to comment.