2 * << Haru Free PDF Library 2.0.5 >> -- ExtGStateDemo.dpr
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.
19 SysUtils, hpdf, hpdf_types, hpdf_consts;
22 error_handler (error_no: HPDF_STATUS; detail_no: HPDF_STATUS;
23 user_data: Pointer); stdcall;
27 message := 'ERROR: ' + IntToStr(error_no) + '-' + IntToStr(detail_no);
28 raise Exception.Create(message);
31 procedure draw_circles (page: HPDF_Page; const description: PChar; x:
32 HPDF_REAL; y: HPDF_REAL);
34 HPDF_Page_SetLineWidth (page, 1.0);
35 HPDF_Page_SetRGBStroke (page, 0.0, 0.0, 0.0);
36 HPDF_Page_SetRGBFill (page, 1.0, 0.0, 0.0);
37 HPDF_Page_Circle (page,x + 40, y + 40, 40);
38 HPDF_Page_FillStroke (page);
39 HPDF_Page_SetRGBFill (page, 0.0, 1.0, 0.0);
40 HPDF_Page_Circle (page, x + 100, y + 40, 40);
41 HPDF_Page_FillStroke (page);
42 HPDF_Page_SetRGBFill (page, 0.0, 0.0, 1.0);
43 HPDF_Page_Circle (page, x + 70, y + 74.64, 40);
44 HPDF_Page_FillStroke (page);
46 HPDF_Page_SetRGBFill (page, 0.0, 0.0, 0.0);
47 HPDF_Page_BeginText (page);
48 HPDF_Page_TextOut (page, x + 0.0, y + 130.0, description);
49 HPDF_Page_EndText (page);
52 procedure make_pdf ();
54 fname: string = 'ExtGStateDemo.pdf';
55 PAGE_WIDTH: HPDF_REAL = 600;
56 PAGE_HEIGHT: HPDF_REAL = 900;
61 gstate: HPDF_ExtGState;
63 pdf := HPDF_New(@error_handler, nil);
66 WriteLn('error: cannot create PdfDoc object\n');
71 // HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL);
73 {* create default-font *}
74 font := HPDF_GetFont (pdf, 'Helvetica-Bold', nil);
76 {* add a new page object. *}
77 page := HPDF_AddPage(pdf);
78 HPDF_Page_SetFontAndSize (page, font, 10);
80 HPDF_Page_SetHeight (page, PAGE_HEIGHT);
81 HPDF_Page_SetWidth (page, PAGE_WIDTH);
85 HPDF_Page_GSave (page);
86 draw_circles (page, 'normal', 40.0, PAGE_HEIGHT - 170);
87 HPDF_Page_GRestore (page);
90 HPDF_Page_GSave (page);
91 gstate := HPDF_CreateExtGState (pdf);
92 HPDF_ExtGState_SetAlphaFill (gstate, 0.8);
93 HPDF_Page_SetExtGState (page, gstate);
94 draw_circles (page, 'alpha fill = 0.8', 230.0, PAGE_HEIGHT - 170);
95 HPDF_Page_GRestore (page);
98 HPDF_Page_GSave (page);
99 gstate := HPDF_CreateExtGState (pdf);
100 HPDF_ExtGState_SetAlphaFill (gstate, 0.4);
101 HPDF_Page_SetExtGState (page, gstate);
102 draw_circles (page, 'alpha fill = 0.4', 420.0, PAGE_HEIGHT - 170);
103 HPDF_Page_GRestore (page);
105 {* blend-mode=HPDF_BM_MULTIPLY *}
106 HPDF_Page_GSave (page);
107 gstate := HPDF_CreateExtGState (pdf);
108 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_MULTIPLY);
109 HPDF_Page_SetExtGState (page, gstate);
110 draw_circles (page, 'HPDF_BM_MULTIPLY', 40.0, PAGE_HEIGHT - 340);
111 HPDF_Page_GRestore (page);
113 {* blend-mode=HPDF_BM_SCREEN *}
114 HPDF_Page_GSave (page);
115 gstate := HPDF_CreateExtGState (pdf);
116 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_SCREEN);
117 HPDF_Page_SetExtGState (page, gstate);
118 draw_circles (page, 'HPDF_BM_SCREEN', 230.0, PAGE_HEIGHT - 340);
119 HPDF_Page_GRestore (page);
121 {* blend-mode=HPDF_BM_OVERLAY *}
122 HPDF_Page_GSave (page);
123 gstate := HPDF_CreateExtGState (pdf);
124 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_OVERLAY);
125 HPDF_Page_SetExtGState (page, gstate);
126 draw_circles (page, 'HPDF_BM_OVERLAY', 420.0, PAGE_HEIGHT - 340);
127 HPDF_Page_GRestore (page);
129 {* blend-mode=HPDF_BM_DARKEN *}
130 HPDF_Page_GSave (page);
131 gstate := HPDF_CreateExtGState (pdf);
132 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_DARKEN);
133 HPDF_Page_SetExtGState (page, gstate);
134 draw_circles (page, 'HPDF_BM_DARKEN', 40.0, PAGE_HEIGHT - 510);
135 HPDF_Page_GRestore (page);
137 {* blend-mode=HPDF_BM_LIGHTEN *}
138 HPDF_Page_GSave (page);
139 gstate := HPDF_CreateExtGState (pdf);
140 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_LIGHTEN);
141 HPDF_Page_SetExtGState (page, gstate);
142 draw_circles (page, 'HPDF_BM_LIGHTEN', 230.0, PAGE_HEIGHT - 510);
143 HPDF_Page_GRestore (page);
145 {* blend-mode=HPDF_BM_COLOR_DODGE *}
146 HPDF_Page_GSave (page);
147 gstate := HPDF_CreateExtGState (pdf);
148 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_COLOR_DODGE);
149 HPDF_Page_SetExtGState (page, gstate);
150 draw_circles (page, 'HPDF_BM_COLOR_DODGE', 420.0, PAGE_HEIGHT - 510);
151 HPDF_Page_GRestore (page);
153 {* blend-mode=HPDF_BM_COLOR_BUM *}
154 HPDF_Page_GSave (page);
155 gstate := HPDF_CreateExtGState (pdf);
156 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_COLOR_BUM);
157 HPDF_Page_SetExtGState (page, gstate);
158 draw_circles (page, 'HPDF_BM_COLOR_BUM', 40.0, PAGE_HEIGHT - 680);
159 HPDF_Page_GRestore (page);
161 {* blend-mode=HPDF_BM_HARD_LIGHT *}
162 HPDF_Page_GSave (page);
163 gstate := HPDF_CreateExtGState (pdf);
164 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_HARD_LIGHT);
165 HPDF_Page_SetExtGState (page, gstate);
166 draw_circles (page, 'HPDF_BM_HARD_LIGHT', 230.0, PAGE_HEIGHT - 680);
167 HPDF_Page_GRestore (page);
169 {* blend-mode=HPDF_BM_SOFT_LIGHT *}
170 HPDF_Page_GSave (page);
171 gstate := HPDF_CreateExtGState (pdf);
172 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_SOFT_LIGHT);
173 HPDF_Page_SetExtGState (page, gstate);
174 draw_circles (page, 'HPDF_BM_SOFT_LIGHT', 420.0, PAGE_HEIGHT - 680);
175 HPDF_Page_GRestore (page);
177 {* blend-mode=HPDF_BM_DIFFERENCE *}
178 HPDF_Page_GSave (page);
179 gstate := HPDF_CreateExtGState (pdf);
180 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_DIFFERENCE);
181 HPDF_Page_SetExtGState (page, gstate);
182 draw_circles (page, 'HPDF_BM_DIFFERENCE', 40.0, PAGE_HEIGHT - 850);
183 HPDF_Page_GRestore (page);
185 {* blend-mode=HPDF_BM_EXCLUSHON *}
186 HPDF_Page_GSave (page);
187 gstate := HPDF_CreateExtGState (pdf);
188 HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_EXCLUSHON);
189 HPDF_Page_SetExtGState (page, gstate);
190 draw_circles (page, 'HPDF_BM_EXCLUSHON', 230.0, PAGE_HEIGHT - 850);
191 HPDF_Page_GRestore (page);
193 {* save the document to a file *}
194 HPDF_SaveToFile (pdf, PChar(fname));