pdf_bookmark.c

Wed, 05 Mar 2003 02:09:49 +0000

author
eric
date
Wed, 05 Mar 2003 02:09:49 +0000
changeset 75
29d7cbc7c251
parent 74
12bc5088172e
child 76
2129cfb36fcc
permissions
-rw-r--r--

Added support for PageMode.

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