add support for PDF file attributes: author, creator, title, etc.

Tue, 01 Jan 2002 06:11:43 +0000

author
eric
date
Tue, 01 Jan 2002 06:11:43 +0000
changeset 30
35fad7ec7732
parent 29
c904ffd6a1cf
child 31
2cec996b38bc

add support for PDF file attributes: author, creator, title, etc.

parser.y file | annotate | diff | revisions
scanner.l file | annotate | diff | revisions
semantics.c file | annotate | diff | revisions
semantics.h file | annotate | diff | revisions
t2p.c file | annotate | diff | revisions
t2p.h file | annotate | diff | revisions
tumble.c file | annotate | diff | revisions
tumble.h file | annotate | diff | revisions
     1.1 diff -r c904ffd6a1cf -r 35fad7ec7732 parser.y
     1.2 --- a/parser.y	Tue Jan 01 05:41:03 2002 +0000
     1.3 +++ b/parser.y	Tue Jan 01 06:11:43 2002 +0000
     1.4 @@ -47,6 +47,12 @@
     1.5  %token BOOKMARK
     1.6  %token OUTPUT
     1.7  
     1.8 +%token AUTHOR
     1.9 +%token CREATOR
    1.10 +%token TITLE
    1.11 +%token SUBJECT
    1.12 +%token KEYWORDS
    1.13 +
    1.14  %type <range> range
    1.15  %type <range> image_ranges
    1.16  %type <range> page_ranges
    1.17 @@ -151,8 +157,21 @@
    1.18  input_statement:
    1.19  	INPUT input_clauses ;
    1.20  
    1.21 +pdf_file_attribute:
    1.22 +	AUTHOR STRING { output_set_author ($2); }
    1.23 +	| CREATOR STRING { output_set_creator ($2); }
    1.24 +	| TITLE STRING { output_set_title ($2); }
    1.25 +	| SUBJECT STRING { output_set_subject ($2); }
    1.26 +	| KEYWORDS STRING { output_set_keywords ($2); } ;
    1.27 +
    1.28 +pdf_file_attributes:
    1.29 +	/* empty */
    1.30 +	| pdf_file_attribute
    1.31 +	| pdf_file_attributes pdf_file_attribute ;
    1.32 +
    1.33  output_file_clause:
    1.34 -	FILE_KEYWORD STRING  ';' { output_set_file ($2) } ;
    1.35 +	FILE_KEYWORD STRING { output_set_file ($2); }
    1.36 +	pdf_file_attributes ';'
    1.37  
    1.38  label_clause:
    1.39  	LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
     2.1 diff -r c904ffd6a1cf -r 35fad7ec7732 scanner.l
     2.2 --- a/scanner.l	Tue Jan 01 05:41:03 2002 +0000
     2.3 +++ b/scanner.l	Tue Jan 01 06:11:43 2002 +0000
     2.4 @@ -1,5 +1,5 @@
     2.5  /*
     2.6 -$Id: scanner.l,v 1.12 2001/12/31 19:46:08 eric Exp $
     2.7 +$Id: scanner.l,v 1.13 2001/12/31 22:11:43 eric Exp $
     2.8  */
     2.9  
    2.10  %option case-insensitive
    2.11 @@ -49,8 +49,10 @@
    2.12                    return (PAGE_SIZE); }
    2.13  
    2.14  all		{ return (ALL); }
    2.15 +author		{ return (AUTHOR); }
    2.16  bookmark	{ return (BOOKMARK); }
    2.17  cm		{ return (CM); }
    2.18 +creator		{ return (CREATOR); }
    2.19  crop		{ return (CROP); }
    2.20  even		{ return (EVEN); }
    2.21  file		{ return (FILE_KEYWORD); }
    2.22 @@ -58,6 +60,7 @@
    2.23  images		{ return (IMAGES); }
    2.24  inch		{ return (INCH); }
    2.25  input		{ return (INPUT); }
    2.26 +keywords	{ return (KEYWORDS); }
    2.27  label		{ return (LABEL); }
    2.28  landscape	{ return (LANDSCAPE); }
    2.29  odd		{ return (ODD); }
    2.30 @@ -68,6 +71,8 @@
    2.31  resolution	{ return (RESOLUTION) ; }
    2.32  rotate		{ return (ROTATE); }
    2.33  size		{ return (SIZE); }
    2.34 +subject		{ return (SUBJECT); }
    2.35 +title		{ return (TITLE); }
    2.36  
    2.37  '[^\n']'	{
    2.38  		  yylval.character = yytext [1];
     3.1 diff -r c904ffd6a1cf -r 35fad7ec7732 semantics.c
     3.2 --- a/semantics.c	Tue Jan 01 05:41:03 2002 +0000
     3.3 +++ b/semantics.c	Tue Jan 01 06:11:43 2002 +0000
     3.4 @@ -52,6 +52,8 @@
     3.5  		      including those from subcontexts */
     3.6  
     3.7    char *output_file;
     3.8 +  pdf_file_attributes_t file_attributes;
     3.9 +
    3.10    bookmark_t *first_bookmark;
    3.11    bookmark_t *last_bookmark;
    3.12  
    3.13 @@ -285,8 +287,38 @@
    3.14  {
    3.15    output_clone ();
    3.16    last_output_context->output_file = name;
    3.17 +  last_output_context->file_attributes.author = NULL;
    3.18 +  last_output_context->file_attributes.creator = NULL;
    3.19 +  last_output_context->file_attributes.title = NULL;
    3.20 +  last_output_context->file_attributes.subject = NULL;
    3.21 +  last_output_context->file_attributes.keywords = NULL;
    3.22  };
    3.23  
    3.24 +void output_set_author (char *author)
    3.25 +{
    3.26 +  last_output_context->file_attributes.author = author;
    3.27 +}
    3.28 +
    3.29 +void output_set_creator (char *creator)
    3.30 +{
    3.31 +  last_output_context->file_attributes.creator = creator;
    3.32 +}
    3.33 +
    3.34 +void output_set_title (char *title)
    3.35 +{
    3.36 +  last_output_context->file_attributes.title = title;
    3.37 +}
    3.38 +
    3.39 +void output_set_subject (char *subject)
    3.40 +{
    3.41 +  last_output_context->file_attributes.subject = subject;
    3.42 +}
    3.43 +
    3.44 +void output_set_keywords (char *keywords)
    3.45 +{
    3.46 +  last_output_context->file_attributes.keywords = keywords;
    3.47 +}
    3.48 +
    3.49  void output_set_bookmark (char *name)
    3.50  {
    3.51    bookmark_t *new_bookmark;
    3.52 @@ -408,7 +440,16 @@
    3.53    for (; context; context = context->parent)
    3.54      if (context->output_file)
    3.55        return (context->output_file);
    3.56 -  fprintf (stderr, "no output file name found\n");
    3.57 +  fprintf (stderr, "no output file found\n");
    3.58 +  exit (2);
    3.59 +}
    3.60 +
    3.61 +static pdf_file_attributes_t *get_output_file_attributes (output_context_t *context)
    3.62 +{
    3.63 +  for (; context; context = context->parent)
    3.64 +    if (context->output_file)
    3.65 +      return (& context->file_attributes);
    3.66 +  fprintf (stderr, "no output file found\n");
    3.67    exit (2);
    3.68  }
    3.69  
    3.70 @@ -557,7 +598,8 @@
    3.71  	  else
    3.72  	    page = first_output_page;
    3.73  	  p = 0;
    3.74 -	  if (! open_pdf_output_file (get_output_file (page->output_context)))
    3.75 +	  if (! open_pdf_output_file (get_output_file (page->output_context),
    3.76 +				      get_output_file_attributes (page->output_context)))
    3.77  	    return (0);
    3.78  	  page_label = get_output_page_label (page->output_context);
    3.79  	  process_page_numbers (page_index,
     4.1 diff -r c904ffd6a1cf -r 35fad7ec7732 semantics.h
     4.2 --- a/semantics.h	Tue Jan 01 05:41:03 2002 +0000
     4.3 +++ b/semantics.h	Tue Jan 01 06:11:43 2002 +0000
     4.4 @@ -57,7 +57,14 @@
     4.5  /* semantic routines for output statements */
     4.6  void output_push_context (void);
     4.7  void output_pop_context (void);
     4.8 +
     4.9  void output_set_file (char *name);
    4.10 +void output_set_author (char *author);
    4.11 +void output_set_creator (char *creator);
    4.12 +void output_set_title (char *title);
    4.13 +void output_set_subject (char *subject);
    4.14 +void output_set_keywords (char *keywords);
    4.15 +
    4.16  void output_set_bookmark (char *name);
    4.17  void output_set_page_label (page_label_t label);
    4.18  void output_pages (range_t range);
     5.1 diff -r c904ffd6a1cf -r 35fad7ec7732 t2p.c
     5.2 --- a/t2p.c	Tue Jan 01 05:41:03 2002 +0000
     5.3 +++ b/t2p.c	Tue Jan 01 06:11:43 2002 +0000
     5.4 @@ -5,7 +5,7 @@
     5.5   *           encoding.
     5.6   *
     5.7   * Main program
     5.8 - * $Id: t2p.c,v 1.10 2001/12/31 21:41:03 eric Exp $
     5.9 + * $Id: t2p.c,v 1.11 2001/12/31 22:11:43 eric Exp $
    5.10   * Copyright 2001 Eric Smith <eric@brouhaha.com>
    5.11   *
    5.12   * This program is free software; you can redistribute it and/or modify
    5.13 @@ -114,7 +114,8 @@
    5.14    return (1);
    5.15  }
    5.16  
    5.17 -boolean open_pdf_output_file (char *name)
    5.18 +boolean open_pdf_output_file (char *name,
    5.19 +			      pdf_file_attributes_t *attributes)
    5.20  {
    5.21    output_file_t *o;
    5.22  
    5.23 @@ -150,6 +151,17 @@
    5.24        return (0);
    5.25      }
    5.26  
    5.27 +  if (attributes->author)
    5.28 +    panda_setauthor (o->pdf, attributes->author);
    5.29 +  if (attributes->creator)
    5.30 +    panda_setcreator (o->pdf, attributes->creator);
    5.31 +  if (attributes->title)
    5.32 +    panda_settitle (o->pdf, attributes->title);
    5.33 +  if (attributes->subject)
    5.34 +    panda_setsubject (o->pdf, attributes->subject);
    5.35 +  if (attributes->keywords)
    5.36 +    panda_setkeywords (o->pdf, attributes->keywords);
    5.37 +
    5.38    /* prepend new output file onto list */
    5.39    o->next = output_files;
    5.40    output_files = o;
     6.1 diff -r c904ffd6a1cf -r 35fad7ec7732 t2p.h
     6.2 --- a/t2p.h	Tue Jan 01 05:41:03 2002 +0000
     6.3 +++ b/t2p.h	Tue Jan 01 06:11:43 2002 +0000
     6.4 @@ -8,7 +8,19 @@
     6.5  boolean open_tiff_input_file (char *name);
     6.6  boolean close_tiff_input_file (void);
     6.7  
     6.8 -boolean open_pdf_output_file (char *name);
     6.9 +
    6.10 +typedef struct
    6.11 +{
    6.12 +  char *author;
    6.13 +  char *creator;
    6.14 +  char *title;
    6.15 +  char *subject;
    6.16 +  char *keywords;
    6.17 +} pdf_file_attributes_t;
    6.18 +
    6.19 +boolean open_pdf_output_file (char *name,
    6.20 +			      pdf_file_attributes_t *attributes);
    6.21 +
    6.22  
    6.23  void process_page_numbers (int page_index,
    6.24  			   int count,
     7.1 diff -r c904ffd6a1cf -r 35fad7ec7732 tumble.c
     7.2 --- a/tumble.c	Tue Jan 01 05:41:03 2002 +0000
     7.3 +++ b/tumble.c	Tue Jan 01 06:11:43 2002 +0000
     7.4 @@ -5,7 +5,7 @@
     7.5   *           encoding.
     7.6   *
     7.7   * Main program
     7.8 - * $Id: tumble.c,v 1.10 2001/12/31 21:41:03 eric Exp $
     7.9 + * $Id: tumble.c,v 1.11 2001/12/31 22:11:43 eric Exp $
    7.10   * Copyright 2001 Eric Smith <eric@brouhaha.com>
    7.11   *
    7.12   * This program is free software; you can redistribute it and/or modify
    7.13 @@ -114,7 +114,8 @@
    7.14    return (1);
    7.15  }
    7.16  
    7.17 -boolean open_pdf_output_file (char *name)
    7.18 +boolean open_pdf_output_file (char *name,
    7.19 +			      pdf_file_attributes_t *attributes)
    7.20  {
    7.21    output_file_t *o;
    7.22  
    7.23 @@ -150,6 +151,17 @@
    7.24        return (0);
    7.25      }
    7.26  
    7.27 +  if (attributes->author)
    7.28 +    panda_setauthor (o->pdf, attributes->author);
    7.29 +  if (attributes->creator)
    7.30 +    panda_setcreator (o->pdf, attributes->creator);
    7.31 +  if (attributes->title)
    7.32 +    panda_settitle (o->pdf, attributes->title);
    7.33 +  if (attributes->subject)
    7.34 +    panda_setsubject (o->pdf, attributes->subject);
    7.35 +  if (attributes->keywords)
    7.36 +    panda_setkeywords (o->pdf, attributes->keywords);
    7.37 +
    7.38    /* prepend new output file onto list */
    7.39    o->next = output_files;
    7.40    output_files = o;
     8.1 diff -r c904ffd6a1cf -r 35fad7ec7732 tumble.h
     8.2 --- a/tumble.h	Tue Jan 01 05:41:03 2002 +0000
     8.3 +++ b/tumble.h	Tue Jan 01 06:11:43 2002 +0000
     8.4 @@ -8,7 +8,19 @@
     8.5  boolean open_tiff_input_file (char *name);
     8.6  boolean close_tiff_input_file (void);
     8.7  
     8.8 -boolean open_pdf_output_file (char *name);
     8.9 +
    8.10 +typedef struct
    8.11 +{
    8.12 +  char *author;
    8.13 +  char *creator;
    8.14 +  char *title;
    8.15 +  char *subject;
    8.16 +  char *keywords;
    8.17 +} pdf_file_attributes_t;
    8.18 +
    8.19 +boolean open_pdf_output_file (char *name,
    8.20 +			      pdf_file_attributes_t *attributes);
    8.21 +
    8.22  
    8.23  void process_page_numbers (int page_index,
    8.24  			   int count,