1 | /* |
2 | * << Haru Free PDF Library >> -- hpdf_name.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_objects.h" |
21 | |
22 | |
23 | HPDF_Name |
24 | HPDF_Name_New (HPDF_MMgr mmgr, |
25 | const char *value) |
26 | { |
27 | HPDF_Name obj; |
28 | |
29 | obj = HPDF_GetMem (mmgr, sizeof(HPDF_Name_Rec)); |
30 | |
31 | if (obj) { |
32 | HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header)); |
33 | obj->header.obj_class = HPDF_OCLASS_NAME; |
34 | obj->error = mmgr->error; |
35 | if (HPDF_Name_SetValue (obj, value) == HPDF_NAME_INVALID_VALUE) { |
36 | HPDF_FreeMem (mmgr, obj); |
37 | return NULL; |
38 | } |
39 | } |
40 | |
41 | return obj; |
42 | } |
43 | |
44 | |
45 | HPDF_STATUS |
46 | HPDF_Name_Write (HPDF_Name obj, |
47 | HPDF_Stream stream) |
48 | { |
49 | return HPDF_Stream_WriteEscapeName (stream, obj->value); |
50 | } |
51 | |
52 | |
53 | HPDF_STATUS |
54 | HPDF_Name_SetValue (HPDF_Name obj, |
55 | const char *value) |
56 | { |
57 | if (!value || value[0] == 0) |
58 | return HPDF_SetError (obj->error, HPDF_NAME_INVALID_VALUE, 0); |
59 | |
60 | if (HPDF_StrLen (value, HPDF_LIMIT_MAX_NAME_LEN + 1) > |
61 | HPDF_LIMIT_MAX_NAME_LEN) |
62 | return HPDF_SetError (obj->error, HPDF_NAME_OUT_OF_RANGE, 0); |
63 | |
64 | HPDF_StrCpy (obj->value, value, obj->value + HPDF_LIMIT_MAX_NAME_LEN); |
65 | |
66 | return HPDF_OK; |
67 | } |
68 | |
69 | const char* |
70 | HPDF_Name_GetValue (HPDF_Name obj) |
71 | { |
72 | return (const char *)obj->value; |
73 | } |
74 | |
75 | |