1#!/usr/bin/perl 2# $Id: pdfclock.pl 14574 2005-10-29 16:27:43Z bonefish $ 3# 4# PDFlib client: pdfclock example in Perl 5# 6 7use pdflib_pl 5.0; 8 9$RADIUS = 200.0; 10$MARGIN = 20.0; 11 12$p = PDF_new(); 13eval{ 14 if (PDF_open_file($p, "pdfclock.pdf") == -1){ 15 printf("Error: %s\n", PDF_get_errmsg($p)); 16 exit; 17 } 18 19 # This line is required to avoid problems on Japanese systems 20 PDF_set_parameter($p, "hypertextencoding", "winansi"); 21 22 PDF_set_info($p, "Creator", "pdfclock.pl"); 23 PDF_set_info($p, "Author", "Thomas Merz"); 24 PDF_set_info($p, "Title", "PDF clock (Perl)"); 25 26 PDF_begin_page($p, 2 * ($RADIUS + $MARGIN), 2 * ($RADIUS + $MARGIN)); 27 28 PDF_translate($p, $RADIUS + $MARGIN, $RADIUS + $MARGIN); 29 PDF_setcolor($p, "fillstroke", "rgb", 0.0, 0.0, 1.0, 0.0); 30 PDF_save($p); 31 32 # minute strokes 33 PDF_setlinewidth($p, 2.0); 34 for ($alpha = 0; $alpha < 360; $alpha += 6) 35 { 36 PDF_rotate($p, 6.0); 37 PDF_moveto($p, $RADIUS, 0.0); 38 PDF_lineto($p, $RADIUS-$MARGIN/3, 0.0); 39 PDF_stroke($p); 40 } 41 42 PDF_restore($p); 43 PDF_save($p); 44 45 # 5 minute strokes 46 PDF_setlinewidth($p, 3.0); 47 for ($alpha = 0; $alpha < 360; $alpha += 30) 48 { 49 PDF_rotate($p, 30.0); 50 PDF_moveto($p, $RADIUS, 0.0); 51 PDF_lineto($p, $RADIUS-$MARGIN, 0.0); 52 PDF_stroke($p); 53 } 54 55 ($tm_sec,$tm_min,$tm_hour) = localtime(time); 56 57 # draw hour hand 58 PDF_save($p); 59 PDF_rotate($p, (-(($tm_min/60.0) + $tm_hour - 3.0) * 30.0)); 60 PDF_moveto($p, -$RADIUS/10, -$RADIUS/20); 61 PDF_lineto($p, $RADIUS/2, 0.0); 62 PDF_lineto($p, -$RADIUS/10, $RADIUS/20); 63 PDF_closepath($p); 64 PDF_fill($p); 65 PDF_restore($p); 66 67 # draw minute hand 68 PDF_save($p); 69 PDF_rotate($p, (-(($tm_sec/60.0) + $tm_min - 15.0) * 6.0)); 70 PDF_moveto($p, -$RADIUS/10, -$RADIUS/20); 71 PDF_lineto($p, $RADIUS * 0.8, 0.0); 72 PDF_lineto($p, -$RADIUS/10, $RADIUS/20); 73 PDF_closepath($p); 74 PDF_fill($p); 75 PDF_restore($p); 76 77 # draw second hand 78 PDF_setcolor($p, "fillstroke", "rgb", 1.0, 0.0, 0.0, 0.0); 79 PDF_setlinewidth($p, 2); 80 PDF_save($p); 81 PDF_rotate($p, -(($tm_sec - 15.0) * 6.0)); 82 PDF_moveto($p, -$RADIUS/5, 0.0); 83 PDF_lineto($p, $RADIUS, 0.0); 84 PDF_stroke($p); 85 PDF_restore($p); 86 87 # draw little circle at center 88 PDF_circle($p, 0, 0, $RADIUS/30); 89 PDF_fill($p); 90 91 PDF_restore($p); 92 PDF_end_page($p); 93 94 PDF_close($p); 95 96}; 97if ($@) { 98 printf("pdfclock: PDFlib Exception occurred:\n"); 99 printf(" $@\n"); 100 exit; 101} 102 103PDF_delete($p); # delete the PDFlib object 104