2 * << Haru Free PDF Library >> -- hpdf_ext_gstate.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"
20 #include "hpdf_ext_gstate.h"
23 static const char * const HPDF_BM_NAMES[] = {
40 HPDF_ExtGState_Validate (HPDF_ExtGState ext_gstate)
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)))
53 ExtGState_Check (HPDF_ExtGState ext_gstate)
55 if (!HPDF_ExtGState_Validate (ext_gstate))
56 return HPDF_INVALID_OBJECT;
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,
68 HPDF_ExtGState_New (HPDF_MMgr mmgr,
71 HPDF_Dict obj = HPDF_Dict_New (mmgr);
73 HPDF_PTRACE ((" HPDF_ExtGState_New\n"));
78 if (HPDF_Xref_Add (xref, obj) != HPDF_OK)
81 if (HPDF_Dict_AddName (obj, "Type", "ExtGState") != HPDF_OK)
84 obj->header.obj_class |= HPDF_OSUBCLASS_EXT_GSTATE;
90 HPDF_EXPORT(HPDF_STATUS)
91 HPDF_ExtGState_SetAlphaStroke (HPDF_ExtGState ext_gstate,
94 HPDF_STATUS ret = ExtGState_Check (ext_gstate);
99 if (value < 0 || value > 1.0f)
100 return HPDF_RaiseError (ext_gstate->error,
101 HPDF_EXT_GSTATE_OUT_OF_RANGE, 0);
103 return HPDF_Dict_AddReal (ext_gstate, "CA", value);
107 HPDF_EXPORT(HPDF_STATUS)
108 HPDF_ExtGState_SetAlphaFill (HPDF_ExtGState ext_gstate,
111 HPDF_STATUS ret = ExtGState_Check (ext_gstate);
116 if (value < 0 || value > 1.0f)
117 return HPDF_RaiseError (ext_gstate->error,
118 HPDF_EXT_GSTATE_OUT_OF_RANGE, 0);
120 return HPDF_Dict_AddReal (ext_gstate, "ca", value);
124 HPDF_EXPORT(HPDF_STATUS)
125 HPDF_ExtGState_SetBlendMode (HPDF_ExtGState ext_gstate,
126 HPDF_BlendMode bmode)
128 HPDF_STATUS ret = ExtGState_Check (ext_gstate);
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);
137 return HPDF_Dict_AddName (ext_gstate, "BM", HPDF_BM_NAMES[(int)bmode]);
142 HPDF_ExtGState_SetStrokeAdjustment (HPDF_ExtGState ext_gstate,
145 HPDF_STATUS ret = ExtGState_Check (ext_gstate);
150 return HPDF_Dict_AddBoolean (ext_gstate, "SA", value);