2 * << Haru Free PDF Library >> -- hpdf_destination.c
4 * URL: http://libharu.org
6 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7 * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
9 * Permission to use, copy, modify, distribute and sell this software
10 * and its documentation for any purpose is hereby granted without fee,
11 * provided that the above copyright notice appear in all copies and
12 * that both that copyright notice and this permission notice appear
13 * in supporting documentation.
14 * It is provided "as is" without express or implied warranty.
18 #include "hpdf_conf.h"
19 #include "hpdf_utils.h"
22 const char * const HPDF_DESTINATION_TYPE_NAMES[] = {
34 /*----------------------------------------------------------------------------*/
35 /*----- HPDF_Destination -----------------------------------------------------*/
38 HPDF_Destination_New (HPDF_MMgr mmgr,
44 HPDF_PTRACE((" HPDF_Destination_New\n"));
46 if (!HPDF_Page_Validate (target)) {
47 HPDF_SetError (mmgr->error, HPDF_INVALID_PAGE, 0);
51 dst = HPDF_Array_New (mmgr);
55 dst->header.obj_class |= HPDF_OSUBCLASS_DESTINATION;
57 if (HPDF_Xref_Add (xref, dst) != HPDF_OK)
60 /* first item of array must be target page */
61 if (HPDF_Array_Add (dst, target) != HPDF_OK)
64 /* default type is HPDF_FIT */
65 if (HPDF_Array_AddName (dst,
66 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_FIT]) != HPDF_OK)
74 HPDF_Destination_Validate (HPDF_Destination dst)
76 HPDF_Obj_Header *header = (HPDF_Obj_Header *)dst;
79 if (!dst || header->obj_class !=
80 (HPDF_OCLASS_ARRAY | HPDF_OSUBCLASS_DESTINATION))
83 /* destination-types not defined. */
84 if (dst->list->count < 2)
87 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
88 if (!HPDF_Page_Validate (target)) {
89 HPDF_SetError (dst->error, HPDF_INVALID_PAGE, 0);
97 HPDF_EXPORT(HPDF_STATUS)
98 HPDF_Destination_SetXYZ (HPDF_Destination dst,
103 HPDF_STATUS ret = HPDF_OK;
106 HPDF_PTRACE((" HPDF_Destination_SetXYZ\n"));
108 if (!HPDF_Destination_Validate (dst))
109 return HPDF_INVALID_DESTINATION;
111 if (left < 0 || top < 0 || zoom < 0.08 || zoom > 32)
112 return HPDF_RaiseError (dst->error, HPDF_INVALID_PARAMETER, 0);
115 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
117 if (dst->list->count > 1) {
118 HPDF_Array_Clear (dst);
119 ret += HPDF_Array_Add (dst, target);
122 ret += HPDF_Array_AddName (dst,
123 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_XYZ]);
124 ret += HPDF_Array_AddReal (dst, left);
125 ret += HPDF_Array_AddReal (dst, top);
126 ret += HPDF_Array_AddReal (dst, zoom);
129 return HPDF_CheckError (dst->error);
135 HPDF_EXPORT(HPDF_STATUS)
136 HPDF_Destination_SetFit (HPDF_Destination dst)
138 HPDF_STATUS ret = HPDF_OK;
141 HPDF_PTRACE((" HPDF_Destination_SetFit\n"));
143 if (!HPDF_Destination_Validate (dst))
144 return HPDF_INVALID_DESTINATION;
146 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
148 if (dst->list->count > 1) {
149 HPDF_Array_Clear (dst);
150 ret += HPDF_Array_Add (dst, target);
153 ret += HPDF_Array_AddName (dst,
154 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_FIT]);
157 return HPDF_CheckError (dst->error);
163 HPDF_EXPORT(HPDF_STATUS)
164 HPDF_Destination_SetFitH (HPDF_Destination dst,
167 HPDF_STATUS ret = HPDF_OK;
170 HPDF_PTRACE((" HPDF_Destination_SetFitH\n"));
172 if (!HPDF_Destination_Validate (dst))
173 return HPDF_INVALID_DESTINATION;
175 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
177 if (dst->list->count > 1) {
178 HPDF_Array_Clear (dst);
179 ret += HPDF_Array_Add (dst, target);
182 ret += HPDF_Array_AddName (dst,
183 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_FIT_H]);
184 ret += HPDF_Array_AddReal (dst, top);
187 return HPDF_CheckError (dst->error);
192 HPDF_EXPORT(HPDF_STATUS)
193 HPDF_Destination_SetFitV (HPDF_Destination dst,
196 HPDF_STATUS ret = HPDF_OK;
199 HPDF_PTRACE((" HPDF_Destination_SetFitV\n"));
201 if (!HPDF_Destination_Validate (dst))
202 return HPDF_INVALID_DESTINATION;
204 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
206 if (dst->list->count > 1) {
207 HPDF_Array_Clear (dst);
208 ret += HPDF_Array_Add (dst, target);
211 ret += HPDF_Array_AddName (dst,
212 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_FIT_V]);
213 ret += HPDF_Array_AddReal (dst, left);
216 return HPDF_CheckError (dst->error);
222 HPDF_EXPORT(HPDF_STATUS)
223 HPDF_Destination_SetFitR (HPDF_Destination dst,
229 HPDF_STATUS ret = HPDF_OK;
232 HPDF_PTRACE((" HPDF_Destination_SetFitR\n"));
234 if (!HPDF_Destination_Validate (dst))
235 return HPDF_INVALID_DESTINATION;
237 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
239 if (dst->list->count > 1) {
240 HPDF_Array_Clear (dst);
241 ret += HPDF_Array_Add (dst, target);
244 ret += HPDF_Array_AddName (dst,
245 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_FIT_R]);
246 ret += HPDF_Array_AddReal (dst, left);
247 ret += HPDF_Array_AddReal (dst, bottom);
248 ret += HPDF_Array_AddReal (dst, right);
249 ret += HPDF_Array_AddReal (dst, top);
252 return HPDF_CheckError (dst->error);
258 HPDF_EXPORT(HPDF_STATUS)
259 HPDF_Destination_SetFitB (HPDF_Destination dst)
261 HPDF_STATUS ret = HPDF_OK;
264 HPDF_PTRACE((" HPDF_Destination_SetFitB\n"));
266 if (!HPDF_Destination_Validate (dst))
267 return HPDF_INVALID_DESTINATION;
269 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
271 if (dst->list->count > 1) {
272 HPDF_Array_Clear (dst);
273 ret += HPDF_Array_Add (dst, target);
276 ret += HPDF_Array_AddName (dst,
277 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_FIT_B]);
280 return HPDF_CheckError (dst->error);
286 HPDF_EXPORT(HPDF_STATUS)
287 HPDF_Destination_SetFitBH (HPDF_Destination dst,
290 HPDF_STATUS ret = HPDF_OK;
293 HPDF_PTRACE((" HPDF_Destination_SetFitBH\n"));
295 if (!HPDF_Destination_Validate (dst))
296 return HPDF_INVALID_DESTINATION;
298 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
300 if (dst->list->count > 1) {
301 HPDF_Array_Clear (dst);
302 ret += HPDF_Array_Add (dst, target);
305 ret += HPDF_Array_AddName (dst,
306 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_FIT_BH]);
307 ret += HPDF_Array_AddReal (dst, top);
310 return HPDF_CheckError (dst->error);
315 HPDF_EXPORT(HPDF_STATUS)
316 HPDF_Destination_SetFitBV (HPDF_Destination dst,
319 HPDF_STATUS ret = HPDF_OK;
322 HPDF_PTRACE((" HPDF_Destination_SetFitBV\n"));
324 if (!HPDF_Destination_Validate (dst))
325 return HPDF_INVALID_DESTINATION;
327 target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
329 if (dst->list->count > 1) {
330 HPDF_Array_Clear (dst);
331 ret += HPDF_Array_Add (dst, target);
334 ret += HPDF_Array_AddName (dst,
335 HPDF_DESTINATION_TYPE_NAMES[(HPDF_INT)HPDF_FIT_BV]);
336 ret += HPDF_Array_AddReal (dst, left);
339 return HPDF_CheckError (dst->error);