Skip to content

Commit

Permalink
specify page mode when file is closed rather than when it is initiall…
Browse files Browse the repository at this point in the history
…y created. if USE_OUTLINES but no bookmarks, use USE_NONE instead.
  • Loading branch information
brouhaha committed Mar 14, 2003
1 parent 8c311a3 commit 04bbb05
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
42 changes: 26 additions & 16 deletions pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* PDF routines
* $Id: pdf.c,v 1.12 2003/03/14 00:24:37 eric Exp $
* $Id: pdf.c,v 1.13 2003/03/14 00:57:40 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -67,19 +67,9 @@ struct pdf_pages *pdf_new_pages (pdf_file_handle pdf_file)
}


pdf_file_handle pdf_create (char *filename, int page_mode)
pdf_file_handle pdf_create (char *filename)
{
pdf_file_handle pdf_file;
char *page_mode_string;

switch (page_mode)
{
case PDF_PAGE_MODE_USE_NONE: page_mode_string = "UseNone"; break;
case PDF_PAGE_MODE_USE_OUTLINES: page_mode_string = "UseOutlines"; break;
case PDF_PAGE_MODE_USE_THUMBS: page_mode_string = "UseThumbs"; break;
default:
pdf_fatal ("invalid page mode\n");
}

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

Expand All @@ -95,9 +85,6 @@ pdf_file_handle pdf_create (char *filename, int page_mode)
pdf_set_dict_entry (pdf_file->catalog, "Type", pdf_new_name ("Catalog"));
pdf_set_dict_entry (pdf_file->catalog, "Pages", pdf_file->root->pages_dict);
/* Outlines dictionary will be created later if needed */
pdf_set_dict_entry (pdf_file->catalog,
"PageMode",
pdf_new_name (page_mode_string));
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));
Expand All @@ -119,8 +106,31 @@ pdf_file_handle pdf_create (char *filename, int page_mode)
}


void pdf_close (pdf_file_handle pdf_file)
void pdf_close (pdf_file_handle pdf_file, int page_mode)
{
char *page_mode_string;

page_mode_string = "UseNone";

switch (page_mode)
{
case PDF_PAGE_MODE_USE_NONE:
break;
case PDF_PAGE_MODE_USE_OUTLINES:
if (pdf_file->outline_root)
page_mode_string = "UseOutlines";
break;
case PDF_PAGE_MODE_USE_THUMBS:
page_mode_string = "UseThumbs";
break;
default:
pdf_fatal ("invalid page mode\n");
}

pdf_set_dict_entry (pdf_file->catalog,
"PageMode",
pdf_new_name (page_mode_string));

/* finalize trees, object numbers aren't allocated until this step */
pdf_finalize_name_trees (pdf_file);

Expand Down
8 changes: 4 additions & 4 deletions pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* PDF routines
* $Id: pdf.h,v 1.10 2003/03/14 00:24:37 eric Exp $
* $Id: pdf.h,v 1.11 2003/03/14 00:57:40 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -30,15 +30,15 @@ typedef struct pdf_bookmark *pdf_bookmark_handle;


#define PDF_PAGE_MODE_USE_NONE 0
#define PDF_PAGE_MODE_USE_OUTLINES 1
#define PDF_PAGE_MODE_USE_OUTLINES 1 /* if no outlines, will use NONE */
#define PDF_PAGE_MODE_USE_THUMBS 2 /* not yet implemented */


void pdf_init (void);

pdf_file_handle pdf_create (char *filename, int page_mode);
pdf_file_handle pdf_create (char *filename);

void pdf_close (pdf_file_handle pdf_file);
void pdf_close (pdf_file_handle pdf_file, int page_mode);

void pdf_set_author (pdf_file_handle pdf_file, char *author);
void pdf_set_creator (pdf_file_handle pdf_file, char *author);
Expand Down
10 changes: 3 additions & 7 deletions tumble.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* tumble: build a PDF file from image files
*
* Main program
* $Id: tumble.c,v 1.34 2003/03/14 00:24:37 eric Exp $
* $Id: tumble.c,v 1.35 2003/03/14 00:57:40 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -159,7 +159,7 @@ bool close_pdf_output_files (void)
for (o = output_files; o; o = n)
{
n = o->next;
pdf_close (o->pdf);
pdf_close (o->pdf, PDF_PAGE_MODE_USE_OUTLINES);
free (o->name);
free (o);
}
Expand Down Expand Up @@ -196,9 +196,7 @@ bool open_pdf_output_file (char *name,
return (0);
}

o->pdf = pdf_create (name, (attributes->has_bookmarks ?
PDF_PAGE_MODE_USE_OUTLINES :
PDF_PAGE_MODE_USE_NONE));
o->pdf = pdf_create (name);
if (! o->pdf)
{
fprintf (stderr, "can't open output file '%s'\n", name);
Expand Down Expand Up @@ -606,8 +604,6 @@ void main_args (char *out_fn,
memset (& input_attributes, 0, sizeof (input_attributes));
memset (& output_attributes, 0, sizeof (output_attributes));

output_attributes.has_bookmarks = (bookmark_fmt != NULL);

if (! open_pdf_output_file (out_fn, & output_attributes))
fatal (3, "error opening output file \"%s\"\n", out_fn);
for (i = 0; i < inf_count; i++)
Expand Down
3 changes: 1 addition & 2 deletions tumble.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* tumble: build a PDF file from image files
*
* $Id: tumble.h,v 1.14 2003/03/14 00:24:37 eric Exp $
* $Id: tumble.h,v 1.15 2003/03/14 00:57:40 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -50,7 +50,6 @@ typedef struct
char *title;
char *subject;
char *keywords;
bool has_bookmarks;
} pdf_file_attributes_t;

bool open_pdf_output_file (char *name,
Expand Down

0 comments on commit 04bbb05

Please sign in to comment.