OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / demo / arc_demo.c
1 /*
2  * << Haru Free PDF Library 2.0.0 >> -- arc_demo.c
3  *
4  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
5  *
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.
12  *
13  */
14
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <setjmp.h>
19 #include "hpdf.h"
20 #include "grid_sheet.h"
21
22 jmp_buf env;
23
24 #ifdef HPDF_DLL
25 void  __stdcall
26 #else
27 void
28 #endif
29 error_handler  (HPDF_STATUS   error_no,
30                 HPDF_STATUS   detail_no,
31                 void         *user_data)
32 {
33     printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
34                 (HPDF_UINT)detail_no);
35     longjmp(env, 1);
36 }
37
38 int
39 main (int argc, char **argv)
40 {
41     HPDF_Doc  pdf;
42     HPDF_Page page;
43     char fname[256];
44     HPDF_Point pos;
45
46     strcpy (fname, argv[0]);
47     strcat (fname, ".pdf");
48
49     pdf = HPDF_New (error_handler, NULL);
50     if (!pdf) {
51         printf ("error: cannot create PdfDoc object\n");
52         return 1;
53     }
54
55     if (setjmp(env)) {
56         HPDF_Free (pdf);
57         return 1;
58     }
59
60     /* add a new page object. */
61     page = HPDF_AddPage (pdf);
62
63     HPDF_Page_SetHeight (page, 220);
64     HPDF_Page_SetWidth (page, 200);
65
66     /* draw grid to the page */
67     print_grid  (pdf, page);
68
69     /* draw pie chart
70      *
71      *   A: 45% Red
72      *   B: 25% Blue
73      *   C: 15% green
74      *   D: other yellow
75      */
76
77     /* A */
78     HPDF_Page_SetRGBFill (page, 1.0, 0, 0);
79     HPDF_Page_MoveTo (page, 100, 100);
80     HPDF_Page_LineTo (page, 100, 180);
81     HPDF_Page_Arc (page, 100, 100, 80, 0, 360 * 0.45);
82     pos = HPDF_Page_GetCurrentPos (page);
83     HPDF_Page_LineTo (page, 100, 100);
84     HPDF_Page_Fill (page);
85
86     /* B */
87     HPDF_Page_SetRGBFill (page, 0, 0, 1.0);
88     HPDF_Page_MoveTo (page, 100, 100);
89     HPDF_Page_LineTo (page, pos.x, pos.y);
90     HPDF_Page_Arc (page, 100, 100, 80, 360 * 0.45, 360 * 0.7);
91     pos = HPDF_Page_GetCurrentPos (page);
92     HPDF_Page_LineTo (page, 100, 100);
93     HPDF_Page_Fill (page);
94
95     /* C */
96     HPDF_Page_SetRGBFill (page, 0, 1.0, 0);
97     HPDF_Page_MoveTo (page, 100, 100);
98     HPDF_Page_LineTo (page, pos.x, pos.y);
99     HPDF_Page_Arc (page, 100, 100, 80, 360 * 0.7, 360 * 0.85);
100     pos = HPDF_Page_GetCurrentPos (page);
101     HPDF_Page_LineTo (page, 100, 100);
102     HPDF_Page_Fill (page);
103
104     /* D */
105     HPDF_Page_SetRGBFill (page, 1.0, 1.0, 0);
106     HPDF_Page_MoveTo (page, 100, 100);
107     HPDF_Page_LineTo (page, pos.x, pos.y);
108     HPDF_Page_Arc (page, 100, 100, 80, 360 * 0.85, 360);
109     pos = HPDF_Page_GetCurrentPos (page);
110     HPDF_Page_LineTo (page, 100, 100);
111     HPDF_Page_Fill (page);
112
113     /* draw center circle */
114     HPDF_Page_SetGrayStroke (page, 0);
115     HPDF_Page_SetGrayFill (page, 1);
116     HPDF_Page_Circle (page, 100, 100, 30);
117     HPDF_Page_Fill (page);
118
119     /* save the document to a file */
120     HPDF_SaveToFile (pdf, fname);
121
122     /* clean up */
123     HPDF_Free (pdf);
124
125     return 0;
126 }
127