1 | /* |
2 | * << Haru Free PDF Library >> -- hpdf_real.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_Real |
24 | HPDF_Real_New (HPDF_MMgr mmgr, |
25 | HPDF_REAL value) |
26 | { |
27 | HPDF_Real obj = HPDF_GetMem (mmgr, sizeof(HPDF_Real_Rec)); |
28 | |
29 | if (obj) { |
30 | HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header)); |
31 | obj->header.obj_class = HPDF_OCLASS_REAL; |
32 | obj->error = mmgr->error; |
33 | HPDF_Real_SetValue (obj, value); |
34 | } |
35 | |
36 | return obj; |
37 | } |
38 | |
39 | |
40 | HPDF_STATUS |
41 | HPDF_Real_Write (HPDF_Real obj, |
42 | HPDF_Stream stream) |
43 | { |
44 | return HPDF_Stream_WriteReal (stream, obj->value); |
45 | } |
46 | |
47 | |
48 | HPDF_STATUS |
49 | HPDF_Real_SetValue (HPDF_Real obj, |
50 | HPDF_REAL value) |
51 | { |
52 | HPDF_STATUS ret = HPDF_OK; |
53 | |
54 | if (value > HPDF_LIMIT_MAX_REAL) |
55 | return HPDF_SetError (obj->error, HPDF_REAL_OUT_OF_RANGE, 0); |
56 | |
57 | if (value < HPDF_LIMIT_MIN_REAL) |
58 | return HPDF_SetError (obj->error, HPDF_REAL_OUT_OF_RANGE, 0); |
59 | |
60 | obj->value =value; |
61 | |
62 | return ret; |
63 | } |
64 | |
65 | |