OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / if / c# / demo / JPFontDemo.cs
1 /*
2  * << Haru Free PDF Library 2.0.5 >> -- JPFontDemo.cs
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 using System;
16 using System.IO;
17 using HPdf;
18
19 public class JPFontDemo {
20     public static void Main() {
21         Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());
22
23         try {
24             const int PAGE_HEIGHT = 210;
25             string samp_text = "\83A\83\81\83\93\83{\90Ô\82¢\82È\82 \82¢\82¤\82¦\82¨\81B\95\82\82«\91\94\82É\8f¬\83G\83r\82à\82¨\82æ\82¢\82Å\82é\81B";
26             HPdfFont[] detail_font = new HPdfFont[16];
27
28             HPdfDoc pdf = new HPdfDoc();
29
30             /*declaration for using Japanese font, encoding. */
31             pdf.UseJPEncodings();
32             pdf.UseJPFonts();
33
34             detail_font[0] = pdf.GetFont("MS-Mincyo", "90ms-RKSJ-H");
35             detail_font[1] = pdf.GetFont("MS-Mincyo,Bold", "90ms-RKSJ-H");
36             detail_font[2] = pdf.GetFont("MS-Mincyo,Italic", "90ms-RKSJ-H");
37             detail_font[3] = pdf.GetFont("MS-Mincyo,BoldItalic", "90ms-RKSJ-H");
38             detail_font[4] = pdf.GetFont("MS-PMincyo", "90msp-RKSJ-H");
39             detail_font[5] = pdf.GetFont("MS-PMincyo,Bold", "90msp-RKSJ-H");
40             detail_font[6] = pdf.GetFont("MS-PMincyo,Italic", "90msp-RKSJ-H");
41             detail_font[7] = pdf.GetFont("MS-PMincyo,BoldItalic",
42             "90msp-RKSJ-H");
43             detail_font[8] = pdf.GetFont("MS-Gothic", "90ms-RKSJ-H");
44             detail_font[9] = pdf.GetFont("MS-Gothic,Bold", "90ms-RKSJ-H");
45             detail_font[10] = pdf.GetFont("MS-Gothic,Italic", "90ms-RKSJ-H");
46             detail_font[11] = pdf.GetFont("MS-Gothic,BoldItalic", "90ms-RKSJ-H");
47             detail_font[12] = pdf.GetFont("MS-PGothic", "90msp-RKSJ-H");
48             detail_font[13] = pdf.GetFont("MS-PGothic,Bold", "90msp-RKSJ-H");
49             detail_font[14] = pdf.GetFont("MS-PGothic,Italic", "90msp-RKSJ-H");
50             detail_font[15] = pdf.GetFont("MS-PGothic,BoldItalic",
51             "90msp-RKSJ-H");
52
53             /*configure pdf-document to be compressed. */
54             pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);
55
56             /*Set page mode to use outlines. */
57             pdf.SetPageMode(HPdfPageMode.HPDF_PAGE_MODE_USE_OUTLINE);
58
59             /*create outline root. */
60             HPdfOutline root = pdf.CreateOutline(null, "JP font demo", null);
61             root.SetOpened (true);
62
63             for (int i = 0; i <= 15; i++) {
64                 float x_pos;
65
66                 /*add a new page object. */
67                 HPdfPage page = pdf.AddPage();
68
69                 /*create outline entry */
70                 HPdfOutline outline = pdf.CreateOutline(root,
71                         detail_font[i].GetFontName(), null);
72                 HPdfDestination dst = page.CreateDestination();
73                 outline.SetDestination(dst);
74
75                 HPdfFont title_font = pdf.GetFont("Helvetica", null);
76                 page.SetFontAndSize(title_font, 10);
77
78                 page.BeginText();
79
80                 /*move the position of the text to top of the page. */
81                 page.MoveTextPos(10, 190);
82                 page.ShowText(detail_font[i].GetFontName());
83
84                 page.SetFontAndSize(detail_font[i], 15);
85                 page.MoveTextPos(10, -20);
86                 page.ShowText("abcdefghijklmnopqrstuvwxyz");
87                 page.MoveTextPos(0, -20);
88                 page.ShowText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
89                 page.MoveTextPos(0, -20);
90                 page.ShowText("1234567890");
91                 page.MoveTextPos(0, -20);
92
93                 page.SetFontAndSize(detail_font[i], 10);
94                 page.ShowText(samp_text);
95                 page.MoveTextPos(0, -18);
96
97                 page.SetFontAndSize(detail_font[i], 16);
98                 page.ShowText(samp_text);
99                 page.MoveTextPos(0, -27);
100
101                 page.SetFontAndSize(detail_font[i], 23);
102                 page.ShowText(samp_text);
103                 page.MoveTextPos(0, -36);
104
105                 page.SetFontAndSize(detail_font[i], 30);
106                 page.ShowText(samp_text);
107
108                 HPdfPoint p = page.GetCurrentTextPos();
109
110                 /*finish to print text. */
111                 page.EndText();
112
113                 page.SetLineWidth(0.5f);
114
115                 x_pos = 20;
116                 for (int j = 0; j <= samp_text.Length / 2; j++) {
117                     page.MoveTo(x_pos, p.y - 10);
118                     page.LineTo(x_pos, p.y - 12);
119                     page.Stroke();
120                     x_pos = x_pos + 30;
121                 }
122
123                 page.SetWidth(p.x + 20);
124                 page.SetHeight(PAGE_HEIGHT);
125
126                 page.MoveTo(10, PAGE_HEIGHT - 25);
127                 page.LineTo(p.x + 10, PAGE_HEIGHT - 25);
128                 page.Stroke();
129
130                 page.MoveTo(10, PAGE_HEIGHT - 85);
131                 page.LineTo(p.x + 10, PAGE_HEIGHT - 85);
132                 page.Stroke();
133
134                 page.MoveTo(10, p.y - 12);
135                 page.LineTo(p.x + 10, p.y - 12);
136                 page.Stroke();
137             }
138
139             pdf.SaveToFile("JPFontDemo.pdf");
140         } catch (Exception e) {
141             Console.Error.WriteLine(e.Message);
142         }
143     }
144 }
145
146
147