1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/pdf_bookmark.c Wed Mar 05 01:58:36 2003 +0000 1.3 @@ -0,0 +1,132 @@ 1.4 +/* 1.5 + * t2p: Create a PDF file from the contents of one or more TIFF 1.6 + * bilevel image files. The images in the resulting PDF file 1.7 + * will be compressed using ITU-T T.6 (G4) fax encoding. 1.8 + * 1.9 + * PDF routines 1.10 + * $Id: pdf_bookmark.c,v 1.1 2003/03/04 17:58:36 eric Exp $ 1.11 + * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 1.12 + * 1.13 + * This program is free software; you can redistribute it and/or modify 1.14 + * it under the terms of the GNU General Public License version 2 as 1.15 + * published by the Free Software Foundation. Note that permission is 1.16 + * not granted to redistribute this program under the terms of any 1.17 + * other version of the General Public License. 1.18 + * 1.19 + * This program is distributed in the hope that it will be useful, 1.20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.22 + * GNU General Public License for more details. 1.23 + * 1.24 + * You should have received a copy of the GNU General Public License 1.25 + * along with this program; if not, write to the Free Software 1.26 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 1.27 + */ 1.28 + 1.29 + 1.30 +#include <stdbool.h> 1.31 +#include <stdint.h> 1.32 +#include <stdio.h> 1.33 +#include <stdlib.h> 1.34 +#include <string.h> 1.35 + 1.36 + 1.37 +#include "bitblt.h" 1.38 +#include "pdf.h" 1.39 +#include "pdf_util.h" 1.40 +#include "pdf_prim.h" 1.41 +#include "pdf_private.h" 1.42 + 1.43 + 1.44 +static void pdf_bookmark_update_count (pdf_bookmark_handle entry) 1.45 +{ 1.46 + struct pdf_obj *count_obj; 1.47 + 1.48 + while (entry) 1.49 + { 1.50 + count_obj = pdf_get_dict_entry (entry->dict, "Count"); 1.51 + if (! count_obj) 1.52 + { 1.53 + count_obj = pdf_new_integer (0); 1.54 + pdf_set_dict_entry (entry->dict, "Count", count_obj); 1.55 + } 1.56 + pdf_set_integer (count_obj, 1.57 + pdf_get_integer (count_obj) + 1.58 + ((entry->open) ? 1 : -1)); 1.59 + entry = entry->parent; 1.60 + } 1.61 +} 1.62 + 1.63 + 1.64 +/* Create a new bookmark, under the specified parent, or at the top 1.65 + level if parent is NULL. */ 1.66 +pdf_bookmark_handle pdf_new_bookmark (pdf_bookmark_handle parent, 1.67 + char *title, 1.68 + bool open, 1.69 + pdf_page_handle pdf_page) 1.70 +{ 1.71 + pdf_file_handle pdf_file = pdf_page->pdf_file; 1.72 + struct pdf_bookmark *root; 1.73 + struct pdf_bookmark *entry; 1.74 + 1.75 + struct pdf_obj *dest_array; 1.76 + 1.77 + root = pdf_file->outline_root; 1.78 + if (! root) 1.79 + { 1.80 + root = pdf_calloc (1, sizeof (struct pdf_bookmark)); 1.81 + root->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY)); 1.82 + pdf_set_dict_entry (root->dict, "Count", pdf_new_integer (0)); 1.83 + 1.84 + pdf_file->outline_root = root; 1.85 + pdf_set_dict_entry (pdf_file->catalog, "Outlines", root->dict); 1.86 + } 1.87 + 1.88 + entry = pdf_calloc (1, sizeof (struct pdf_bookmark)); 1.89 + entry->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY)); 1.90 + entry->open = open; 1.91 + 1.92 + pdf_set_dict_entry (entry->dict, "Title", pdf_new_string (title)); 1.93 + 1.94 + dest_array = pdf_new_obj (PT_ARRAY); 1.95 + pdf_add_array_elem (dest_array, pdf_page->page_dict); 1.96 + pdf_add_array_elem (dest_array, pdf_new_name ("Fit")); 1.97 + pdf_set_dict_entry (entry->dict, "Dest", dest_array); 1.98 + 1.99 + if (parent) 1.100 + { 1.101 + entry->parent = parent; 1.102 + entry->prev = parent->last; 1.103 + } 1.104 + else 1.105 + { 1.106 + parent = root; 1.107 + entry->parent = root; 1.108 + entry->prev = root->last; 1.109 + } 1.110 + 1.111 + pdf_set_dict_entry (entry->dict, "Parent", parent->dict); 1.112 + 1.113 + if (entry->prev) 1.114 + { 1.115 + pdf_set_dict_entry (entry->dict, "Prev", entry->prev->dict); 1.116 + 1.117 + entry->prev->next = entry; 1.118 + pdf_set_dict_entry (entry->prev->dict, "Next", entry->dict); 1.119 + 1.120 + parent->last = entry; 1.121 + pdf_set_dict_entry (parent->dict, "Last", entry->dict); 1.122 + } 1.123 + else 1.124 + { 1.125 + parent->first = entry; 1.126 + pdf_set_dict_entry (parent->dict, "First", entry->dict); 1.127 + 1.128 + parent->last = entry; 1.129 + pdf_set_dict_entry (parent->dict, "Last", entry->dict); 1.130 + } 1.131 + 1.132 + pdf_bookmark_update_count (parent); 1.133 + 1.134 + return (entry); 1.135 +}