2 * << Haru Free PDF Library 2.0.5 >> -- JPFontDemo.cs
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 public class JPFontDemo {
20 public static void Main() {
21 Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());
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];
28 HPdfDoc pdf = new HPdfDoc();
30 /*declaration for using Japanese font, encoding. */
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",
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",
53 /*configure pdf-document to be compressed. */
54 pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);
56 /*Set page mode to use outlines. */
57 pdf.SetPageMode(HPdfPageMode.HPDF_PAGE_MODE_USE_OUTLINE);
59 /*create outline root. */
60 HPdfOutline root = pdf.CreateOutline(null, "JP font demo", null);
61 root.SetOpened (true);
63 for (int i = 0; i <= 15; i++) {
66 /*add a new page object. */
67 HPdfPage page = pdf.AddPage();
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);
75 HPdfFont title_font = pdf.GetFont("Helvetica", null);
76 page.SetFontAndSize(title_font, 10);
80 /*move the position of the text to top of the page. */
81 page.MoveTextPos(10, 190);
82 page.ShowText(detail_font[i].GetFontName());
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);
93 page.SetFontAndSize(detail_font[i], 10);
94 page.ShowText(samp_text);
95 page.MoveTextPos(0, -18);
97 page.SetFontAndSize(detail_font[i], 16);
98 page.ShowText(samp_text);
99 page.MoveTextPos(0, -27);
101 page.SetFontAndSize(detail_font[i], 23);
102 page.ShowText(samp_text);
103 page.MoveTextPos(0, -36);
105 page.SetFontAndSize(detail_font[i], 30);
106 page.ShowText(samp_text);
108 HPdfPoint p = page.GetCurrentTextPos();
110 /*finish to print text. */
113 page.SetLineWidth(0.5f);
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);
123 page.SetWidth(p.x + 20);
124 page.SetHeight(PAGE_HEIGHT);
126 page.MoveTo(10, PAGE_HEIGHT - 25);
127 page.LineTo(p.x + 10, PAGE_HEIGHT - 25);
130 page.MoveTo(10, PAGE_HEIGHT - 85);
131 page.LineTo(p.x + 10, PAGE_HEIGHT - 85);
134 page.MoveTo(10, p.y - 12);
135 page.LineTo(p.x + 10, p.y - 12);
139 pdf.SaveToFile("JPFontDemo.pdf");
140 } catch (Exception e) {
141 Console.Error.WriteLine(e.Message);