OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / demo / outline_demo_jp.c
1 /*
2  * << Haru Free PDF Library 2.0.0 >> -- outline_demo_jp.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
21 jmp_buf env;
22
23 #ifdef HPDF_DLL
24 void  __stdcall
25 #else
26 void
27 #endif
28 error_handler  (HPDF_STATUS   error_no,
29                 HPDF_STATUS   detail_no,
30                 void         *user_data)
31 {
32     printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
33                 (HPDF_UINT)detail_no);
34     longjmp(env, 1);
35 }
36
37
38 void
39 print_page  (HPDF_Page   page,  int page_num)
40 {
41     char buf[50];
42
43     HPDF_Page_SetWidth (page, 200);
44     HPDF_Page_SetHeight (page, 300);
45
46     HPDF_Page_BeginText (page);
47     HPDF_Page_MoveTextPos (page, 50, 250);
48 #ifdef __WIN32__
49     _snprintf(buf, 50, "Page:%d", page_num);
50 #else
51     snprintf(buf, 50, "Page:%d", page_num);
52 #endif
53     HPDF_Page_ShowText (page, buf);
54     HPDF_Page_EndText (page);
55 }
56
57 int main(int argc, char **argv)
58 {
59     HPDF_Doc  pdf;
60     HPDF_Font font;
61     HPDF_Page page[4];
62     HPDF_Outline root;
63     HPDF_Outline outline[4];
64     HPDF_Destination dst;
65     char fname[256];
66     FILE *f;
67     char SAMP_TXT[2048];
68
69     strcpy (fname, argv[0]);
70     strcat (fname, ".pdf");
71
72 #ifdef __WIN32__
73     f = fopen ("mbtext\\sjis.txt", "rb");
74 #else
75     f = fopen ("mbtext/sjis.txt", "rb");
76 #endif
77     if (!f) {
78         printf ("error: cannot open 'mbtext/sjis.txt'\n");
79         return 1;
80     }
81
82     fgets (SAMP_TXT, 2048, f);
83     fclose (f);
84
85     pdf = HPDF_New (error_handler, NULL);
86     if (!pdf) {
87         printf ("error: cannot create PdfDoc object\n");
88         return 1;
89     }
90
91     if (setjmp(env)) {
92         HPDF_Free (pdf);
93         return 1;
94     }
95
96     /* declaration for using Japanese encoding. */
97     HPDF_UseJPEncodings (pdf);
98
99     /* create default-font */
100     font = HPDF_GetFont (pdf, "Helvetica", NULL);
101
102     /* Set page mode to use outlines. */
103     HPDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE);
104
105     /* Add 3 pages to the document. */
106     page[0] = HPDF_AddPage (pdf);
107     HPDF_Page_SetFontAndSize (page[0], font, 20);
108     print_page(page[0], 1);
109
110     page[1] = HPDF_AddPage (pdf);
111     HPDF_Page_SetFontAndSize (page[1], font, 20);
112     print_page(page[1], 2);
113
114     page[2] = HPDF_AddPage (pdf);
115     HPDF_Page_SetFontAndSize (page[2], font, 20);
116     print_page(page[2], 3);
117
118     /* create outline root. */
119     root = HPDF_CreateOutLine (pdf, NULL, "OutlineRoot", NULL);
120     HPDF_Outline_SetOpened (root, HPDF_TRUE);
121
122     outline[0] = HPDF_CreateOutLine (pdf, root, "page1", NULL);
123     outline[1] = HPDF_CreateOutLine (pdf, root, "page2", NULL);
124
125     /* create outline with test which is  encoding */
126     outline[2] = HPDF_CreateOutLine (pdf, root, SAMP_TXT,
127                     HPDF_GetEncoder (pdf, "90ms-RKSJ-H"));
128
129     /* create destination objects on each pages
130      * and link it to outline items.
131      */
132     dst = HPDF_Page_CreateDestination (page[0]);
133     HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page[0]), 1);
134     HPDF_Outline_SetDestination(outline[0], dst);
135   //  HPDF_Catalog_SetOpenAction(dst);
136
137     dst = HPDF_Page_CreateDestination (page[1]);
138     HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page[1]), 1);
139     HPDF_Outline_SetDestination(outline[1], dst);
140
141     dst = HPDF_Page_CreateDestination (page[2]);
142     HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page[2]), 1);
143     HPDF_Outline_SetDestination(outline[2], dst);
144
145     /* save the document to a file */
146     HPDF_SaveToFile (pdf, fname);
147
148     /* clean up */
149     HPDF_Free (pdf);
150
151     return 0;
152 }