2 ## * << Haru Free PDF Library 2.0.0 >> -- ext_gstate_demo.c
4 ## * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
6 ## * Permission to use, copy, modify, distribute and sell this software
7 ## * and its documentation for any purpose is hereby granted without fee,
8 ## * provided that the above copyright notice appear in all copies and
9 ## * that both that copyright notice and this permission notice appear
10 ## * in supporting documentation.
11 ## * It is provided "as is" without express or implied warranty.
15 ## port to python by Li Jun
16 ## http://groups.google.com/group/pythoncia
24 path=os.path.normpath(os.path.split(os.path.realpath(__file__))[0]+'\..'*up)
25 if path not in sys.path:
31 from haru.c_func import *
32 from haru.hpdf_errorcode import *
35 @HPDF_Error_Handler(None, HPDF_UINT, HPDF_UINT, c_void_p)
36 def error_handler (error_no, detail_no, user_data):
38 printf ("ERROR: %s, detail_no=%u\n", error_detail[error_no],
44 def draw_circles (page, description, x, y):
45 HPDF_Page_SetLineWidth (page, 1.0)
46 HPDF_Page_SetRGBStroke (page, 0.0, 0.0, 0.0)
47 HPDF_Page_SetRGBFill (page, 1.0, 0.0, 0.0)
48 HPDF_Page_Circle (page, x + 40, y + 40, 40)
49 HPDF_Page_ClosePathFillStroke (page)
50 HPDF_Page_SetRGBFill (page, 0.0, 1.0, 0.0)
51 HPDF_Page_Circle (page, x + 100, y + 40, 40)
52 HPDF_Page_ClosePathFillStroke (page)
53 HPDF_Page_SetRGBFill (page, 0.0, 0.0, 1.0)
54 HPDF_Page_Circle (page, x + 70, y + 74.64, 40)
55 HPDF_Page_ClosePathFillStroke (page)
57 HPDF_Page_SetRGBFill (page, 0.0, 0.0, 0.0)
58 HPDF_Page_BeginText (page)
59 HPDF_Page_TextOut (page, x + 0.0, y + 130.0, description)
60 HPDF_Page_EndText (page)
69 fname=os.path.realpath(sys.argv[0])
70 fname=fname[:fname.rfind('.')]+'.pdf'
72 pdf = HPDF_New (error_handler, NULL)
74 printf ("error: cannot create PdfDoc object\n")
77 hfont = HPDF_GetFont (pdf, "Helvetica-Bold", NULL)
79 # add a new page object.
80 page = HPDF_AddPage (pdf)
82 HPDF_Page_SetFontAndSize (page, hfont, 10)
84 HPDF_Page_SetHeight (page, PAGE_HEIGHT)
85 HPDF_Page_SetWidth (page, PAGE_WIDTH)
88 HPDF_Page_GSave (page)
89 draw_circles (page, "normal", 40.0, PAGE_HEIGHT - 170)
90 HPDF_Page_GRestore (page)
93 HPDF_Page_GSave (page)
94 gstate = HPDF_CreateExtGState (pdf)
95 HPDF_ExtGState_SetAlphaFill (gstate, 0.8)
96 HPDF_ExtGState_SetAlphaStroke (gstate, 0.8)
97 HPDF_Page_SetExtGState (page, gstate)
98 draw_circles (page, "alpha fill = 0.8", 230.0, PAGE_HEIGHT - 170)
99 HPDF_Page_GRestore (page)
102 HPDF_Page_GSave (page)
103 gstate = HPDF_CreateExtGState (pdf)
104 HPDF_ExtGState_SetAlphaFill (gstate, 0.4)
105 HPDF_Page_SetExtGState (page, gstate)
106 draw_circles (page, "alpha fill = 0.4", 420.0, PAGE_HEIGHT - 170)
107 HPDF_Page_GRestore (page)
109 # blend-mode=HPDF_BM_MULTIPLY
110 HPDF_Page_GSave (page)
111 gstate = HPDF_CreateExtGState (pdf)
112 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_MULTIPLY)
113 HPDF_Page_SetExtGState (page, gstate)
114 draw_circles (page, "HPDF_BM_MULTIPLY", 40.0, PAGE_HEIGHT - 340)
115 HPDF_Page_GRestore (page)
117 # blend-mode=HPDF_BM_SCREEN
118 HPDF_Page_GSave (page)
119 gstate = HPDF_CreateExtGState (pdf)
120 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_SCREEN)
121 HPDF_Page_SetExtGState (page, gstate)
122 draw_circles (page, "HPDF_BM_SCREEN", 230.0, PAGE_HEIGHT - 340)
123 HPDF_Page_GRestore (page)
125 # blend-mode=HPDF_BM_OVERLAY
126 HPDF_Page_GSave (page)
127 gstate = HPDF_CreateExtGState (pdf)
128 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_OVERLAY)
129 HPDF_Page_SetExtGState (page, gstate)
130 draw_circles (page, "HPDF_BM_OVERLAY", 420.0, PAGE_HEIGHT - 340)
131 HPDF_Page_GRestore (page)
133 # blend-mode=HPDF_BM_DARKEN
134 HPDF_Page_GSave (page)
135 gstate = HPDF_CreateExtGState (pdf)
136 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_DARKEN)
137 HPDF_Page_SetExtGState (page, gstate)
138 draw_circles (page, "HPDF_BM_DARKEN", 40.0, PAGE_HEIGHT - 510)
139 HPDF_Page_GRestore (page)
141 # blend-mode=HPDF_BM_LIGHTEN
142 HPDF_Page_GSave (page)
143 gstate = HPDF_CreateExtGState (pdf)
144 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_LIGHTEN)
145 HPDF_Page_SetExtGState (page, gstate)
146 draw_circles (page, "HPDF_BM_LIGHTEN", 230.0, PAGE_HEIGHT - 510)
147 HPDF_Page_GRestore (page)
149 # blend-mode=HPDF_BM_COLOR_DODGE
150 HPDF_Page_GSave (page)
151 gstate = HPDF_CreateExtGState (pdf)
152 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_COLOR_DODGE)
153 HPDF_Page_SetExtGState (page, gstate)
154 draw_circles (page, "HPDF_BM_COLOR_DODGE", 420.0, PAGE_HEIGHT - 510)
155 HPDF_Page_GRestore (page)
158 # blend-mode=HPDF_BM_COLOR_BUM
159 HPDF_Page_GSave (page)
160 gstate = HPDF_CreateExtGState (pdf)
161 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_COLOR_BUM)
162 HPDF_Page_SetExtGState (page, gstate)
163 draw_circles (page, "HPDF_BM_COLOR_BUM", 40.0, PAGE_HEIGHT - 680)
164 HPDF_Page_GRestore (page)
166 # blend-mode=HPDF_BM_HARD_LIGHT
167 HPDF_Page_GSave (page)
168 gstate = HPDF_CreateExtGState (pdf)
169 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_HARD_LIGHT)
170 HPDF_Page_SetExtGState (page, gstate)
171 draw_circles (page, "HPDF_BM_HARD_LIGHT", 230.0, PAGE_HEIGHT - 680)
172 HPDF_Page_GRestore (page)
174 # blend-mode=HPDF_BM_SOFT_LIGHT
175 HPDF_Page_GSave (page)
176 gstate = HPDF_CreateExtGState (pdf)
177 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_SOFT_LIGHT)
178 HPDF_Page_SetExtGState (page, gstate)
179 draw_circles (page, "HPDF_BM_SOFT_LIGHT", 420.0, PAGE_HEIGHT - 680)
180 HPDF_Page_GRestore (page)
182 # blend-mode=HPDF_BM_DIFFERENCE
183 HPDF_Page_GSave (page)
184 gstate = HPDF_CreateExtGState (pdf)
185 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_DIFFERENCE)
186 HPDF_Page_SetExtGState (page, gstate)
187 draw_circles (page, "HPDF_BM_DIFFERENCE", 40.0, PAGE_HEIGHT - 850)
188 HPDF_Page_GRestore (page)
191 # blend-mode=HPDF_BM_EXCLUSHON
192 HPDF_Page_GSave (page)
193 gstate = HPDF_CreateExtGState (pdf)
194 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_EXCLUSHON)
195 HPDF_Page_SetExtGState (page, gstate)
196 draw_circles (page, "HPDF_BM_EXCLUSHON", 230.0, PAGE_HEIGHT - 850)
197 HPDF_Page_GRestore (page)
200 # save the document to a file
201 HPDF_SaveToFile (pdf, fname)