pdf_bookmark.c

Wed, 12 Mar 2003 10:59:09 +0000

author
eric
date
Wed, 12 Mar 2003 10:59:09 +0000
changeset 109
663da96ad2bc
parent 79
4cd9d23d924a
child 125
e2ef1c2f9eca
permissions
-rw-r--r--

changed word_type to word_t.

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@79 7 * $Id: pdf_bookmark.c,v 1.5 2003/03/05 12:56:25 eric Exp $
eric@78 8 * Copyright 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@79 41 struct pdf_bookmark
eric@79 42 {
eric@79 43 struct pdf_obj *dict; /* indirect reference */
eric@79 44 struct pdf_obj *count;
eric@79 45 bool open;
eric@79 46
eric@79 47 struct pdf_bookmark *first;
eric@79 48 struct pdf_bookmark *last;
eric@79 49
eric@79 50 /* the following fields don't appear in the root */
eric@79 51 /* title and dest are in the dictionary but don't have
eric@79 52 explicit fields in the C structure */
eric@79 53 struct pdf_bookmark *parent;
eric@79 54 struct pdf_bookmark *prev;
eric@79 55 struct pdf_bookmark *next;
eric@79 56 };
eric@79 57
eric@79 58
eric@74 59 static void pdf_bookmark_update_count (pdf_bookmark_handle entry)
eric@74 60 {
eric@74 61 while (entry)
eric@74 62 {
eric@77 63 if (! entry->count)
eric@74 64 {
eric@77 65 entry->count = pdf_new_integer (0);
eric@77 66 pdf_set_dict_entry (entry->dict, "Count", entry->count);
eric@74 67 }
eric@77 68 pdf_set_integer (entry->count,
eric@77 69 pdf_get_integer (entry->count) +
eric@74 70 ((entry->open) ? 1 : -1));
eric@76 71 if (! entry->open)
eric@76 72 break;
eric@74 73 entry = entry->parent;
eric@74 74 }
eric@74 75 }
eric@74 76
eric@74 77
eric@74 78 /* Create a new bookmark, under the specified parent, or at the top
eric@74 79 level if parent is NULL. */
eric@74 80 pdf_bookmark_handle pdf_new_bookmark (pdf_bookmark_handle parent,
eric@74 81 char *title,
eric@74 82 bool open,
eric@74 83 pdf_page_handle pdf_page)
eric@74 84 {
eric@74 85 pdf_file_handle pdf_file = pdf_page->pdf_file;
eric@74 86 struct pdf_bookmark *root;
eric@74 87 struct pdf_bookmark *entry;
eric@74 88
eric@74 89 struct pdf_obj *dest_array;
eric@74 90
eric@74 91 root = pdf_file->outline_root;
eric@74 92 if (! root)
eric@74 93 {
eric@74 94 root = pdf_calloc (1, sizeof (struct pdf_bookmark));
eric@74 95 root->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY));
eric@74 96
eric@74 97 pdf_file->outline_root = root;
eric@74 98 pdf_set_dict_entry (pdf_file->catalog, "Outlines", root->dict);
eric@74 99 }
eric@74 100
eric@74 101 entry = pdf_calloc (1, sizeof (struct pdf_bookmark));
eric@74 102 entry->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY));
eric@74 103 entry->open = open;
eric@74 104
eric@74 105 pdf_set_dict_entry (entry->dict, "Title", pdf_new_string (title));
eric@74 106
eric@74 107 dest_array = pdf_new_obj (PT_ARRAY);
eric@74 108 pdf_add_array_elem (dest_array, pdf_page->page_dict);
eric@74 109 pdf_add_array_elem (dest_array, pdf_new_name ("Fit"));
eric@74 110 pdf_set_dict_entry (entry->dict, "Dest", dest_array);
eric@74 111
eric@74 112 if (parent)
eric@74 113 {
eric@74 114 entry->parent = parent;
eric@74 115 entry->prev = parent->last;
eric@74 116 }
eric@74 117 else
eric@74 118 {
eric@74 119 parent = root;
eric@74 120 entry->parent = root;
eric@74 121 entry->prev = root->last;
eric@74 122 }
eric@74 123
eric@74 124 pdf_set_dict_entry (entry->dict, "Parent", parent->dict);
eric@74 125
eric@74 126 if (entry->prev)
eric@74 127 {
eric@74 128 pdf_set_dict_entry (entry->dict, "Prev", entry->prev->dict);
eric@74 129
eric@74 130 entry->prev->next = entry;
eric@74 131 pdf_set_dict_entry (entry->prev->dict, "Next", entry->dict);
eric@74 132
eric@74 133 parent->last = entry;
eric@74 134 pdf_set_dict_entry (parent->dict, "Last", entry->dict);
eric@74 135 }
eric@74 136 else
eric@74 137 {
eric@74 138 parent->first = entry;
eric@74 139 pdf_set_dict_entry (parent->dict, "First", entry->dict);
eric@74 140
eric@74 141 parent->last = entry;
eric@74 142 pdf_set_dict_entry (parent->dict, "Last", entry->dict);
eric@74 143 }
eric@74 144
eric@74 145 pdf_bookmark_update_count (parent);
eric@74 146
eric@74 147 return (entry);
eric@74 148 }