2 * << Haru Free PDF Library 2.0.5 >> -- LineDemo.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_line (page: HPDF_Page; x: Single; y: Single; const text: PChar);
33 HPDF_Page_BeginText(page);
34 HPDF_Page_MoveTextPos(page, x, y - 10);
35 HPDF_Page_ShowText(page, text);
36 HPDF_Page_EndText(page);
38 HPDF_Page_MoveTo(page, x, y - 15);
39 HPDF_Page_LineTo(page, x + 220, y - 15);
40 HPDF_Page_Stroke(page);
43 procedure draw_line2 (page: HPDF_Page; x: Single; y: Single; const text: PChar);
45 HPDF_Page_BeginText(page);
46 HPDF_Page_MoveTextPos(page, x, y);
47 HPDF_Page_ShowText(page, text);
48 HPDF_Page_EndText(page);
50 HPDF_Page_MoveTo(page, x + 30, y - 25);
51 HPDF_Page_LineTo(page, x + 160, y - 25);
52 HPDF_Page_Stroke(page);
55 procedure draw_rect (page: HPDF_Page; x: Single; y: Single; const text: PChar);
57 HPDF_Page_BeginText(page);
58 HPDF_Page_MoveTextPos(page, x, y - 10);
59 HPDF_Page_ShowText(page, text);
60 HPDF_Page_EndText(page);
62 HPDF_Page_Rectangle(page, x, y - 40, 220, 25);
66 procedure make_pdf ();
68 page_title: string = 'Line Demo';
69 fname: string = 'LineDemo.pdf';
71 DASH_MODE1: array[0..0] of HPDF_UINT16 = (3);
72 DASH_MODE2: array[0..1] of HPDF_UINT16 = (7, 3);
73 DASH_MODE3: array[0..3] of HPDF_UINT16 = (8, 7, 2, 7);
92 pdf := HPDF_New(@error_handler, nil);
95 WriteLn('error: cannot create PdfDoc object\n');
100 HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL);
102 {* create default-font *}
103 font := HPDF_GetFont(pdf, 'Helvetica', nil);
105 {* add a new page object. *}
106 page := HPDF_AddPage(pdf);
108 {* print the lines of the page. *}
109 HPDF_Page_SetLineWidth(page, 1);
110 x := HPDF_Page_GetWidth(page) - 100;
111 y := HPDF_Page_GetHeight(page) - 110;
112 HPDF_Page_Rectangle(page, 50, 50, x, y);
113 HPDF_Page_Stroke(page);
115 {* print the title of the page (with positioning center). *}
116 HPDF_Page_SetFontAndSize(page, font, 24);
117 tw := HPDF_Page_TextWidth(page, PChar(page_title));
118 HPDF_Page_BeginText(page);
120 x := (HPDF_Page_GetWidth(page) - tw) / 2;
121 y := HPDF_Page_GetHeight(page) - 50;
122 HPDF_Page_MoveTextPos (page, x, y);
124 HPDF_Page_ShowText (page, PChar(page_title));
125 HPDF_Page_EndText (page);
127 HPDF_Page_SetFontAndSize (page, font, 10);
129 {* Draw verious widths of lines. *}
130 HPDF_Page_SetLineWidth (page, 0);
131 draw_line (page, 60, 770, 'line width := 0');
133 HPDF_Page_SetLineWidth (page, 1.0);
134 draw_line (page, 60, 740, 'line width := 1.0');
136 HPDF_Page_SetLineWidth (page, 2.0);
137 draw_line (page, 60, 710, 'line width := 2.0');
139 {* Line dash pattern *}
140 HPDF_Page_SetLineWidth (page, 1.0);
142 HPDF_Page_SetDash (page, @DASH_MODE1, 1, 1);
143 draw_line (page, 60, 680, 'dash_ptn=[3], phase=1 -- 2 on, 3 off, 3 on...');
145 HPDF_Page_SetDash (page, @DASH_MODE2, 2, 2);
146 draw_line (page, 60, 650, 'dash_ptn=[7, 3], phase=2 -- 5 on 3 off, 7 on,...');
148 HPDF_Page_SetDash (page, @DASH_MODE3, 4, 0);
149 draw_line (page, 60, 620, 'dash_ptn=[8, 7, 2, 7], phase=0');
151 HPDF_Page_SetDash (page, nil, 0, 0);
153 HPDF_Page_SetLineWidth (page, 30);
154 HPDF_Page_SetRGBStroke (page, 0.0, 0.5, 0.0);
157 HPDF_Page_SetLineCap (page, HPDF_BUTT_END);
158 draw_line2 (page, 60, 570, 'PDF_BUTT_END');
160 HPDF_Page_SetLineCap (page, HPDF_ROUND_END);
161 draw_line2 (page, 60, 505, 'PDF_ROUND_END');
163 HPDF_Page_SetLineCap (page, HPDF_PROJECTING_SCUARE_END);
164 draw_line2 (page, 60, 440, 'PDF_PROJECTING_SCUARE_END');
166 {* Line Join Style *}
167 HPDF_Page_SetLineWidth (page, 30);
168 HPDF_Page_SetRGBStroke (page, 0.0, 0.0, 0.5);
170 HPDF_Page_SetLineJoin (page, HPDF_MITER_JOIN);
171 HPDF_Page_MoveTo (page, 120, 300);
172 HPDF_Page_LineTo (page, 160, 340);
173 HPDF_Page_LineTo (page, 200, 300);
174 HPDF_Page_Stroke (page);
176 HPDF_Page_BeginText (page);
177 HPDF_Page_MoveTextPos (page, 60, 360);
178 HPDF_Page_ShowText (page, 'PDF_MITER_JOIN');
179 HPDF_Page_EndText (page);
181 HPDF_Page_SetLineJoin (page, HPDF_ROUND_JOIN);
182 HPDF_Page_MoveTo (page, 120, 195);
183 HPDF_Page_LineTo (page, 160, 235);
184 HPDF_Page_LineTo (page, 200, 195);
185 HPDF_Page_Stroke (page);
187 HPDF_Page_BeginText (page);
188 HPDF_Page_MoveTextPos (page, 60, 255);
189 HPDF_Page_ShowText (page, 'PDF_ROUND_JOIN');
190 HPDF_Page_EndText (page);
192 HPDF_Page_SetLineJoin (page, HPDF_BEVEL_JOIN);
193 HPDF_Page_MoveTo (page, 120, 90);
194 HPDF_Page_LineTo (page, 160, 130);
195 HPDF_Page_LineTo (page, 200, 90);
196 HPDF_Page_Stroke (page);
198 HPDF_Page_BeginText (page);
199 HPDF_Page_MoveTextPos (page, 60, 150);
200 HPDF_Page_ShowText (page, 'PDF_BEVEL_JOIN');
201 HPDF_Page_EndText (page);
204 HPDF_Page_SetLineWidth (page, 2);
205 HPDF_Page_SetRGBStroke (page, 0, 0, 0);
206 HPDF_Page_SetRGBFill (page, 0.75, 0.0, 0.0);
208 draw_rect (page, 300, 770, 'Stroke');
209 HPDF_Page_Stroke (page);
211 draw_rect (page, 300, 720, 'Fill');
212 HPDF_Page_Fill (page);
214 draw_rect (page, 300, 670, 'Fill then Stroke');
215 HPDF_Page_FillStroke (page);
218 HPDF_Page_GSave (page); {* Save the current graphic state *}
219 draw_rect (page, 300, 620, 'Clip Rectangle');
220 HPDF_Page_Clip (page);
221 HPDF_Page_Stroke (page);
222 HPDF_Page_SetFontAndSize (page, font, 13);
224 HPDF_Page_BeginText (page);
225 HPDF_Page_MoveTextPos (page, 290, 600);
226 HPDF_Page_SetTextLeading (page, 12);
227 HPDF_Page_ShowText (page,
228 'Clip Clip Clip Clip Clip Clipi Clip Clip Clip');
229 HPDF_Page_ShowTextNextLine (page,
230 'Clip Clip Clip Clip Clip Clip Clip Clip Clip');
231 HPDF_Page_ShowTextNextLine (page,
232 'Clip Clip Clip Clip Clip Clip Clip Clip Clip');
233 HPDF_Page_EndText (page);
234 HPDF_Page_GRestore (page);
245 {* Curve Example(CurveTo2) *}
246 HPDF_Page_SetRGBFill (page, 0, 0, 0);
248 HPDF_Page_BeginText (page);
249 HPDF_Page_MoveTextPos (page, 300, 540);
250 HPDF_Page_ShowText (page, 'CurveTo2(x1, y1, x2. y2)');
251 HPDF_Page_EndText (page);
253 HPDF_Page_BeginText (page);
254 HPDF_Page_MoveTextPos (page, x0 + 5, y0 - 5);
255 HPDF_Page_ShowText (page, 'Current point');
256 HPDF_Page_MoveTextPos (page, x1 - x0, y1 - y0);
257 HPDF_Page_ShowText (page, '(x1, y1)');
258 HPDF_Page_MoveTextPos (page, x2 - x1, y2 - y1);
259 HPDF_Page_ShowText (page, '(x2, y2)');
260 HPDF_Page_EndText (page);
262 HPDF_Page_SetDash (page, nil, 0, 0);
264 HPDF_Page_SetLineWidth (page, 0.5);
265 HPDF_Page_MoveTo (page, x1, y1);
266 HPDF_Page_LineTo (page, x2, y2);
267 HPDF_Page_Stroke (page);
269 HPDF_Page_SetDash (page, nil, 0, 0);
271 HPDF_Page_SetLineWidth (page, 1.5);
273 HPDF_Page_MoveTo (page, x0, y0);
274 HPDF_Page_CurveTo2 (page, x1, y1, x2, y2);
275 HPDF_Page_Stroke (page);
277 {* Curve Example(CurveTo3) *}
282 HPDF_Page_BeginText (page);
283 HPDF_Page_MoveTextPos (page, 300, 390);
284 HPDF_Page_ShowText (page, 'CurveTo3(x1, y1, x2. y2)');
285 HPDF_Page_EndText (page);
287 HPDF_Page_BeginText (page);
288 HPDF_Page_MoveTextPos (page, x0 + 5, y0 - 5);
289 HPDF_Page_ShowText (page, 'Current point');
290 HPDF_Page_MoveTextPos (page, x1 - x0, y1 - y0);
291 HPDF_Page_ShowText (page, '(x1, y1)');
292 HPDF_Page_MoveTextPos (page, x2 - x1, y2 - y1);
293 HPDF_Page_ShowText (page, '(x2, y2)');
294 HPDF_Page_EndText (page);
296 HPDF_Page_SetDash (page, @DASH_MODE1, 1, 1);
298 HPDF_Page_SetLineWidth (page, 0.5);
299 HPDF_Page_MoveTo (page, x0, y0);
300 HPDF_Page_LineTo (page, x1, y1);
301 HPDF_Page_Stroke (page);
303 HPDF_Page_SetDash (page, nil, 0, 0);
305 HPDF_Page_SetLineWidth (page, 1.5);
306 HPDF_Page_MoveTo (page, x0, y0);
307 HPDF_Page_CurveTo3 (page, x1, y1, x2, y2);
308 HPDF_Page_Stroke (page);
310 {* Curve Example(CurveTo) *}
316 HPDF_Page_BeginText (page);
317 HPDF_Page_MoveTextPos (page, 300, 240);
318 HPDF_Page_ShowText (page, 'CurveTo(x1, y1, x2. y2, x3, y3)');
319 HPDF_Page_EndText (page);
321 HPDF_Page_BeginText (page);
322 HPDF_Page_MoveTextPos (page, x0 + 5, y0 - 5);
323 HPDF_Page_ShowText (page, 'Current point');
324 HPDF_Page_MoveTextPos (page, x1 - x0, y1 - y0);
325 HPDF_Page_ShowText (page, '(x1, y1)');
326 HPDF_Page_MoveTextPos (page, x2 - x1, y2 - y1);
327 HPDF_Page_ShowText (page, '(x2, y2)');
328 HPDF_Page_MoveTextPos (page, x3 - x2, y3 - y2);
329 HPDF_Page_ShowText (page, '(x3, y3)');
330 HPDF_Page_EndText (page);
332 HPDF_Page_SetDash (page, @DASH_MODE1, 1, 1);
334 HPDF_Page_SetLineWidth (page, 0.5);
335 HPDF_Page_MoveTo (page, x0, y0);
336 HPDF_Page_LineTo (page, x1, y1);
337 HPDF_Page_Stroke (page);
338 HPDF_Page_MoveTo (page, x2, y2);
339 HPDF_Page_LineTo (page, x3, y3);
340 HPDF_Page_Stroke (page);
342 HPDF_Page_SetDash (page, nil, 0, 0);
344 HPDF_Page_SetLineWidth (page, 1.5);
345 HPDF_Page_MoveTo (page, x0, y0);
346 HPDF_Page_CurveTo (page, x1, y1, x2, y2, x3, y3);
347 HPDF_Page_Stroke (page);
349 {* save the document to a file *}
350 HPDF_SaveToFile (pdf, PChar(fname));