1/*
2 * << Haru Free PDF Library >> -- hpdf_page_label.c
3 *
4 * URL: http://libharu.org
5 *
6 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7 * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
8 *
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.
15 *
16 */
17
18#include "hpdf_conf.h"
19#include "hpdf_utils.h"
20#include "hpdf_page_label.h"
21
22HPDF_Dict
23HPDF_PageLabel_New (HPDF_Doc pdf,
24 HPDF_PageNumStyle style,
25 HPDF_INT first_page,
26 const char *prefix)
27{
28 HPDF_Dict obj = HPDF_Dict_New (pdf->mmgr);
29
30 HPDF_PTRACE ((" HPDF_PageLabel_New\n"));
31
32 if (!obj)
33 return NULL;
34
35 switch (style) {
36 case HPDF_PAGE_NUM_STYLE_DECIMAL:
37 if (HPDF_Dict_AddName (obj, "S", "D") != HPDF_OK)
38 goto Fail;
39 break;
40 case HPDF_PAGE_NUM_STYLE_UPPER_ROMAN:
41 if (HPDF_Dict_AddName (obj, "S", "R") != HPDF_OK)
42 goto Fail;
43 break;
44 case HPDF_PAGE_NUM_STYLE_LOWER_ROMAN:
45 if (HPDF_Dict_AddName (obj, "S", "r") != HPDF_OK)
46 goto Fail;
47 break;
48 case HPDF_PAGE_NUM_STYLE_UPPER_LETTERS:
49 if (HPDF_Dict_AddName (obj, "S", "A") != HPDF_OK)
50 goto Fail;
51 break;
52 case HPDF_PAGE_NUM_STYLE_LOWER_LETTERS:
53 if (HPDF_Dict_AddName (obj, "S", "a") != HPDF_OK)
54 goto Fail;
55 break;
56 default:
57 HPDF_SetError (&pdf->error, HPDF_PAGE_NUM_STYLE_OUT_OF_RANGE,
58 (HPDF_STATUS)style);
59 goto Fail;
60 }
61
62 if (prefix && prefix[0] != 0)
63 if (HPDF_Dict_Add (obj, "P", HPDF_String_New (pdf->mmgr, prefix,
64 pdf->def_encoder)) != HPDF_OK)
65 goto Fail;
66
67 if (first_page != 0)
68 if (HPDF_Dict_AddNumber (obj, "St", first_page) != HPDF_OK)
69 goto Fail;
70
71 return obj;
72
73Fail:
74 HPDF_Dict_Free (obj);
75 return NULL;
76}
77
78