Wed, 05 Mar 2003 20:44:33 +0000
correct copyright years on recently created source files.
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@78 | 7 | * $Id: pdf_bookmark.c,v 1.4 2003/03/05 12:44:33 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@74 | 41 | static void pdf_bookmark_update_count (pdf_bookmark_handle entry) |
eric@74 | 42 | { |
eric@74 | 43 | while (entry) |
eric@74 | 44 | { |
eric@77 | 45 | if (! entry->count) |
eric@74 | 46 | { |
eric@77 | 47 | entry->count = pdf_new_integer (0); |
eric@77 | 48 | pdf_set_dict_entry (entry->dict, "Count", entry->count); |
eric@74 | 49 | } |
eric@77 | 50 | pdf_set_integer (entry->count, |
eric@77 | 51 | pdf_get_integer (entry->count) + |
eric@74 | 52 | ((entry->open) ? 1 : -1)); |
eric@76 | 53 | if (! entry->open) |
eric@76 | 54 | break; |
eric@74 | 55 | entry = entry->parent; |
eric@74 | 56 | } |
eric@74 | 57 | } |
eric@74 | 58 | |
eric@74 | 59 | |
eric@74 | 60 | /* Create a new bookmark, under the specified parent, or at the top |
eric@74 | 61 | level if parent is NULL. */ |
eric@74 | 62 | pdf_bookmark_handle pdf_new_bookmark (pdf_bookmark_handle parent, |
eric@74 | 63 | char *title, |
eric@74 | 64 | bool open, |
eric@74 | 65 | pdf_page_handle pdf_page) |
eric@74 | 66 | { |
eric@74 | 67 | pdf_file_handle pdf_file = pdf_page->pdf_file; |
eric@74 | 68 | struct pdf_bookmark *root; |
eric@74 | 69 | struct pdf_bookmark *entry; |
eric@74 | 70 | |
eric@74 | 71 | struct pdf_obj *dest_array; |
eric@74 | 72 | |
eric@74 | 73 | root = pdf_file->outline_root; |
eric@74 | 74 | if (! root) |
eric@74 | 75 | { |
eric@74 | 76 | root = pdf_calloc (1, sizeof (struct pdf_bookmark)); |
eric@74 | 77 | root->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY)); |
eric@74 | 78 | |
eric@74 | 79 | pdf_file->outline_root = root; |
eric@74 | 80 | pdf_set_dict_entry (pdf_file->catalog, "Outlines", root->dict); |
eric@74 | 81 | } |
eric@74 | 82 | |
eric@74 | 83 | entry = pdf_calloc (1, sizeof (struct pdf_bookmark)); |
eric@74 | 84 | entry->dict = pdf_new_ind_ref (pdf_file, pdf_new_obj (PT_DICTIONARY)); |
eric@74 | 85 | entry->open = open; |
eric@74 | 86 | |
eric@74 | 87 | pdf_set_dict_entry (entry->dict, "Title", pdf_new_string (title)); |
eric@74 | 88 | |
eric@74 | 89 | dest_array = pdf_new_obj (PT_ARRAY); |
eric@74 | 90 | pdf_add_array_elem (dest_array, pdf_page->page_dict); |
eric@74 | 91 | pdf_add_array_elem (dest_array, pdf_new_name ("Fit")); |
eric@74 | 92 | pdf_set_dict_entry (entry->dict, "Dest", dest_array); |
eric@74 | 93 | |
eric@74 | 94 | if (parent) |
eric@74 | 95 | { |
eric@74 | 96 | entry->parent = parent; |
eric@74 | 97 | entry->prev = parent->last; |
eric@74 | 98 | } |
eric@74 | 99 | else |
eric@74 | 100 | { |
eric@74 | 101 | parent = root; |
eric@74 | 102 | entry->parent = root; |
eric@74 | 103 | entry->prev = root->last; |
eric@74 | 104 | } |
eric@74 | 105 | |
eric@74 | 106 | pdf_set_dict_entry (entry->dict, "Parent", parent->dict); |
eric@74 | 107 | |
eric@74 | 108 | if (entry->prev) |
eric@74 | 109 | { |
eric@74 | 110 | pdf_set_dict_entry (entry->dict, "Prev", entry->prev->dict); |
eric@74 | 111 | |
eric@74 | 112 | entry->prev->next = entry; |
eric@74 | 113 | pdf_set_dict_entry (entry->prev->dict, "Next", entry->dict); |
eric@74 | 114 | |
eric@74 | 115 | parent->last = entry; |
eric@74 | 116 | pdf_set_dict_entry (parent->dict, "Last", entry->dict); |
eric@74 | 117 | } |
eric@74 | 118 | else |
eric@74 | 119 | { |
eric@74 | 120 | parent->first = entry; |
eric@74 | 121 | pdf_set_dict_entry (parent->dict, "First", entry->dict); |
eric@74 | 122 | |
eric@74 | 123 | parent->last = entry; |
eric@74 | 124 | pdf_set_dict_entry (parent->dict, "Last", entry->dict); |
eric@74 | 125 | } |
eric@74 | 126 | |
eric@74 | 127 | pdf_bookmark_update_count (parent); |
eric@74 | 128 | |
eric@74 | 129 | return (entry); |
eric@74 | 130 | } |