OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / src / hpdf_ext_gstate.c
1 /*
2  * << Haru Free PDF Library >> -- hpdf_ext_gstate.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_ext_gstate.h"
21 #include "hpdf.h"
22
23 static const char * const HPDF_BM_NAMES[] = {
24                                       "Normal",
25                                       "Multiply",
26                                       "Screen",
27                                       "Overlay",
28                                       "Darken",
29                                       "Lighten",
30                                       "ColorDodge",
31                                       "ColorBurn",
32                                       "HardLight",
33                                       "SoftLight",
34                                       "Difference",
35                                       "Exclusion"
36                                       };
37
38
39 HPDF_BOOL
40 HPDF_ExtGState_Validate  (HPDF_ExtGState  ext_gstate)
41 {
42     if (!ext_gstate || (ext_gstate->header.obj_class != 
43                 (HPDF_OSUBCLASS_EXT_GSTATE | HPDF_OCLASS_DICT) &&
44                 ext_gstate->header.obj_class !=
45                  (HPDF_OSUBCLASS_EXT_GSTATE_R | HPDF_OCLASS_DICT)))
46         return HPDF_FALSE;
47
48     return HPDF_TRUE;
49 }
50
51
52 HPDF_STATUS
53 ExtGState_Check  (HPDF_ExtGState  ext_gstate)
54 {
55     if (!HPDF_ExtGState_Validate (ext_gstate))
56         return HPDF_INVALID_OBJECT;
57     
58     if (ext_gstate->header.obj_class == 
59             (HPDF_OSUBCLASS_EXT_GSTATE_R | HPDF_OCLASS_DICT))
60         return HPDF_RaiseError (ext_gstate->error, HPDF_EXT_GSTATE_READ_ONLY,
61                 0);
62
63     return HPDF_OK;
64 }
65
66
67 HPDF_Dict
68 HPDF_ExtGState_New  (HPDF_MMgr   mmgr, 
69                      HPDF_Xref   xref)
70 {
71     HPDF_Dict obj = HPDF_Dict_New (mmgr);
72
73     HPDF_PTRACE ((" HPDF_ExtGState_New\n"));
74
75     if (!obj)
76         return NULL;
77
78     if (HPDF_Xref_Add (xref, obj) != HPDF_OK)
79         return NULL;
80
81     if (HPDF_Dict_AddName (obj, "Type", "ExtGState") != HPDF_OK)
82         return NULL;
83
84     obj->header.obj_class |= HPDF_OSUBCLASS_EXT_GSTATE;
85
86     return obj;
87 }
88
89
90 HPDF_EXPORT(HPDF_STATUS)
91 HPDF_ExtGState_SetAlphaStroke  (HPDF_ExtGState   ext_gstate,
92                                 HPDF_REAL        value)
93 {
94     HPDF_STATUS ret = ExtGState_Check (ext_gstate);
95     
96     if (ret != HPDF_OK)
97         return ret;
98     
99     if (value < 0 || value > 1.0f)
100         return HPDF_RaiseError (ext_gstate->error, 
101                 HPDF_EXT_GSTATE_OUT_OF_RANGE, 0);
102
103     return HPDF_Dict_AddReal (ext_gstate, "CA", value);
104 }
105
106
107 HPDF_EXPORT(HPDF_STATUS)
108 HPDF_ExtGState_SetAlphaFill  (HPDF_ExtGState   ext_gstate,
109                               HPDF_REAL        value)
110 {
111     HPDF_STATUS ret = ExtGState_Check (ext_gstate);
112     
113     if (ret != HPDF_OK)
114         return ret;
115
116     if (value < 0 || value > 1.0f)
117         return HPDF_RaiseError (ext_gstate->error, 
118                 HPDF_EXT_GSTATE_OUT_OF_RANGE, 0);
119
120     return HPDF_Dict_AddReal (ext_gstate, "ca", value);
121 }
122
123
124 HPDF_EXPORT(HPDF_STATUS)
125 HPDF_ExtGState_SetBlendMode  (HPDF_ExtGState   ext_gstate,
126                               HPDF_BlendMode   bmode)
127 {
128     HPDF_STATUS ret = ExtGState_Check (ext_gstate);
129     
130     if (ret != HPDF_OK)
131         return ret;
132
133     if ((int)bmode < 0 || (int)bmode > (int)HPDF_BM_EOF)
134         return HPDF_RaiseError (ext_gstate->error, 
135                 HPDF_EXT_GSTATE_OUT_OF_RANGE, 0);
136
137     return HPDF_Dict_AddName (ext_gstate, "BM", HPDF_BM_NAMES[(int)bmode]);
138 }
139
140 /*
141 HPDF_STATUS
142 HPDF_ExtGState_SetStrokeAdjustment  (HPDF_ExtGState   ext_gstate,
143                                      HPDF_BOOL        value)
144 {
145     HPDF_STATUS ret = ExtGState_Check (ext_gstate);
146     
147     if (ret != HPDF_OK)
148         return ret;
149
150     return HPDF_Dict_AddBoolean (ext_gstate, "SA", value);
151 }
152 */
153