pdf_bookmark.c

Wed, 05 Mar 2003 20:44:33 +0000

author
eric
date
Wed, 05 Mar 2003 20:44:33 +0000
changeset 78
74b6b230f85d
parent 77
544fff830581
child 79
4cd9d23d924a
permissions
-rw-r--r--

correct copyright years on recently created source files.

     1 /*
     2  * t2p: Create a PDF file from the contents of one or more TIFF
     3  *      bilevel image files.  The images in the resulting PDF file
     4  *      will be compressed using ITU-T T.6 (G4) fax encoding.
     5  *
     6  * PDF routines
     7  * $Id: pdf_bookmark.c,v 1.4 2003/03/05 12:44:33 eric Exp $
     8  * Copyright 2003 Eric Smith <eric@brouhaha.com>
     9  *
    10  * This program is free software; you can redistribute it and/or modify
    11  * it under the terms of the GNU General Public License version 2 as
    12  * published by the Free Software Foundation.  Note that permission is
    13  * not granted to redistribute this program under the terms of any
    14  * other version of the General Public License.
    15  *
    16  * This program is distributed in the hope that it will be useful,
    17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19  * GNU General Public License for more details.
    20  *
    21  * You should have received a copy of the GNU General Public License
    22  * along with this program; if not, write to the Free Software
    23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
    24  */
    27 #include <stdbool.h>
    28 #include <stdint.h>
    29 #include <stdio.h>
    30 #include <stdlib.h>
    31 #include <string.h>
    34 #include "bitblt.h"
    35 #include "pdf.h"
    36 #include "pdf_util.h"
    37 #include "pdf_prim.h"
    38 #include "pdf_private.h"
    41 static void pdf_bookmark_update_count (pdf_bookmark_handle entry)
    42 {
    43   while (entry)
    44     {
    45       if (! entry->count)
    46 	{
    47 	  entry->count = pdf_new_integer (0);
    48 	  pdf_set_dict_entry (entry->dict, "Count", entry->count);
    49 	}
    50       pdf_set_integer (entry->count,
    51 		       pdf_get_integer (entry->count) +
    52 		       ((entry->open) ? 1 : -1));
    53       if (! entry->open)
    54 	break;
    55       entry = entry->parent;
    56     }
    57 }
    60 /* Create a new bookmark, under the specified parent, or at the top
    61    level if parent is NULL. */
    62 pdf_bookmark_handle pdf_new_bookmark (pdf_bookmark_handle parent,
    63 				      char *title,
    64 				      bool open,
    65 				      pdf_page_handle pdf_page)
    66 {
    67   pdf_file_handle pdf_file = pdf_page->pdf_file;
    68   struct pdf_bookmark *root;
    69   struct pdf_bookmark *entry;
    71   struct pdf_obj *dest_array;
    73   root = pdf_file->outline_root;
    74   if (! root)
    75     {
    76       root = pdf_calloc (1, sizeof (struct pdf_bookmark));
    77       root->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY));
    79       pdf_file->outline_root = root;
    80       pdf_set_dict_entry (pdf_file->catalog, "Outlines", root->dict);
    81     }
    83   entry = pdf_calloc (1, sizeof (struct pdf_bookmark));
    84   entry->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY));
    85   entry->open = open;
    87   pdf_set_dict_entry (entry->dict, "Title", pdf_new_string (title));
    89   dest_array = pdf_new_obj (PT_ARRAY);
    90   pdf_add_array_elem (dest_array, pdf_page->page_dict);
    91   pdf_add_array_elem (dest_array, pdf_new_name ("Fit"));
    92   pdf_set_dict_entry (entry->dict, "Dest", dest_array);
    94   if (parent)
    95     {
    96       entry->parent = parent;
    97       entry->prev = parent->last;
    98     }
    99   else
   100     {
   101       parent = root;
   102       entry->parent = root;
   103       entry->prev = root->last;
   104     }
   106   pdf_set_dict_entry (entry->dict, "Parent", parent->dict);
   108   if (entry->prev)
   109     {
   110       pdf_set_dict_entry (entry->dict, "Prev", entry->prev->dict);
   112       entry->prev->next = entry;
   113       pdf_set_dict_entry (entry->prev->dict, "Next", entry->dict);
   115       parent->last = entry;
   116       pdf_set_dict_entry (parent->dict, "Last", entry->dict);
   117     }
   118   else
   119     {
   120       parent->first = entry;
   121       pdf_set_dict_entry (parent->dict, "First", entry->dict);
   123       parent->last = entry;
   124       pdf_set_dict_entry (parent->dict, "Last", entry->dict);
   125     }
   127   pdf_bookmark_update_count (parent);
   129   return (entry);
   130 }