pdf_bookmark.c

Wed, 05 Mar 2003 02:26:43 +0000

author
eric
date
Wed, 05 Mar 2003 02:26:43 +0000
changeset 76
2129cfb36fcc
parent 74
12bc5088172e
child 77
544fff830581
permissions
-rw-r--r--

fixed Count for closed bookmarks, doesn't contribute to parent's Count.

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@76 7 * $Id: pdf_bookmark.c,v 1.2 2003/03/04 18:26:43 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@76 56 if (! entry->open)
eric@76 57 break;
eric@74 58 entry = entry->parent;
eric@74 59 }
eric@74 60 }
eric@74 61
eric@74 62
eric@74 63 /* Create a new bookmark, under the specified parent, or at the top
eric@74 64 level if parent is NULL. */
eric@74 65 pdf_bookmark_handle pdf_new_bookmark (pdf_bookmark_handle parent,
eric@74 66 char *title,
eric@74 67 bool open,
eric@74 68 pdf_page_handle pdf_page)
eric@74 69 {
eric@74 70 pdf_file_handle pdf_file = pdf_page->pdf_file;
eric@74 71 struct pdf_bookmark *root;
eric@74 72 struct pdf_bookmark *entry;
eric@74 73
eric@74 74 struct pdf_obj *dest_array;
eric@74 75
eric@74 76 root = pdf_file->outline_root;
eric@74 77 if (! root)
eric@74 78 {
eric@74 79 root = pdf_calloc (1, sizeof (struct pdf_bookmark));
eric@74 80 root->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY));
eric@74 81 pdf_set_dict_entry (root->dict, "Count", pdf_new_integer (0));
eric@74 82
eric@74 83 pdf_file->outline_root = root;
eric@74 84 pdf_set_dict_entry (pdf_file->catalog, "Outlines", root->dict);
eric@74 85 }
eric@74 86
eric@74 87 entry = pdf_calloc (1, sizeof (struct pdf_bookmark));
eric@74 88 entry->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY));
eric@74 89 entry->open = open;
eric@74 90
eric@74 91 pdf_set_dict_entry (entry->dict, "Title", pdf_new_string (title));
eric@74 92
eric@74 93 dest_array = pdf_new_obj (PT_ARRAY);
eric@74 94 pdf_add_array_elem (dest_array, pdf_page->page_dict);
eric@74 95 pdf_add_array_elem (dest_array, pdf_new_name ("Fit"));
eric@74 96 pdf_set_dict_entry (entry->dict, "Dest", dest_array);
eric@74 97
eric@74 98 if (parent)
eric@74 99 {
eric@74 100 entry->parent = parent;
eric@74 101 entry->prev = parent->last;
eric@74 102 }
eric@74 103 else
eric@74 104 {
eric@74 105 parent = root;
eric@74 106 entry->parent = root;
eric@74 107 entry->prev = root->last;
eric@74 108 }
eric@74 109
eric@74 110 pdf_set_dict_entry (entry->dict, "Parent", parent->dict);
eric@74 111
eric@74 112 if (entry->prev)
eric@74 113 {
eric@74 114 pdf_set_dict_entry (entry->dict, "Prev", entry->prev->dict);
eric@74 115
eric@74 116 entry->prev->next = entry;
eric@74 117 pdf_set_dict_entry (entry->prev->dict, "Next", entry->dict);
eric@74 118
eric@74 119 parent->last = entry;
eric@74 120 pdf_set_dict_entry (parent->dict, "Last", entry->dict);
eric@74 121 }
eric@74 122 else
eric@74 123 {
eric@74 124 parent->first = entry;
eric@74 125 pdf_set_dict_entry (parent->dict, "First", entry->dict);
eric@74 126
eric@74 127 parent->last = entry;
eric@74 128 pdf_set_dict_entry (parent->dict, "Last", entry->dict);
eric@74 129 }
eric@74 130
eric@74 131 pdf_bookmark_update_count (parent);
eric@74 132
eric@74 133 return (entry);
eric@74 134 }